19declare(strict_types=1);
30 return 'Migration for setting date of last change of existing media objects to their creation date.';
41 new \ilDatabaseInitializedObjective(),
42 new \ilDatabaseUpdatedObjective()
48 $this->db = $environment->
getResource(Environment::RESOURCE_DATABASE);
53 $res = $this->db->query(
54 "SELECT mob_data.id AS mob_id, object_data.create_date AS date FROM mob_data" .
55 " LEFT JOIN object_data ON object_data.obj_id = mob_data.id" .
56 " WHERE last_change = 0 ORDER BY mob_id LIMIT 1"
58 if (!($row = $this->db->fetchAssoc(
$res))) {
61 $mob_id = (
int) $row[
'mob_id'];
62 $date =
new DateTimeImmutable((
string) $row[
'date']);
66 [
'last_change' => [
'integer', $date->getTimestamp()]],
67 [
'id' => [
'integer', $mob_id]]
73 $res = $this->db->query(
74 "SELECT COUNT(mob_data.id) AS count FROM mob_data JOIN object_data ON object_data.obj_id = mob_data.id" .
75 " WHERE last_change = 0"
77 if ($row = $this->db->fetchAssoc(
$res)) {
78 return $row[
'count'] ?? 0;
getPreconditions(Environment $environment)
Objectives the migration depend on.
prepare(Environment $environment)
Prepare the migration by means of some environment.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
step(Environment $environment)
Run one step of the migration.
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
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.