# -*- coding: utf-8 -*-
from ppms.migration.packet import *

class FixOrderOfProcessPhases(ChangeDTPPacket):
    '''Change sorting of process phases.

    Prevents process phases from getting scrambled when releasing a process step.
    '''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 6883

    def fix(self, runner):
        record = self.get_record(343, ['-', '000219'], [40109])
        if not self.change_value(record, 'source_text_clob', "Select di041152 from DT499 WHERE DI057817='{0}' GROUP BY di041152, di041163, di041187 ORDER BY di041187 DESC,di041163", "Select di041152 from DT499 WHERE DI057817='{0}' GROUP BY di041152, di041163, di041187 ORDER BY di041163, di041187 DESC"):
            return self.fail()

        return self.success()
