|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://flipboxfactory.com/software/patron/license |
|
6
|
|
|
* @link https://www.flipboxfactory.com/software/patron/ |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\patron\migrations; |
|
10
|
|
|
|
|
11
|
|
|
use craft\db\Migration; |
|
12
|
|
|
use flipbox\patron\records\Provider as ProviderRecord; |
|
13
|
|
|
use flipbox\patron\records\Token as TokensRecord; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @author Flipbox Factory <[email protected]> |
|
17
|
|
|
* @since 1.0.0 |
|
18
|
|
|
*/ |
|
19
|
|
|
class Install extends Migration |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @inheritdoc |
|
23
|
|
|
*/ |
|
24
|
|
|
public function safeUp() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->createTables(); |
|
27
|
|
|
$this->createIndexes(); |
|
28
|
|
|
$this->addForeignKeys(); |
|
29
|
|
|
|
|
30
|
|
|
// Locks |
|
31
|
|
|
if (false === (new m181010_081033_provider_locks())->safeUp()) { |
|
32
|
|
|
return false; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
return true; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @inheritdoc |
|
40
|
|
|
*/ |
|
41
|
|
|
public function safeDown() |
|
42
|
|
|
{ |
|
43
|
|
|
// Locks |
|
44
|
|
|
if (false === (new m181010_081033_provider_locks())->safeDown()) { |
|
45
|
|
|
return false; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$this->dropTableIfExists(TokensRecord::tableName()); |
|
49
|
|
|
$this->dropTableIfExists(ProviderRecord::tableName()); |
|
50
|
|
|
|
|
51
|
|
|
return true; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Creates the tables. |
|
56
|
|
|
* |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function createTables() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->createTable(TokensRecord::tableName(), [ |
|
62
|
|
|
'id' => $this->primaryKey(), |
|
63
|
|
|
'accessToken' => $this->text()->notNull(), |
|
64
|
|
|
'refreshToken' => $this->text(), |
|
65
|
|
|
'providerId' => $this->integer()->notNull(), |
|
66
|
|
|
'values' => $this->text(), |
|
67
|
|
|
'enabled' => $this->boolean(), |
|
68
|
|
|
'dateExpires' => $this->dateTime(), |
|
69
|
|
|
'dateUpdated' => $this->dateTime()->notNull(), |
|
70
|
|
|
'dateCreated' => $this->dateTime()->notNull(), |
|
71
|
|
|
'uid' => $this->uid() |
|
72
|
|
|
]); |
|
73
|
|
|
|
|
74
|
|
|
$this->createTable(ProviderRecord::tableName(), [ |
|
75
|
|
|
'id' => $this->primaryKey(), |
|
76
|
|
|
'handle' => $this->string()->notNull(), |
|
77
|
|
|
'clientId' => $this->string(ProviderRecord::CLIENT_ID_LENGTH)->notNull(), |
|
78
|
|
|
'clientSecret' => $this->string(ProviderRecord::CLIENT_SECRET_LENGTH), |
|
79
|
|
|
'scopes' => $this->string(), |
|
80
|
|
|
'class' => $this->string()->notNull(), |
|
81
|
|
|
'settings' => $this->text(), |
|
82
|
|
|
'enabled' => $this->boolean(), |
|
83
|
|
|
'dateUpdated' => $this->dateTime()->notNull(), |
|
84
|
|
|
'dateCreated' => $this->dateTime()->notNull(), |
|
85
|
|
|
'uid' => $this->uid() |
|
86
|
|
|
]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Creates the indexes. |
|
91
|
|
|
* |
|
92
|
|
|
* @return void |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function createIndexes() |
|
95
|
|
|
{ |
|
96
|
|
|
$this->createIndex( |
|
97
|
|
|
$this->db->getIndexName(TokensRecord::tableName(), 'providerId', false, true), |
|
98
|
|
|
TokensRecord::tableName(), |
|
99
|
|
|
'providerId', |
|
100
|
|
|
false |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Adds the foreign keys. |
|
106
|
|
|
* |
|
107
|
|
|
* @return void |
|
108
|
|
|
*/ |
|
109
|
|
|
protected function addForeignKeys() |
|
110
|
|
|
{ |
|
111
|
|
|
$this->addForeignKey( |
|
112
|
|
|
$this->db->getForeignKeyName(TokensRecord::tableName(), 'providerId'), |
|
113
|
|
|
TokensRecord::tableName(), |
|
114
|
|
|
'providerId', |
|
115
|
|
|
ProviderRecord::tableName(), |
|
116
|
|
|
'id', |
|
117
|
|
|
'CASCADE' |
|
118
|
|
|
); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|