ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
ILIAS\Test\Setup\MoveSettingsTemplatesMigration Class Reference
+ Inheritance diagram for ILIAS\Test\Setup\MoveSettingsTemplatesMigration:
+ Collaboration diagram for ILIAS\Test\Setup\MoveSettingsTemplatesMigration:

Public Member Functions

 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 
 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 

Private Attributes

ilDBInterface $db
 

Additional Inherited Members

- Data Fields inherited from ILIAS\Setup\Migration
const INFINITE = -1
 

Detailed Description

Definition at line 27 of file MoveSettingsTemplatesMigration.php.

Member Function Documentation

◆ getDefaultAmountOfStepsPerRun()

ILIAS\Test\Setup\MoveSettingsTemplatesMigration::getDefaultAmountOfStepsPerRun ( )

Tell the default amount of steps to be executed for one run of the migration.

Return Migration::INFINITE if all units should be migrated at once.

Implements ILIAS\Setup\Migration.

Definition at line 38 of file MoveSettingsTemplatesMigration.php.

38 : int
39 {
40 return 100;
41 }

◆ getLabel()

ILIAS\Test\Setup\MoveSettingsTemplatesMigration::getLabel ( )
Returns
string - a meaningful and concise description for your migration.

Implements ILIAS\Setup\Migration.

Definition at line 33 of file MoveSettingsTemplatesMigration.php.

33 : string
34 {
35 return 'Migrate personal test template settings from tst_test_defaults to tst_test_settings';
36 }

◆ getPreconditions()

ILIAS\Test\Setup\MoveSettingsTemplatesMigration::getPreconditions ( Environment  $environment)

Objectives the migration depend on.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Migration.

Definition at line 43 of file MoveSettingsTemplatesMigration.php.

43 : array
44 {
45 return [new \ilDatabaseInitializedObjective()];
46 }

◆ getRemainingAmountOfSteps()

ILIAS\Test\Setup\MoveSettingsTemplatesMigration::getRemainingAmountOfSteps ( )

Count up how many "things" need to be migrated.

This helps the admin to decide how big he can create the steps and also how long a migration takes

Implements ILIAS\Setup\Migration.

Definition at line 112 of file MoveSettingsTemplatesMigration.php.

112 : int
113 {
114 $result = $this->db->query("SELECT COUNT(test_defaults_id) AS cnt FROM tst_test_defaults WHERE settings_id IS NULL");
115 return (int) $this->db->fetchObject($result)->cnt;
116 }

◆ prepare()

ILIAS\Test\Setup\MoveSettingsTemplatesMigration::prepare ( Environment  $environment)

Prepare the migration by means of some environment.

This is not supposed to modify the environment, but will be run to prime the migration object to run step and getRemainingAmountOfSteps afterwards.

Implements ILIAS\Setup\Migration.

Definition at line 48 of file MoveSettingsTemplatesMigration.php.

48 : void
49 {
50 $this->db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
51 }

References ILIAS\Setup\Environment\getResource(), and ILIAS\Setup\Environment\RESOURCE_DATABASE.

+ Here is the call graph for this function:

◆ step()

ILIAS\Test\Setup\MoveSettingsTemplatesMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 53 of file MoveSettingsTemplatesMigration.php.

53 : void
54 {
55 $row = $this->db->fetchAssoc(
56 $this->db->query("SELECT * FROM tst_test_defaults WHERE settings_id IS NULL LIMIT 1")
57 );
58
59 $settings_id = $this->db->nextId('tst_test_settings');
60 $setting_data = ['id' => [\ilDBConstants::T_INTEGER, $settings_id]];
61
62 // Migrate the legacy serialized column to a row in 'tst_test_settings'
63 $raw_settings = unserialize($row['defaults'], ['allowed_classes' => [\DateTimeImmutable::class]]);
64 foreach (self::SETTINGS_COLUMNS as $column_name => $column) {
65 [$column_def, $raw_name] = $column;
66 if (isset($raw_settings[$raw_name])) {
67 $value = $raw_settings[$raw_name];
68
69 if ($column_name === 'reporting_date') {
70 $value = $this->convertLegacyDate($value);
71 }
72
73 $setting_data[$column_name] = [$column_def['type'], $value];
74 }
75 }
76
77 // Insert the new row
78 $this->db->insert('tst_test_settings', $setting_data);
79 $this->db->update(
80 'tst_test_defaults',
81 ['settings_id' => [\ilDBConstants::T_INTEGER, $settings_id]],
82 ['test_defaults_id' => [\ilDBConstants::T_INTEGER, $row['test_defaults_id']]]
83 );
84
85 // Migrate the legacy json decoded to a row in 'tst_mark'
86 $raw_marks = json_decode($row['marks'], true);
87 foreach ($raw_marks as $mark_data) {
88 $mark_id = $this->db->nextId('tst_mark');
89 $this->db->insert(
90 'tst_mark',
91 [
92 'mark_id' => [\ilDBConstants::T_INTEGER, $mark_id],
93 'test_fi' => [\ilDBConstants::T_INTEGER, 0],
94 'short_name' => [\ilDBConstants::T_TEXT, $mark_data['short_name']],
95 'official_name' => [\ilDBConstants::T_TEXT, $mark_data['official_name']],
96 'minimum_level' => [\ilDBConstants::T_FLOAT, $mark_data['minimum_level']],
97 'passed' => [\ilDBConstants::T_FLOAT, (int) $mark_data['passed']],
98 'tstamp' => [\ilDBConstants::T_INTEGER, $row['tstamp']],
99 ]
100 );
101
102 $this->db->insert(
103 'tst_defaults_marks',
104 [
105 'defaults_id' => [\ilDBConstants::T_INTEGER, $row['test_defaults_id']],
106 'mark_id' => [\ilDBConstants::T_INTEGER, $mark_id],
107 ]
108 );
109 }
110 }
convertLegacyDate(string|\DateTimeImmutable|null $date)

References ILIAS\Test\Setup\convertLegacyDate(), ilDBConstants\T_FLOAT, ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ILIAS\Test\Setup\MoveSettingsTemplatesMigration::$db
private

Definition at line 31 of file MoveSettingsTemplatesMigration.php.


The documentation for this class was generated from the following file: