1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use yii\db\Schema; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class m000000_093700_term |
7
|
|
|
* |
8
|
|
|
* @author Agiel K. Saputra <[email protected]> |
9
|
|
|
* @since 0.1.0 |
10
|
|
|
*/ |
11
|
|
View Code Duplication |
class m000000_000010_term extends \yii\db\Migration |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @inheritdoc |
15
|
|
|
*/ |
16
|
|
|
public function up() |
17
|
|
|
{ |
18
|
|
|
$tableOptions = null; |
19
|
|
|
|
20
|
|
|
if ($this->db->driverName === 'mysql') { |
21
|
|
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$this->createTable('{{%term}}', [ |
25
|
|
|
'id' => Schema::TYPE_PK, |
26
|
|
|
'taxonomy_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', |
27
|
|
|
'name' => Schema::TYPE_STRING . '(200) NOT NULL', |
28
|
|
|
'slug' => Schema::TYPE_STRING . '(200) NOT NULL', |
29
|
|
|
'description' => Schema::TYPE_TEXT, |
30
|
|
|
'parent' => Schema::TYPE_INTEGER . '(11) DEFAULT 0', |
31
|
|
|
'count' => Schema::TYPE_INTEGER . '(11) DEFAULT 0', |
32
|
|
|
'FOREIGN KEY ([[taxonomy_id]]) REFERENCES {{%taxonomy}} ([[id]]) ON DELETE CASCADE ON UPDATE CASCADE', |
33
|
|
|
], $tableOptions); |
34
|
|
|
|
35
|
|
|
$this->batchInsert('{{%term}}', ['taxonomy_id', 'name', 'slug', 'description', 'parent', 'count'], [ |
36
|
|
|
['1', 'Sample Category', 'sample-category', 'Hello there, this is example of category.', 0, '1'], |
37
|
|
|
['2', 'Sample Tag', 'sample-tag', 'Hello there, this is an example of tag.', 0, '1'], |
38
|
|
|
]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritdoc |
43
|
|
|
*/ |
44
|
|
|
public function down() |
45
|
|
|
{ |
46
|
|
|
$this->dropTable('{{%term}}'); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.