|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use yii\db\Schema; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class m000000_000008_taxonomy. |
|
7
|
|
|
* Migration class for taxonomy. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Agiel K. Saputra <[email protected]> |
|
10
|
|
|
* @since 0.1.0 |
|
11
|
|
|
*/ |
|
12
|
|
View Code Duplication |
class m000000_000008_taxonomy extends \yii\db\Migration |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @inheritdoc |
|
16
|
|
|
*/ |
|
17
|
|
|
public function up() |
|
18
|
|
|
{ |
|
19
|
|
|
$tableOptions = null; |
|
20
|
|
|
|
|
21
|
|
|
if ($this->db->driverName === 'mysql') { |
|
22
|
|
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
$this->createTable('{{%taxonomy}}', [ |
|
26
|
|
|
'id' => Schema::TYPE_PK, |
|
27
|
|
|
'name' => Schema::TYPE_STRING . '(200) NOT NULL', |
|
28
|
|
|
'slug' => Schema::TYPE_STRING . '(200) NOT NULL', |
|
29
|
|
|
'hierarchical' => Schema::TYPE_SMALLINT . '(1) NOT NULL DEFAULT 0', |
|
30
|
|
|
'singular_name' => Schema::TYPE_STRING . '(255) NOT NULL', |
|
31
|
|
|
'plural_name' => Schema::TYPE_STRING . '(255) NOT NULL', |
|
32
|
|
|
'menu_builder' => Schema::TYPE_SMALLINT . '(1) NOT NULL DEFAULT 0', |
|
33
|
|
|
], $tableOptions); |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Add two taxonomies, that are category and tag |
|
37
|
|
|
*/ |
|
38
|
|
|
$this->batchInsert( |
|
39
|
|
|
'{{%taxonomy}}', |
|
40
|
|
|
['name', 'slug', 'hierarchical', 'singular_name', 'plural_name', 'menu_builder'], [ |
|
41
|
|
|
['category', 'category', '1', 'Category', 'Categories', 1], |
|
42
|
|
|
['tag', 'tag', '0', 'Tag', 'Tags', 0], |
|
43
|
|
|
] |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @inheritdoc |
|
49
|
|
|
*/ |
|
50
|
|
|
public function down() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->dropTable('{{%taxonomy}}'); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
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.