# -*- coding: utf-8 -*-
"""Provides <x>"""
from ppms.migration import *
import hql


class MigrateDfBehaviourOfLongestPath(ChangeDTPPacket):
    """Migrates the DF-behaviour of di064921 and di064924 longest_critical_path from i2/o2 to i/o
    """
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 21970

    def migrate_df_behaviour(self):
        query = """FROM DataField df WHERE df.di in ('064921', '064924') AND df.behavior ='{behaviour}'"""
        success = True
        for rec in hql.search_record(query.format(behaviour='i2')):
            success = self.change_value(record=rec, attribute='behaviour', old_value='i2', new_value='i') and success

        for rec in hql.search_record(query.format(behaviour='o2')):
            success = self.change_value(record=rec, attribute='behaviour', old_value='o2', new_value='o') and success

        if not success:
            return self.fail("Could not change the df-behaviour for all dfs")
        return self.success()

