12 const ERROR_QUERY_FAILED=1;
21 public $superuserName;
25 public $authenticatedName;
33 private $_authManager;
55 $authManager = Yii::app()->getAuthManager();
57 throw new CException(
Rights::t(
'install',
'Application authorization manager must extend the RDbAuthManager class.'));
61 $user = Yii::app()->getUser();
62 if( ($user instanceof
RWebUser)===
false )
63 throw new CException(
Rights::t(
'install',
'Application web user must extend the RWebUser class.'));
65 $this->_authManager = $authManager;
66 $this->db = $this->_authManager->db;
77 $itemTable = $this->_authManager->itemTable;
78 $itemChildTable = $this->_authManager->itemChildTable;
79 $assignmentTable = $this->_authManager->assignmentTable;
80 $rightsTable = $this->_authManager->rightsTable;
83 $schema = file_get_contents(dirname(__FILE__).
'/../data/schema.sql');
86 $schema = strtr($schema, array(
87 'AuthItem'=>$itemTable,
88 'AuthItemChild'=>$itemChildTable,
89 'AuthAssignment'=>$assignmentTable,
90 'Rights'=>$rightsTable,
94 $schema = preg_split(
"/;\s*/", trim($schema,
';'));
97 $txn = $this->db->beginTransaction();
102 foreach( $schema as $sql )
104 $command = $this->db->createCommand($sql);
109 $roles = $this->getUniqueRoles();
110 foreach( $roles as $roleName )
112 $sql =
"INSERT INTO {$itemTable} (name, type, data)
113 VALUES (:name, :type, :data)";
114 $command = $this->db->createCommand($sql);
115 $command->bindValue(
':name', $roleName);
116 $command->bindValue(
':type', CAuthItem::TYPE_ROLE);
117 $command->bindValue(
':data',
'N;');
122 $sql =
"INSERT INTO {$assignmentTable} (itemname, userid, data)
123 VALUES (:itemname, :userid, :data)";
124 $command = $this->db->createCommand($sql);
125 $command->bindValue(
':itemname', $this->superuserName);
126 $command->bindValue(
':userid', Yii::app()->getUser()->
id);
127 $command->bindValue(
':data',
'N;');
132 return self::ERROR_NONE;
134 catch( CDbException $e )
139 return self::ERROR_QUERY_FAILED;
147 private function getUniqueRoles()
149 $roles = CMap::mergeArray($this->defaultRoles, array(
150 $this->superuserName,
151 $this->authenticatedName,
154 return array_unique($roles);
162 if( $this->_installed!==null )
164 return $this->_installed;
169 "SELECT COUNT(*) FROM {$this->_authManager->itemTable}",
170 "SELECT COUNT(*) FROM {$this->_authManager->itemChildTable}",
171 "SELECT COUNT(*) FROM {$this->_authManager->assignmentTable}",
172 "SELECT COUNT(*) FROM {$this->_authManager->rightsTable}",
177 foreach( $schema as $sql )
179 $command = $this->db->createCommand($sql);
180 $command->queryScalar();
185 catch( CDbException $e )
190 return $this->_installed = $installed;