ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
RemoveLegacyTestSettingsMigration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Test\Setup;
22
23use ILIAS\Setup;
26
28{
30
31 private const array UNUSED_LEGACY_COLUMNS = [
32 'ects_output',
33 'ects_fx',
34 'ects_a',
35 'ects_b',
36 'ects_c',
37 'ects_d',
38 'ects_e',
39 'keep_questions',
40 'mc_scoring',
41 'show_question_titles',
42 'certificate_visibility',
43 'resultoutput',
44 'pool_usage',
45 'info_screen',
46 ];
47
48 private \ilDBInterface $db;
49 private bool $data_loss_detected = false;
50
51 public function getLabel(): string
52 {
53 return 'Remove columns from tst_tests and tst_test_defaults that are now in tst_test_settings';
54 }
55
57 {
58 return 1;
59 }
60
61 public function getPreconditions(Environment $environment): array
62 {
63 return [
64 new \ilDatabaseInitializedObjective(),
65 ];
66 }
67
68 public function prepare(Environment $environment): void
69 {
70 $this->db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
71
72 $move_settings = new MoveTestSettingsMigration();
73 $move_settings->prepare($environment);
74 if ($move_settings->getRemainingAmountOfSteps() > 0) {
75 $this->data_loss_detected = true;
76 return;
77 }
78
79 $move_templates = new MoveSettingsTemplatesMigration();
80 $move_templates->prepare($environment);
81 if ($move_templates->getRemainingAmountOfSteps() > 0) {
82 $this->data_loss_detected = true;
83 return;
84 }
85 }
86
87 public function step(Environment $environment): void
88 {
89 if ($this->data_loss_detected) {
91 'Failed to remove legacy test settings. Please run MoveTestSettingsMigration and MoveSettingsTemplatesMigration first.'
92 );
93 }
94
95 $test_columns = array_merge(array_keys(self::SETTINGS_COLUMNS), self::UNUSED_LEGACY_COLUMNS);
96 foreach ($test_columns as $column) {
97 $this->dropColumn('tst_tests', $column);
98 }
99
100 $this->dropColumn('tst_test_defaults', 'marks');
101 $this->dropColumn('tst_test_defaults', 'defaults');
102 }
103
105 {
106 return (int) ($this->db->tableColumnExists('tst_tests', array_key_first(self::SETTINGS_COLUMNS))
107 || $this->db->tableColumnExists('tst_tests', self::UNUSED_LEGACY_COLUMNS[0])
108 || $this->db->tableColumnExists('tst_test_defaults', 'defaults'));
109 }
110
111 private function dropColumn(string $table, string $column): void
112 {
113 if ($this->db->tableColumnExists($table, $column)) {
114 $this->db->dropTableColumn($table, $column);
115 }
116 }
117}
Signals that some goal won't be achievable by actions of the system ever.
prepare(Environment $environment)
Prepare the migration by means of some environment.
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
getPreconditions(Environment $environment)
Objectives the migration depend on.
step(Environment $environment)
Run one step 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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...