Passed
Push — develop ( bcbfe3...88a0b1 )
by Benjamin
05:49
created

Install::removeIndexes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @link      https://dukt.net/videos/
4
 * @copyright Copyright (c) 2019, Dukt
5
 * @license   https://github.com/dukt/videos/blob/v2/LICENSE.md
6
 */
7
8
namespace dukt\videos\migrations;
9
10
use Craft;
11
use craft\db\Migration;
12
use dukt\videos\models\Info;
0 ignored issues
show
Bug introduced by
The type dukt\videos\models\Info was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use dukt\videos\Plugin;
14
15
class Install extends Migration
16
{
17
    // Public Properties
18
    // =========================================================================
19
20
    /**
21
     * @var string The database driver to use
22
     */
23
    public $driver;
24
25
    // Public Methods
26
    // =========================================================================
27
28
    /**
29
     * This method contains the logic to be executed when applying this migration.
30
     * This method differs from [[up()]] in that the DB logic implemented here will
31
     * be enclosed within a DB transaction.
32
     * Child classes may implement this method instead of [[up()]] if the DB logic
33
     * needs to be within a transaction.
34
     *
35
     * @return boolean return a false value to indicate the migration fails
36
     * and should not proceed further. All other return values mean the migration succeeds.
37
     */
38
    public function safeUp()
39
    {
40
        $this->driver = Craft::$app->getConfig()->getDb()->driver;
41
        $this->createTables();
42
        $this->createIndexes();
43
        $this->addForeignKeys();
44
        $this->insertDefaultData();
45
46
        return true;
47
    }
48
49
    /**
50
     * This method contains the logic to be executed when removing this migration.
51
     * This method differs from [[down()]] in that the DB logic implemented here will
52
     * be enclosed within a DB transaction.
53
     * Child classes may implement this method instead of [[down()]] if the DB logic
54
     * needs to be within a transaction.
55
     *
56
     * @return boolean return a false value to indicate the migration fails
57
     * and should not proceed further. All other return values mean the migration succeeds.
58
     */
59
    public function safeDown()
60
    {
61
        $this->driver = Craft::$app->getConfig()->getDb()->driver;
62
        $this->removeForeignKeys();
63
        $this->removeIndexes();
64
        $this->removeTables();
65
66
        return true;
67
    }
68
69
    // Protected Methods
70
    // =========================================================================
71
72
    /**
73
     * Creates the tables needed for the Records used by the plugin
74
     *
75
     * @return void
76
     */
77
    protected function createTables()
78
    {
79
        $this->createTable(
80
            '{{%videos_tokens}}',
81
            [
82
                'id' => $this->primaryKey(),
83
                'gateway' => $this->string()->notNull(),
84
                'accessToken' => $this->text(),
85
86
                'dateCreated' => $this->dateTime()->notNull(),
87
                'dateUpdated' => $this->dateTime()->notNull(),
88
                'uid' => $this->uid()
89
            ]
90
        );
91
    }
92
93
    /**
94
     * Creates the indexes needed for the Records used by the plugin
95
     *
96
     * @return void
97
     */
98
    protected function createIndexes()
99
    {
100
        $this->createIndex(null, '{{%videos_tokens}}', 'gateway', true);
101
    }
102
103
    /**
104
     * Creates the foreign keys needed for the Records used by the plugin
105
     *
106
     * @return void
107
     */
108
    protected function addForeignKeys()
109
    {
110
    }
111
112
    /**
113
     * Populates the DB with the default data.
114
     *
115
     * @return void
116
     */
117
    protected function insertDefaultData()
118
    {
119
    }
120
121
    /**
122
     * Removes the tables needed for the Records used by the plugin
123
     *
124
     * @return void
125
     */
126
    protected function removeTables()
127
    {
128
        $this->dropTable('{{%videos_tokens}}');
129
    }
130
131
    /**
132
     * Removes the indexes needed for the Records used by the plugin
133
     *
134
     * @return void
135
     */
136
    protected function removeIndexes()
137
    {
138
        $this->dropIndex($this->db->getIndexName('{{%videos_tokens}}', 'gateway', true), '{{%videos_tokens}}');
139
    }
140
141
    /**
142
     * Removes the foreign keys needed for the Records used by the plugin
143
     *
144
     * @return void
145
     */
146
    protected function removeForeignKeys()
147
    {
148
    }
149
}
150