Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
m120321_154445_right.php
1 <?php
2 /**
3  * Gentics Portal.Node PHP
4  * Author & Copyright (c) by Gentics Software GmbH
5  * sales@gentics.com
6  * http://www.gentics.com
7  * Licenses can be found in the LICENSE.txt file in the root-folder of this installation
8  * You must not use this software without a valid license agreement.
9  */
10 class m120321_154445_right extends CDbMigration
11 {
12  public function safeUp()
13  {
14  $this->createTable('AuthItem', array(
15  'name' => 'string',
16  'type' => 'integer not null',
17  'description' => 'text',
18  'bizrule' => 'text',
19  'data' => 'text',
20  ));
21  $this->createIndex('name', 'AuthItem', 'name', true);
22 
23  $this->createTable('AuthItemChild', array(
24  'parent' => 'string not null',
25  'child' => 'string not null',
26  ));
27  $this->createIndex('AuthItemChild_parent_idx', 'AuthItemChild', 'parent');
28  $this->createIndex('AuthItemChild_child_idx', 'AuthItemChild', 'child');
29 
30  $this->addForeignKey('parent_name_ref', 'AuthItemChild', 'parent', 'AuthItem', 'name', 'cascade', 'cascade');
31  $this->addForeignKey('child_name_ref', 'AuthItemChild', 'child', 'AuthItem', 'name', 'cascade', 'cascade');
32 
33  $this->createTable('AuthAssignment', array(
34  'itemname' => 'string not null',
35  'userid' => 'integer not null',
36  'bizrule' => 'text',
37  'data' => 'text',
38  ));
39  $this->createIndex('AuthAssignment_itemname_userid_idx', 'AuthAssignment', 'itemname, userid');
40 
41  $this->addForeignKey('assign_itemname_name_ref', 'AuthAssignment', 'itemname', 'AuthItem', 'name', 'cascade', 'cascade');
42 
43  $this->createTable('Rights', array(
44  'itemname' => 'string not null',
45  'type' => 'integer not null',
46  'weight' => 'integer not null',
47  ));
48  $this->createIndex('Rights_itemname_idx', 'Rights', 'itemname');
49 
50  $this->addForeignKey('right_itemname_name_ref', 'Rights', 'itemname', 'AuthItem', 'name', 'cascade', 'cascade');
51 
52  $this->insert('AuthItem', array(
53  'name' => 'Admin',
54  'type' => '2',
55  'description' => 'Administrator',
56  'bizrule' => null,
57  'data' => 'N;'
58  ));
59 
60  $res = Yii::app()->db->createCommand()->select('id')->from('{{users}}')
61  ->where('username=:username', array(':username' => 'admin'))
62  ->queryRow();
63  $this->insert('AuthAssignment', array(
64  'itemname' => 'Admin',
65  'userid' => $res['id'],
66  'bizrule' => null,
67  'data' => 'N;'
68  ));
69  }
70 
71  public function safeDown()
72  {
73  $this->dropTable('Rights');
74  $this->dropTable('AuthItemChild');
75  $this->dropTable('AuthAssignment');
76  $this->dropTable('AuthItem');
77  }
78 
79 }