57 $authManager = Yii::app()->getAuthManager();
59 throw new CException(
Rights::t(
'install',
'Application authorization manager must extend the RDbAuthManager class.'));
64 $user = Yii::app()->getUser();
65 if (($user instanceof
RWebUser) ===
false) {
66 throw new CException(
Rights::t(
'install',
'Application web user must extend the RWebUser class.'));
69 $this->_authManager = $authManager;
70 $this->db = $this->_authManager->db;
83 $itemTable = $this->_authManager->itemTable;
84 $itemChildTable = $this->_authManager->itemChildTable;
85 $assignmentTable = $this->_authManager->assignmentTable;
86 $rightsTable = $this->_authManager->rightsTable;
89 $schema = file_get_contents(dirname(__FILE__).
'/../data/schema.sql');
92 $schema = strtr($schema, array(
93 'AuthItem' => $itemTable,
94 'AuthItemChild' => $itemChildTable,
95 'AuthAssignment' => $assignmentTable,
96 'Rights' => $rightsTable,
100 $schema = preg_split(
"/;\s*/", trim($schema,
';'));
103 $txn = $this->db->beginTransaction();
107 foreach ($schema as $sql) {
108 $command = $this->db->createCommand($sql);
114 foreach ($roles as $roleName) {
115 $sql =
"INSERT INTO {$itemTable} (name, type, data)
116 VALUES (:name, :type, :data)";
117 $command = $this->db->createCommand($sql);
118 $command->bindValue(
':name', $roleName);
119 $command->bindValue(
':type', CAuthItem::TYPE_ROLE);
120 $command->bindValue(
':data',
'N;');
125 $sql =
"INSERT INTO {$assignmentTable} (itemname, userid, data)
126 VALUES (:itemname, :userid, :data)";
127 $command = $this->db->createCommand($sql);
128 $command->bindValue(
':itemname', $this->superuserName);
129 $command->bindValue(
':userid', Yii::app()->getUser()->
id);
130 $command->bindValue(
':data',
'N;');
137 }
catch (CDbException $e) {
152 $roles = CMap::mergeArray($this->defaultRoles, array(
153 $this->superuserName,
158 return array_unique($roles);
166 if ($this->_installed !== null) {
170 "SELECT COUNT(*) FROM {$this->_authManager->itemTable}",
171 "SELECT COUNT(*) FROM {$this->_authManager->itemChildTable}",
172 "SELECT COUNT(*) FROM {$this->_authManager->assignmentTable}",
173 "SELECT COUNT(*) FROM {$this->_authManager->rightsTable}",
177 foreach ($schema as $sql) {
178 $command = $this->db->createCommand($sql);
179 $command->queryScalar();
183 }
catch (CDbException $e) {
187 return $this->_installed = $installed;