ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
class.ilMobLastChangeMigration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
25{
26 protected ilDBInterface $db;
27
28 public function getLabel(): string
29 {
30 return 'Migration for setting date of last change of existing media objects to their creation date.';
31 }
32
34 {
35 return 10000;
36 }
37
38 public function getPreconditions(Environment $environment): array
39 {
40 return [
41 new \ilDatabaseInitializedObjective(),
42 new \ilDatabaseUpdatedObjective()
43 ];
44 }
45
46 public function prepare(Environment $environment): void
47 {
48 $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
49 }
50
51 public function step(Environment $environment): void
52 {
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"
57 );
58 if (!($row = $this->db->fetchAssoc($res))) {
59 return;
60 }
61 $mob_id = (int) $row['mob_id'];
62 $date = new DateTimeImmutable((string) $row['date']);
63
64 $this->db->update(
65 'mob_data',
66 ['last_change' => ['integer', $date->getTimestamp()]],
67 ['id' => ['integer', $mob_id]]
68 );
69 }
70
71 public function getRemainingAmountOfSteps(): int
72 {
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"
76 );
77 if ($row = $this->db->fetchAssoc($res)) {
78 return $row['count'] ?? 0;
79 }
80 return 0;
81 }
82}
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.
Definition: Environment.php:28
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.
Definition: Migration.php:29
Interface ilDBInterface.
$res
Definition: ltiservices.php:69