diff --git a/Modules/StudyProgramme/classes/Setup/class.PRGUpdateCRSRefLPSettingMigration.php b/Modules/StudyProgramme/classes/Setup/class.PRGUpdateCRSRefLPSettingMigration.php new file mode 100644 index 000000000000..6930ce130751 --- /dev/null +++ b/Modules/StudyProgramme/classes/Setup/class.PRGUpdateCRSRefLPSettingMigration.php @@ -0,0 +1,108 @@ +db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE); + } + + /** + * @throws Exception + */ + public function step(Environment $environment) : void + { + $query = "SELECT distinct od.obj_id AS objid " . PHP_EOL . + "FROM object_reference oref " . PHP_EOL . + "JOIN object_data od ON od.obj_id = oref.obj_id AND od.type = 'crsr'" . PHP_EOL . + "JOIN tree ON oref.ref_id = tree.child" . PHP_EOL . + "JOIN tree t2 ON t2.path > tree.path" . PHP_EOL . + "JOIN object_reference oref2 ON oref2.ref_id = t2.child" . PHP_EOL . + "JOIN object_data od2 ON od2.obj_id = oref2.obj_id AND od2.type = 'prg'" . PHP_EOL . + "WHERE od.obj_id NOT IN (" . PHP_EOL . + "SELECT obj_id FROM ut_lp_settings WHERE obj_type = 'crsr' AND u_mode = " + . ilLPObjSettings::LP_MODE_COURSE_REFERENCE . PHP_EOL . + ")" . PHP_EOL . + "LIMIT 1"; + + $result = $this->db->query($query); + $row = $this->db->fetchAssoc($result); + $q = 'DELETE FROM ut_lp_settings WHERE obj_id = ' . (int) $row['objid']; + $this->db->manipulate($q); + + $q = 'INSERT INTO ut_lp_settings (obj_id, obj_type, u_mode)' . PHP_EOL . + 'VALUES (' . + (int) $row['objid'] . + ', "crsr", ' . + ilLPObjSettings::LP_MODE_COURSE_REFERENCE . + ');'; + $this->db->manipulate($q); + } + + public function getRemainingAmountOfSteps() : int + { + $query = "SELECT count(distinct od.obj_id) AS cnt " . PHP_EOL . + "FROM object_reference oref " . PHP_EOL . + "JOIN object_data od ON od.obj_id = oref.obj_id AND od.type = 'crsr'" . PHP_EOL . + "JOIN tree ON oref.ref_id = tree.child" . PHP_EOL . + "JOIN tree t2 ON t2.path > tree.path" . PHP_EOL . + "JOIN object_reference oref2 ON oref2.ref_id = t2.child" . PHP_EOL . + "JOIN object_data od2 ON od2.obj_id = oref2.obj_id AND od2.type = 'prg'" . PHP_EOL . + "WHERE od.obj_id NOT IN (" . PHP_EOL . + "SELECT obj_id FROM ut_lp_settings WHERE obj_type = 'crsr' AND u_mode = " + . ilLPObjSettings::LP_MODE_COURSE_REFERENCE . PHP_EOL . + ")"; + $result = $this->db->query($query); + $row = $this->db->fetchAssoc($result); + + return (int) $row['cnt']; + } +} \ No newline at end of file diff --git a/Modules/StudyProgramme/classes/Setup/class.ilStudyProgrammeMigrationAgent.php b/Modules/StudyProgramme/classes/Setup/class.ilStudyProgrammeMigrationAgent.php new file mode 100644 index 000000000000..a835cbafce17 --- /dev/null +++ b/Modules/StudyProgramme/classes/Setup/class.ilStudyProgrammeMigrationAgent.php @@ -0,0 +1,70 @@ +refinery = $refinery; + } + public function hasConfig(): bool + { + return false; + } + + public function getArrayToConfigTransformation(): Refinery\Transformation + { + throw new LogicException("Agent has no config"); + } + + public function getInstallObjective(\ILIAS\Setup\Config $config = null): Setup\Objective + { + return new Setup\Objective\NullObjective(); + } + + public function getUpdateObjective(\ILIAS\Setup\Config $config = null): Setup\Objective + { + return new Setup\Objective\NullObjective(); + } + + public function getBuildArtifactObjective(): Setup\Objective + { + return new Setup\Objective\NullObjective(); + } + + public function getStatusObjective(Setup\Metrics\Storage $storage): Setup\Objective + { + return new Setup\Objective\NullObjective(); + } + + public function getMigrations(): array + { + return [ + new PRGUpdateCRSRefLPSettingMigration() + ]; + } +}