-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Install.php
85 lines (73 loc) · 2.64 KB
/
Install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace verbb\cpnav\migrations;
use Craft;
use craft\db\Migration;
class Install extends Migration
{
// Public Methods
// =========================================================================
public function safeUp()
{
$this->createTables();
$this->addForeignKeys();
return true;
}
public function safeDown()
{
$this->removeTables();
$this->dropProjectConfig();
return true;
}
public function createTables()
{
$this->createTable('{{%cpnav_layout}}', [
'id' => $this->primaryKey(),
'name' => $this->string(255),
'isDefault' => $this->boolean()->notNull()->defaultValue(false),
'permissions' => $this->text(),
'sortOrder' => $this->smallInteger()->unsigned(),
'dateCreated' => $this->dateTime()->notNull(),
'dateUpdated' => $this->dateTime()->notNull(),
'uid' => $this->uid(),
]);
$this->createTable('{{%cpnav_navigation}}', [
'id' => $this->primaryKey(),
'layoutId' => $this->integer()->notNull(),
'handle' => $this->string(255),
'prevLabel' => $this->string(255),
'currLabel' => $this->string(255),
'enabled' => $this->boolean()->notNull()->defaultValue(true),
'order' => $this->integer()->defaultValue(0),
'prevUrl' => $this->string(255),
'url' => $this->string(255),
'icon' => $this->string(255),
'customIcon' => $this->string(255),
'type' => $this->string(),
'newWindow' => $this->boolean()->notNull()->defaultValue(false),
'dateCreated' => $this->dateTime()->notNull(),
'dateUpdated' => $this->dateTime()->notNull(),
'uid' => $this->uid(),
]);
$this->createTable('{{%cpnav_pending_navigations}}', [
'id' => $this->primaryKey(),
'pluginNavItem' => $this->text(),
'dateCreated' => $this->dateTime()->notNull(),
'dateUpdated' => $this->dateTime()->notNull(),
'uid' => $this->uid(),
]);
}
public function addForeignKeys()
{
$this->addForeignKey(null, '{{%cpnav_navigation}}', ['layoutId'], '{{%cpnav_layout}}', ['id'], 'CASCADE', null);
}
public function removeTables()
{
$this->dropTableIfExists('{{%cpnav_navigation}}');
$this->dropTableIfExists('{{%cpnav_layout}}');
$this->dropTableIfExists('{{%cpnav_pending_navigations}}');
}
public function dropProjectConfig()
{
Craft::$app->projectConfig->remove('cp-nav');
}
}