ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ILIAS\Test\Setup\MoveTestSettingsMigration Class Reference
+ Inheritance diagram for ILIAS\Test\Setup\MoveTestSettingsMigration:
+ Collaboration diagram for ILIAS\Test\Setup\MoveTestSettingsMigration:

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
 
IOWrapper $io
 

Additional Inherited Members

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

Detailed Description

Definition at line 28 of file MoveTestSettingsMigration.php.

Member Function Documentation

◆ getDefaultAmountOfStepsPerRun()

ILIAS\Test\Setup\MoveTestSettingsMigration::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 40 of file MoveTestSettingsMigration.php.

40 : int
41 {
42 return 100;
43 }

◆ getLabel()

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

Implements ILIAS\Setup\Migration.

Definition at line 35 of file MoveTestSettingsMigration.php.

35 : string
36 {
37 return 'Migrate test settings from tst_tests to tst_test_settings';
38 }

◆ getPreconditions()

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

Objectives the migration depend on.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Migration.

Definition at line 45 of file MoveTestSettingsMigration.php.

45 : array
46 {
47 return [new \ilDatabaseInitializedObjective()];
48 }

◆ getRemainingAmountOfSteps()

ILIAS\Test\Setup\MoveTestSettingsMigration::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 97 of file MoveTestSettingsMigration.php.

97 : int
98 {
99 $result = $this->db->query("SELECT COUNT(test_id) AS cnt FROM tst_tests WHERE settings_id IS NULL");
100 return (int) $this->db->fetchObject($result)->cnt;
101 }

◆ prepare()

ILIAS\Test\Setup\MoveTestSettingsMigration::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 50 of file MoveTestSettingsMigration.php.

50 : void
51 {
52 $this->db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
53 $this->io = $environment->getResource(Setup\Environment::RESOURCE_ADMIN_INTERACTION);
54 }

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

+ Here is the call graph for this function:

◆ step()

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

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 56 of file MoveTestSettingsMigration.php.

56 : void
57 {
58 $columns = implode(',', array_keys(self::SETTINGS_COLUMNS));
59 $row = $this->db->fetchAssoc(
60 $this->db->query("SELECT test_id, {$columns} FROM tst_tests WHERE settings_id IS NULL LIMIT 1")
61 );
62
63 $settings_id = $this->db->nextId('tst_test_settings');
64 $setting_data = ['id' => [\ilDBConstants::T_INTEGER, $settings_id]];
65
66 foreach ($row as $column_name => $value) {
67 if (isset(self::SETTINGS_COLUMNS[$column_name])) {
68 [$column_def] = self::SETTINGS_COLUMNS[$column_name];
69
70 if ($column_name === 'reporting_date') {
71 $value = $this->convertLegacyDate($value);
72 }
73 if ($column_name === 'nr_of_tries' && $value > 127) {
74 $this->io->inform(
75 "ID {$settings_id}: Tried to set nr_of_tries to {$value}, which is too high. Setting it to 127 instead."
76 );
77 $value = 127;
78 }
79
80 // Convert legacy null values to 0
81 if ($column_def['type'] === \ilDBConstants::T_INTEGER && !$this->columnIsNullable($column_def)) {
82 $value = (int) $value;
83 }
84
85 $setting_data[$column_name] = [$column_def['type'], $value];
86 }
87 }
88
89 $this->db->insert('tst_test_settings', $setting_data);
90 $this->db->update(
91 'tst_tests',
92 ['settings_id' => [\ilDBConstants::T_INTEGER, $settings_id]],
93 ['test_id' => [\ilDBConstants::T_INTEGER, $row['test_id']]]
94 );
95 }
columnIsNullable(array $column_def)
convertLegacyDate(string|\DateTimeImmutable|null $date)

References ILIAS\Test\Setup\columnIsNullable(), ILIAS\Test\Setup\convertLegacyDate(), ILIAS\Repository\int(), and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

Field Documentation

◆ $db

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

Definition at line 32 of file MoveTestSettingsMigration.php.

◆ $io

IOWrapper ILIAS\Test\Setup\MoveTestSettingsMigration::$io
private

Definition at line 33 of file MoveTestSettingsMigration.php.


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