1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Schema; |
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
5
|
|
|
use Uccello\Core\Database\Migrations\Migration; |
6
|
|
|
use Uccello\Core\Database\Migrations\Traits\TablePrefixTrait; |
7
|
|
|
use Uccello\Core\Models\Module; |
8
|
|
|
use Uccello\Core\Models\Domain; |
9
|
|
|
use Uccello\Core\Models\Tab; |
10
|
|
|
use Uccello\Core\Models\Block; |
11
|
|
|
use Uccello\Core\Models\Field; |
12
|
|
|
use Uccello\Core\Models\Filter; |
13
|
|
|
use Uccello\Core\Models\Menu; |
14
|
|
|
use Uccello\Core\Models\Relatedlist; |
15
|
|
|
use Uccello\Core\Models\Link; |
16
|
|
|
|
17
|
|
|
// TODO... |
18
|
|
|
|
19
|
|
|
class CreateGroupModule extends Migration |
20
|
|
|
{ |
21
|
|
|
use TablePrefixTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Run the migrations. |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
|
|
public function up() |
29
|
|
|
{ |
30
|
|
|
$module = $this->createModule(); |
31
|
|
|
$this->createTables(); |
32
|
|
|
$this->activateModuleOnDomains($module); |
33
|
|
|
$this->updateMenu(); |
34
|
|
|
$this->createTabsBlocksFields($module); |
35
|
|
|
$this->createFilters($module); |
36
|
|
|
$this->createRelatedLists($module); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Reverse the migrations. |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function down() |
45
|
|
|
{ |
46
|
|
|
// Drop table |
47
|
|
|
Schema::dropIfExists($this->tablePrefix . 'groups'); |
48
|
|
|
Schema::dropIfExists($this->tablePrefix . 'rl_groups_groups'); |
49
|
|
|
Schema::dropIfExists($this->tablePrefix . 'rl_groups_users'); |
50
|
|
|
|
51
|
|
|
// Delete module |
52
|
|
|
Module::where('name', 'group')->forceDelete(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function createTables() |
56
|
|
|
{ |
57
|
|
|
// Module Table |
58
|
|
|
Schema::create($this->tablePrefix . 'groups', function (Blueprint $table) { |
59
|
|
|
$table->increments('id'); |
60
|
|
|
$table->string('name')->nullable(); |
61
|
|
|
$table->text('description')->nullable(); |
62
|
|
|
$table->timestamps(); |
63
|
|
|
$table->softDeletes(); |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
// Related List Table: Groups-Groups |
67
|
|
|
Schema::create($this->tablePrefix . 'rl_groups_groups', function (Blueprint $table) { |
68
|
|
|
$table->increments('id'); |
69
|
|
|
$table->unsignedInteger('parent_id'); |
70
|
|
|
$table->unsignedInteger('children_id'); |
71
|
|
|
$table->timestamps(); |
72
|
|
|
|
73
|
|
|
// Foreign keys |
74
|
|
|
$table->foreign('parent_id') |
75
|
|
|
->references('id')->on($this->tablePrefix . 'groups') |
76
|
|
|
->onDelete('cascade'); |
77
|
|
|
|
78
|
|
|
$table->foreign('children_id') |
79
|
|
|
->references('id')->on($this->tablePrefix . 'groups') |
80
|
|
|
->onDelete('cascade'); |
81
|
|
|
|
82
|
|
|
// Unique keys |
83
|
|
|
$table->unique(['parent_id', 'children_id']); |
84
|
|
|
}); |
85
|
|
|
|
86
|
|
|
// Related List Table: Groups-Users |
87
|
|
|
Schema::create($this->tablePrefix . 'rl_groups_users', function (Blueprint $table) { |
88
|
|
|
$table->increments('id'); |
89
|
|
|
$table->unsignedInteger('group_id'); |
90
|
|
|
$table->unsignedInteger('user_id'); |
91
|
|
|
$table->timestamps(); |
92
|
|
|
|
93
|
|
|
// Foreign keys |
94
|
|
|
$table->foreign('group_id') |
95
|
|
|
->references('id')->on($this->tablePrefix . 'groups') |
96
|
|
|
->onDelete('cascade'); |
97
|
|
|
|
98
|
|
|
$table->foreign('user_id') |
99
|
|
|
->references('id')->on('users') |
100
|
|
|
->onDelete('cascade'); |
101
|
|
|
|
102
|
|
|
// Unique keys |
103
|
|
|
$table->unique(['group_id', 'user_id']); |
104
|
|
|
}); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
protected function createModule() |
108
|
|
|
{ |
109
|
|
|
$module = new Module(); |
110
|
|
|
$module->name = 'group'; |
|
|
|
|
111
|
|
|
$module->icon = 'group'; |
|
|
|
|
112
|
|
|
$module->model_class = 'Uccello\Core\Models\Group'; |
|
|
|
|
113
|
|
|
$module->data = [ "package" => "uccello/uccello", "admin" => true, "mandatory" => true ]; |
|
|
|
|
114
|
|
|
$module->save(); |
115
|
|
|
|
116
|
|
|
return $module; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
protected function createTabsBlocksFields($module) |
120
|
|
|
{ |
121
|
|
|
// Main tab |
122
|
|
|
$tab = new Tab(); |
123
|
|
|
$tab->label = 'tab.main'; |
|
|
|
|
124
|
|
|
$tab->icon = null; |
|
|
|
|
125
|
|
|
$tab->sequence = 0; |
|
|
|
|
126
|
|
|
$tab->module_id = $module->id; |
|
|
|
|
127
|
|
|
$tab->save(); |
128
|
|
|
|
129
|
|
|
// General block |
130
|
|
|
$block = new Block(); |
131
|
|
|
$block->label = 'block.general'; |
|
|
|
|
132
|
|
|
$block->icon = 'group'; |
|
|
|
|
133
|
|
|
$block->sequence = 0; |
|
|
|
|
134
|
|
|
$block->tab_id = $tab->id; |
|
|
|
|
135
|
|
|
$block->module_id = $module->id; |
|
|
|
|
136
|
|
|
$block->save(); |
137
|
|
|
|
138
|
|
|
// Name |
139
|
|
|
$field = new Field(); |
140
|
|
|
$field->name = 'name'; |
|
|
|
|
141
|
|
|
$field->uitype_id = uitype('text')->id; |
|
|
|
|
142
|
|
|
$field->displaytype_id = displaytype('everywhere')->id; |
|
|
|
|
143
|
|
|
$field->data = [ 'rules' => 'required' ]; |
|
|
|
|
144
|
|
|
$field->sequence = 0; |
|
|
|
|
145
|
|
|
$field->block_id = $block->id; |
|
|
|
|
146
|
|
|
$field->module_id = $module->id; |
|
|
|
|
147
|
|
|
$field->save(); |
148
|
|
|
|
149
|
|
|
// Description |
150
|
|
|
$field = new Field(); |
151
|
|
|
$field->name = 'description'; |
152
|
|
|
$field->uitype_id = uitype('textarea')->id; |
153
|
|
|
$field->displaytype_id = displaytype('everywhere')->id; |
154
|
|
|
$field->data = null; |
155
|
|
|
$field->sequence = 1; |
156
|
|
|
$field->block_id = $block->id; |
157
|
|
|
$field->module_id = $module->id; |
158
|
|
|
$field->save(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
protected function createFilters($module) |
162
|
|
|
{ |
163
|
|
|
$filter = new Filter(); |
164
|
|
|
$filter->module_id = $module->id; |
|
|
|
|
165
|
|
|
$filter->domain_id = null; |
|
|
|
|
166
|
|
|
$filter->user_id = null; |
|
|
|
|
167
|
|
|
$filter->name = 'filter.all'; |
|
|
|
|
168
|
|
|
$filter->type = 'list'; |
|
|
|
|
169
|
|
|
$filter->columns = [ 'name', 'description']; |
|
|
|
|
170
|
|
|
$filter->conditions = null; |
|
|
|
|
171
|
|
|
$filter->order_by = null; |
|
|
|
|
172
|
|
|
$filter->is_default = true; |
|
|
|
|
173
|
|
|
$filter->is_public = false; |
|
|
|
|
174
|
|
|
$filter->data = [ 'readonly' => true ]; |
|
|
|
|
175
|
|
|
$filter->save(); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
protected function activateModuleOnDomains($module) |
179
|
|
|
{ |
180
|
|
|
$domains = Domain::all(); |
181
|
|
|
foreach ($domains as $domain) { |
182
|
|
|
$domain->modules()->attach($module); |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
protected function createRelatedLists($module) |
187
|
|
|
{ |
188
|
|
|
// Related List groups |
189
|
|
|
//$relatedModule = Module::where('name', $this->tablePrefix . 'group')->first(); |
190
|
|
|
|
191
|
|
|
Relatedlist::create([ |
192
|
|
|
'module_id' => $module->id, |
193
|
|
|
'related_module_id' => $module->id, |
194
|
|
|
'tab_id' => null, |
195
|
|
|
'related_field_id' => null, |
196
|
|
|
'label' => 'relatedlist.childrenGroups', |
197
|
|
|
'type' => 'n-n', |
198
|
|
|
'method' => 'getRelatedList', |
199
|
|
|
'data' => [ |
200
|
|
|
"relationName" => "childrenGroups", |
201
|
|
|
"actions" => ["select", "add"] |
202
|
|
|
], |
203
|
|
|
'sequence' => 0 |
204
|
|
|
]); |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
// Related List users |
208
|
|
|
$relatedModule = Module::where('name', 'user')->first(); |
209
|
|
|
|
210
|
|
|
Relatedlist::create([ |
211
|
|
|
'module_id' => $module->id, |
212
|
|
|
'related_module_id' => $relatedModule->id, |
213
|
|
|
'tab_id' => null, |
214
|
|
|
'related_field_id' => null, |
215
|
|
|
'label' => 'relatedlist.users', |
216
|
|
|
'type' => 'n-n', |
217
|
|
|
'method' => 'getRelatedList', |
218
|
|
|
'data' => ["actions" => ["select", "add"]], |
219
|
|
|
'sequence' => 1 |
220
|
|
|
]); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
protected function updateMenu() |
224
|
|
|
{ |
225
|
|
|
// Add default admin menu |
226
|
|
|
// TODO: Translate |
227
|
|
|
$menu = Menu::find(1); |
228
|
|
|
$menu->data = json_decode('[ |
|
|
|
|
229
|
|
|
{ |
230
|
|
|
"color":"grey", |
231
|
|
|
"nochildren":false, |
232
|
|
|
"icon":"settings", |
233
|
|
|
"translation":"Dashboard", |
234
|
|
|
"label":"menu.dashboard", |
235
|
|
|
"type":"module", |
236
|
|
|
"route":"uccello.settings.dashboard", |
237
|
|
|
"module":"settings", |
238
|
|
|
"id":1 |
239
|
|
|
}, |
240
|
|
|
{ |
241
|
|
|
"color":"green", |
242
|
|
|
"nochildren":false, |
243
|
|
|
"icon":"lock", |
244
|
|
|
"label":"menu.security", |
245
|
|
|
"type":"group", |
246
|
|
|
"id":2, |
247
|
|
|
"children":[ |
248
|
|
|
{ |
249
|
|
|
"color":"grey", |
250
|
|
|
"nochildren":false, |
251
|
|
|
"icon":"person", |
252
|
|
|
"translation":"Users", |
253
|
|
|
"label":"user", |
254
|
|
|
"type":"module", |
255
|
|
|
"route":"uccello.list", |
256
|
|
|
"module":"user", |
257
|
|
|
"id":3 |
258
|
|
|
}, |
259
|
|
|
{ |
260
|
|
|
"color":"grey", |
261
|
|
|
"nochildren":false, |
262
|
|
|
"icon":"group", |
263
|
|
|
"translation":"Group", |
264
|
|
|
"label":"group", |
265
|
|
|
"type":"module", |
266
|
|
|
"route":"uccello.list", |
267
|
|
|
"module":"group", |
268
|
|
|
"id":4 |
269
|
|
|
}, |
270
|
|
|
{ |
271
|
|
|
"color":"grey", |
272
|
|
|
"nochildren":false, |
273
|
|
|
"icon":"domain", |
274
|
|
|
"translation":"Domains", |
275
|
|
|
"label":"domain", |
276
|
|
|
"type":"module", |
277
|
|
|
"route":"uccello.list", |
278
|
|
|
"module":"domain", |
279
|
|
|
"id":5 |
280
|
|
|
}, |
281
|
|
|
{ |
282
|
|
|
"color":"grey", |
283
|
|
|
"nochildren":false, |
284
|
|
|
"icon":"lock", |
285
|
|
|
"translation":"Roles", |
286
|
|
|
"label":"role", |
287
|
|
|
"type":"module", |
288
|
|
|
"route":"uccello.list", |
289
|
|
|
"module":"role", |
290
|
|
|
"id":6 |
291
|
|
|
}, |
292
|
|
|
{ |
293
|
|
|
"color":"grey", |
294
|
|
|
"nochildren":false, |
295
|
|
|
"icon":"lock", |
296
|
|
|
"translation":"Profiles", |
297
|
|
|
"label":"profile", |
298
|
|
|
"type":"module", |
299
|
|
|
"route":"uccello.list", |
300
|
|
|
"module":"profile", |
301
|
|
|
"id":7 |
302
|
|
|
} |
303
|
|
|
] |
304
|
|
|
}, |
305
|
|
|
{ |
306
|
|
|
"color":"green", |
307
|
|
|
"nochildren":false, |
308
|
|
|
"icon":"settings", |
309
|
|
|
"label":"menu.settings", |
310
|
|
|
"type":"group", |
311
|
|
|
"id":7, |
312
|
|
|
"children":[ |
313
|
|
|
{ |
314
|
|
|
"color":"grey", |
315
|
|
|
"nochildren":false, |
316
|
|
|
"icon":"extension", |
317
|
|
|
"translation":"Module manager", |
318
|
|
|
"label":"module_manager.link", |
319
|
|
|
"type":"module", |
320
|
|
|
"route":"uccello.settings.module.manager", |
321
|
|
|
"module":"settings", |
322
|
|
|
"id":8 |
323
|
|
|
}, |
324
|
|
|
{ |
325
|
|
|
"color":"grey", |
326
|
|
|
"nochildren":false, |
327
|
|
|
"icon":"menu", |
328
|
|
|
"translation":"Menu manager", |
329
|
|
|
"label":"menu_manager.link", |
330
|
|
|
"type":"module", |
331
|
|
|
"route":"uccello.settings.menu.manager", |
332
|
|
|
"module":"settings", |
333
|
|
|
"id":9 |
334
|
|
|
} |
335
|
|
|
] |
336
|
|
|
} |
337
|
|
|
]'); |
338
|
|
|
$menu->save(); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
} |
342
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.