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

Public Member Functions

 prepare (\ilDBInterface $db)
 Prepare the execution of the steps. More...
 
 step_1 ()
 
 step_2 ()
 
 prepare (\ilDBInterface $db)
 Prepare the execution of the steps. More...
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

Definition at line 25 of file Test11DBUpdateSteps.php.

Member Function Documentation

◆ prepare()

ILIAS\Test\Setup\Test11DBUpdateSteps::prepare ( \ilDBInterface  $db)

Prepare the execution of the steps.

Do not use anything from the globals or the DIC inside your steps, only use the instance of the database provided here.

Implements ilDatabaseUpdateSteps.

Definition at line 31 of file Test11DBUpdateSteps.php.

31 : void
32 {
33 $this->db = $db;
34 }

References ILIAS\Test\Setup\Test11DBUpdateSteps\$db.

◆ step_1()

ILIAS\Test\Setup\Test11DBUpdateSteps::step_1 ( )

Definition at line 36 of file Test11DBUpdateSteps.php.

36 : void
37 {
38 if ($this->db->tableColumnExists('tst_tests', 'mailnotification')) {
39 $this->db->dropTableColumn('tst_tests', 'mailnotification');
40 }
41 if ($this->db->tableColumnExists('tst_tests', 'mailnottype')) {
42 $this->db->dropTableColumn('tst_tests', 'mailnottype');
43 }
44 }

◆ step_2()

ILIAS\Test\Setup\Test11DBUpdateSteps::step_2 ( )

Definition at line 46 of file Test11DBUpdateSteps.php.

46 : void
47 {
48 // 1. Create table schema
49 if (!$this->db->tableExists('tst_test_settings')) {
50 // Create table and sequence table
51 $this->db->createTable('tst_test_settings', ['id' => ['type' => \ilDBConstants::T_INTEGER]]);
52 $this->db->createSequence('tst_test_settings');
53 $this->db->addPrimaryKey('tst_test_settings', ['id']);
54
55 // Create table columns
56 foreach (self::SETTINGS_COLUMNS as $key => $value) {
57 [$column_def] = $value;
58
59 // No columns should be nullable, except those with NULL by default
60 if (!isset($column_def['notnull'])) {
61 $column_def['notnull'] = !$this->columnIsNullable($column_def);
62 }
63
64 $this->db->addTableColumn('tst_test_settings', $key, $column_def);
65 }
66 }
67
68 // 2. Create a foreign key column in tst_tests
69 if (!$this->db->tableColumnExists('tst_tests', 'settings_id')) {
70 $this->db->addTableColumn(
71 'tst_tests',
72 'settings_id',
73 ['type' => \ilDBConstants::T_INTEGER, 'default' => null, 'notnull' => false],
74 );
75 $this->db->addForeignKey(
76 'test_settings_fkey',
77 ['settings_id'],
78 'tst_tests',
79 ['id'],
80 'tst_test_settings',
81 ForeignKeyConstraints::NO_ACTION,
82 ForeignKeyConstraints::RESTRICT,
83 );
84 }
85
86 // 3. Create a foreign key column and new columns in tst_test_defaults
87 if (!$this->db->tableColumnExists('tst_test_defaults', 'settings_id')) {
88 $this->db->addTableColumn(
89 'tst_test_defaults',
90 'settings_id',
91 ['type' => \ilDBConstants::T_INTEGER, 'default' => null, 'notnull' => false],
92 );
93 $this->db->addForeignKey(
94 'test_default_fkey',
95 ['settings_id'],
96 'tst_test_defaults',
97 ['id'],
98 'tst_test_settings',
99 ForeignKeyConstraints::NO_ACTION,
100 ForeignKeyConstraints::RESTRICT
101 );
102 }
103 if (!$this->db->tableColumnExists('tst_test_defaults', 'description')) {
104 $this->db->addTableColumn(
105 'tst_test_defaults',
106 'description',
107 ['type' => \ilDBConstants::T_TEXT, 'length' => 4000, 'default' => null],
108 );
109 }
110 if (!$this->db->tableColumnExists('tst_test_defaults', 'author')) {
111 $this->db->addTableColumn(
112 'tst_test_defaults',
113 'author',
114 ['type' => \ilDBConstants::T_TEXT, 'length' => 255, 'default' => null],
115 );
116 }
117
118 // 4. Create tst_defaults_marks table to store marks reference
119 if (!$this->db->tableExists('tst_defaults_marks')) {
120 $this->db->createTable(
121 'tst_defaults_marks',
122 [
123 'defaults_id' => ['type' => \ilDBConstants::T_INTEGER],
124 'mark_id' => ['type' => \ilDBConstants::T_INTEGER],
125 ],
126 );
127 $this->db->addPrimaryKey('tst_defaults_marks', ['defaults_id', 'mark_id']);
128
129 $this->db->addForeignKey(
130 'test_default_fkey2',
131 ['defaults_id '],
132 'tst_defaults_marks',
133 ['test_defaults_id'],
134 'tst_test_defaults',
135 ForeignKeyConstraints::NO_ACTION,
136 ForeignKeyConstraints::RESTRICT
137 );
138
139 $this->db->addForeignKey(
140 'test_mark_fkey',
141 ['mark_id '],
142 'tst_defaults_marks',
143 ['mark_id'],
144 'tst_mark',
145 ForeignKeyConstraints::NO_ACTION,
147 );
148 }
149 }
const CASCADE
Definition: Title.php:33
columnIsNullable(array $column_def)

References CASCADE, ILIAS\Test\Setup\columnIsNullable(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ILIAS\Test\Setup\Test11DBUpdateSteps::$db
protected

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