# -*- coding: utf-8 -*-

from ppms.migration.packet import *
from ppms.migration import SQLPacket, MaxVersionDependency

class RenameMenuitemToRestart(SQLPacket):
    """Change the "Reload System Customizing" menuitem to "Restart Server" """
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 18656

    fname = 'wi18656_server_restart.sql'

    def get_dependencies(self):
        return MaxVersionDependency(version='39.5.7'),

    def delete_old_translations(self):
        for statement in (
                "DELETE FROM DT435 WHERE DI023517 = '001569' AND DI001538 IN (SELECT DI001569 FROM DT428 WHERE "
                "DI000357 IN ('0763'))",
                "DELETE FROM DT435 WHERE DI023517 = '001588' AND DI001538 IN (SELECT DI001588 FROM DT405 WHERE "
                "DI000123 IN ('009BAZ'))"):
            self.modify_and_log(statement)

    def insert_new_translations(self):
        self.apply_dml_file(self.sql_planta_de_dbms, self.fname)

    def fix(self, runner):
        self.delete_old_translations()
        self.insert_new_translations()

        return self.success()
