19declare(strict_types=1);
26 private \ilDBInterface
$db;
30 return "Remove Duplicate Rows In Activation Table";
40 return \ilResourceStorageMigrationHelper::getPreconditions();
45 $this->db = $environment->
getResource(Environment::RESOURCE_DATABASE);
50 $activation_data = $this->db->fetchObject(
52 'SELECT obj_id FROM crs_items' . PHP_EOL
53 .
'GROUP BY obj_id HAVING COUNT(*) > 1 LIMIT 1'
57 if ($activation_data ===
null) {
61 $parent_data = $this->db->fetchObject(
63 'SELECT parent FROM tree WHERE child=%s',
65 [$activation_data->obj_id]
69 if ($parent_data ===
null) {
70 $this->db->manipulateF(
71 'DELETE FROM crs_items WHERE obj_id = %s',
73 [$activation_data->obj_id]
78 $this->db->manipulateF(
79 'DELETE FROM crs_items WHERE obj_id = %s AND parent_id != %s',
81 [$activation_data->obj_id, $parent_data->parent]
87 return $this->db->numRows(
89 'SELECT obj_id, parent_id FROM crs_items GROUP BY obj_id HAVING COUNT(*) > 1'
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
getPreconditions(Environment $environment)
Objectives the migration depend on.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
step(Environment $environment)
Run one step of the migration.
prepare(Environment $environment)
Prepare the migration by means of some environment.
An environment holds resources to be used in the setup process.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
A migration is a potentially long lasting operation that can be broken into discrete steps.