1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace nystudio107\retour\migrations; |
4
|
|
|
|
5
|
|
|
use craft\db\Migration; |
6
|
|
|
use yii\base\NotSupportedException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* m181213_233502_add_site_id migration. |
|
|
|
|
10
|
|
|
*/ |
|
|
|
|
11
|
|
|
class m181213_233502_add_site_id extends Migration |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** |
|
|
|
|
14
|
|
|
* @inheritdoc |
15
|
|
|
* @throws NotSupportedException |
|
|
|
|
16
|
|
|
*/ |
|
|
|
|
17
|
|
|
public function safeUp(): bool |
18
|
|
|
{ |
19
|
|
|
// Drop the locale columns |
20
|
|
|
if ($this->db->columnExists('{{%retour_redirects}}', 'locale')) { |
21
|
|
|
$this->dropColumn( |
22
|
|
|
'{{%retour_redirects}}', |
23
|
|
|
'locale' |
24
|
|
|
); |
25
|
|
|
} |
26
|
|
|
if ($this->db->columnExists('{{%retour_static_redirects}}', 'locale')) { |
27
|
|
|
$this->dropColumn( |
28
|
|
|
'{{%retour_static_redirects}}', |
29
|
|
|
'locale' |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
// Add in the siteId columns |
33
|
|
|
if (!$this->db->columnExists('{{%retour_redirects}}', 'siteId')) { |
34
|
|
|
$this->addColumn( |
35
|
|
|
'{{%retour_redirects}}', |
36
|
|
|
'siteId', |
37
|
|
|
$this->integer()->null()->after('uid')->defaultValue(null) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
if (!$this->db->columnExists('{{%retour_static_redirects}}', 'siteId')) { |
41
|
|
|
$this->addColumn( |
42
|
|
|
'{{%retour_static_redirects}}', |
43
|
|
|
'siteId', |
44
|
|
|
$this->integer()->null()->after('uid')->defaultValue(null) |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
if (!$this->db->columnExists('{{%retour_stats}}', 'siteId')) { |
48
|
|
|
$this->addColumn( |
49
|
|
|
'{{%retour_stats}}', |
50
|
|
|
'siteId', |
51
|
|
|
$this->integer()->null()->after('uid')->defaultValue(null) |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
// Add foreign keys |
55
|
|
|
$this->addForeignKeys(); |
56
|
|
|
// Create indexes |
57
|
|
|
$this->createIndexes(); |
58
|
|
|
|
59
|
|
|
return true; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
|
|
|
|
63
|
|
|
* @inheritdoc |
64
|
|
|
*/ |
|
|
|
|
65
|
|
|
public function safeDown() |
66
|
|
|
{ |
67
|
|
|
echo "m181213_233502_add_site_id cannot be reverted.\n"; |
68
|
|
|
return false; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
|
|
|
|
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
|
protected function addForeignKeys(): void |
75
|
|
|
{ |
76
|
|
|
$this->addForeignKey( |
77
|
|
|
$this->db->getForeignKeyName(), |
78
|
|
|
'{{%retour_static_redirects}}', |
79
|
|
|
'siteId', |
80
|
|
|
'{{%sites}}', |
81
|
|
|
'id', |
82
|
|
|
'CASCADE', |
83
|
|
|
'CASCADE' |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
$this->addForeignKey( |
87
|
|
|
$this->db->getForeignKeyName(), |
88
|
|
|
'{{%retour_stats}}', |
89
|
|
|
'siteId', |
90
|
|
|
'{{%sites}}', |
91
|
|
|
'id', |
92
|
|
|
'CASCADE', |
93
|
|
|
'CASCADE' |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
|
|
|
|
98
|
|
|
* @return void |
99
|
|
|
*/ |
100
|
|
|
protected function createIndexes(): void |
101
|
|
|
{ |
102
|
|
|
$this->createIndex( |
103
|
|
|
$this->db->getIndexName(), |
104
|
|
|
'{{%retour_redirects}}', |
105
|
|
|
'siteId', |
106
|
|
|
false |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$this->createIndex( |
110
|
|
|
$this->db->getIndexName(), |
111
|
|
|
'{{%retour_static_redirects}}', |
112
|
|
|
'siteId', |
113
|
|
|
false |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
$this->createIndex( |
117
|
|
|
$this->db->getIndexName(), |
118
|
|
|
'{{%retour_stats}}', |
119
|
|
|
'siteId', |
120
|
|
|
false |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|