|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link https://dukt.net/facebook/ |
|
4
|
|
|
* @copyright Copyright (c) 2021, Dukt |
|
5
|
|
|
* @license https://github.com/dukt/facebook/blob/master/LICENSE.md |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace dukt\facebook\migrations; |
|
9
|
|
|
|
|
10
|
|
|
use Craft; |
|
11
|
|
|
use craft\db\Migration; |
|
12
|
|
|
|
|
13
|
|
|
class Install extends Migration |
|
14
|
|
|
{ |
|
15
|
|
|
// Public Properties |
|
16
|
|
|
// ========================================================================= |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string The database driver to use |
|
20
|
|
|
*/ |
|
21
|
|
|
public $driver; |
|
22
|
|
|
|
|
23
|
|
|
// Public Methods |
|
24
|
|
|
// ========================================================================= |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* This method contains the logic to be executed when applying this migration. |
|
28
|
|
|
* This method differs from [[up()]] in that the DB logic implemented here will |
|
29
|
|
|
* be enclosed within a DB transaction. |
|
30
|
|
|
* Child classes may implement this method instead of [[up()]] if the DB logic |
|
31
|
|
|
* needs to be within a transaction. |
|
32
|
|
|
* |
|
33
|
|
|
* @return boolean return a false value to indicate the migration fails |
|
34
|
|
|
* and should not proceed further. All other return values mean the migration succeeds. |
|
35
|
|
|
*/ |
|
36
|
|
|
public function safeUp() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->driver = Craft::$app->getConfig()->getDb()->driver; |
|
39
|
|
|
$this->createTables(); |
|
40
|
|
|
|
|
41
|
|
|
return true; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* This method contains the logic to be executed when removing this migration. |
|
46
|
|
|
* This method differs from [[down()]] in that the DB logic implemented here will |
|
47
|
|
|
* be enclosed within a DB transaction. |
|
48
|
|
|
* Child classes may implement this method instead of [[down()]] if the DB logic |
|
49
|
|
|
* needs to be within a transaction. |
|
50
|
|
|
* |
|
51
|
|
|
* @return boolean return a false value to indicate the migration fails |
|
52
|
|
|
* and should not proceed further. All other return values mean the migration succeeds. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function safeDown() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->driver = Craft::$app->getConfig()->getDb()->driver; |
|
57
|
|
|
$this->removeTables(); |
|
58
|
|
|
|
|
59
|
|
|
return true; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
// Protected Methods |
|
63
|
|
|
// ========================================================================= |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Creates the tables needed for the Records used by the plugin |
|
67
|
|
|
* |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function createTables() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->createTable( |
|
73
|
|
|
'{{%facebook_accounts}}', |
|
74
|
|
|
[ |
|
75
|
|
|
'id' => $this->primaryKey(), |
|
76
|
|
|
'token' => $this->text(), |
|
77
|
|
|
'dateCreated' => $this->dateTime()->notNull(), |
|
78
|
|
|
'dateUpdated' => $this->dateTime()->notNull(), |
|
79
|
|
|
'uid' => $this->uid() |
|
80
|
|
|
] |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Removes the tables needed for the Records used by the plugin |
|
86
|
|
|
* |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function removeTables() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->dropTable('{{%facebook_accounts}}'); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|