-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1434983278_init.php
More file actions
183 lines (171 loc) · 5.02 KB
/
1434983278_init.php
File metadata and controls
183 lines (171 loc) · 5.02 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
* Init migration
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
/**
* Init migration
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\Containers\Config\Migration
*/
class Init extends CakeMigration {
/**
* Migration description
*
* @var string
*/
public $description = 'init';
/**
* Actions to be performed
*
* @var array $migration
*/
public $migration = array(
'up' => array(
'create_table' => array(
'containers' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
'type' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => 'Type of the container. 1:Header, 2:Major, 3:Main, 4:Minor, 5:Footer'),
'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
),
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'),
),
'containers_pages' => array(
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
'page_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
'container_id' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
'is_published' => array('type' => 'boolean', 'null' => true, 'default' => null, 'comment' => '一般以下のパートが閲覧可能かどうか。ルーム配下ならルーム管理者、またはそれに準ずるユーザはこの値に関わらず閲覧できる。 e.g.) ルーム管理者、またはそれに準ずるユーザ: ルーム管理者、編集長'),
'is_configured' => array('type' => 'boolean', 'null' => false, 'default' => false, 'comment' => '設定したかどうか'),
'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false),
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
),
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'),
),
),
),
'down' => array(
'drop_table' => array(
'containers', 'containers_pages'
),
),
);
/**
* Records keyed by model name.
*
* @var array $records
*/
public $records = array(
'Container' => array(
array(
'id' => '1',
'type' => '1',
),
array(
'id' => '2',
'type' => '2',
),
array (
'id' => '3',
'type' => '3',
),
array(
'id' => '4',
'type' => '4',
),
array(
'id' => '5',
'type' => '5',
),
),
'ContainersPage' => array(
array(
'id' => '1',
'page_id' => '1',
'container_id' => '1',
'is_published' => true,
),
array(
'id' => '2',
'page_id' => '1',
'container_id' => '2',
'is_published' => true,
),
array(
'id' => '3',
'page_id' => '1',
'container_id' => '3',
'is_published' => true,
),
array(
'id' => '4',
'page_id' => '1',
'container_id' => '4',
'is_published' => true,
),
array(
'id' => '5',
'page_id' => '1',
'container_id' => '5',
'is_published' => true,
),
),
);
/**
* Before migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function before($direction) {
return true;
}
/**
* After migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function after($direction) {
if ($direction === 'down') {
return true;
}
foreach ($this->records as $model => $records) {
if (!$this->updateRecords($model, $records)) {
return false;
}
}
return true;
}
/**
* Update model records
*
* @param string $model model name to update
* @param string $records records to be stored
* @param string $scope ?
* @return bool Should process continue
*/
public function updateRecords($model, $records, $scope = null) {
$Model = $this->generateModel($model);
foreach ($records as $record) {
$Model->create();
if (!$Model->save($record, false)) {
return false;
}
}
return true;
}
}