1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Bluz PHP Team |
4
|
|
|
* @link https://github.com/bluzphp/skeleton |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
use Phinx\Migration\AbstractMigration; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* CreateMediaTable |
11
|
|
|
*/ |
12
|
|
|
class ModuleMedia extends AbstractMigration |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Change Method. |
16
|
|
|
* |
17
|
|
|
* Write your reversible migrations using this method. |
18
|
|
|
* |
19
|
|
|
* More information on writing migrations is available here: |
20
|
|
|
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class |
21
|
|
|
* |
22
|
|
|
* The following commands can be used in this method and Phinx will |
23
|
|
|
* automatically reverse them when rolling back: |
24
|
|
|
* |
25
|
|
|
* createTable |
26
|
|
|
* renameTable |
27
|
|
|
* addColumn |
28
|
|
|
* renameColumn |
29
|
|
|
* addIndex |
30
|
|
|
* addForeignKey |
31
|
|
|
* |
32
|
|
|
* Remember to call "create()" or "update()" and NOT "save()" when working |
33
|
|
|
* with the Table class. |
34
|
|
|
*/ |
35
|
|
|
public function change() |
36
|
|
|
{ |
37
|
|
|
$table = $this->table('media'); |
38
|
|
|
$table |
39
|
|
|
->addColumn('module', 'string', ['length' => 255, 'default' => 'users']) |
40
|
|
|
->addColumn('title', 'text') |
41
|
|
|
->addColumn('type', 'string', ['length' => 255]) |
42
|
|
|
->addColumn('file', 'string', ['length' => 255]) |
43
|
|
|
->addColumn('thumb', 'string', ['length' => 255]) |
44
|
|
|
->addColumn('size', 'integer') |
45
|
|
|
->addTimestamps('created', 'updated') |
46
|
|
|
->addForeignKey('userId', 'users', 'id', [ |
47
|
|
|
'delete' => 'CASCADE', |
48
|
|
|
'update' => 'CASCADE' |
49
|
|
|
]) |
50
|
|
|
->create(); |
51
|
|
|
|
52
|
|
|
$data = [ |
53
|
|
|
[ |
54
|
|
|
'roleId' => 2, |
55
|
|
|
'module' => 'media', |
56
|
|
|
'privilege' => 'Management' |
57
|
|
|
], |
58
|
|
|
[ |
59
|
|
|
'roleId' => 2, |
60
|
|
|
'module' => 'media', |
61
|
|
|
'privilege' => 'Upload' |
62
|
|
|
], |
63
|
|
|
[ |
64
|
|
|
'roleId' => 3, |
65
|
|
|
'module' => 'media', |
66
|
|
|
'privilege' => 'Upload' |
67
|
|
|
], |
68
|
|
|
]; |
69
|
|
|
|
70
|
|
|
$privileges = $this->table('acl_privileges'); |
71
|
|
|
$privileges->insert($data) |
72
|
|
|
->save(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.