# -*- coding: utf-8 -*- from ppms import ppms, constants from ppms.db_update import UpdateManager, get_reference_suffix from ppms.migration import PacketCategory, BasePacket class ApplyInCaseOfUpdate(BasePacket): """Applies all configured conflicts to the system customizing automatically""" done_after_success = False run_on_startup = True category = PacketCategory.CATEGORY_MANDATORY special_snowflake = True wi_number = 22487 def fix(self, runner): query = "UPDATE CONFLICT SET RESOLVED = 0" ppms.db_modify(query) update_manager = UpdateManager() update_manager.generate_icou_data(dont_wipe=not self.does_ref_exist()) update_manager = UpdateManager() non_pos_conflicts = update_manager.conflict_manager.get_defined_conflicts() if non_pos_conflicts: self.log(update_manager.modification_manager.modifications) update_manager.apply_icou_data(non_pos_conflicts) pos_conflicts = update_manager.conflict_manager.get_conflicts_with_pos_modifications() if pos_conflicts: self.log(update_manager.modification_manager.modifications) update_manager.apply_pos_icou(pos_conflicts) return self.success() def does_ref_exist(self): MSSQL = """select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME like '%{suffix}' and TABLE_TYPE = 'BASE TABLE'""" ORACLE = """select * from USER_TABLES where TABLE_NAME like '%{suffix}'""" DBMS = ppms.db_get_dbms_name() if DBMS == constants.DBMS_ORACLE: statement = ORACLE.format(suffix=get_reference_suffix()) elif DBMS == constants.DBMS_MSSQL: statement = MSSQL.format(suffix=get_reference_suffix()) else: return False result = ppms.db_select(statement) return len(result) > 0