Browse Source

DbManager code style fix + right Exception type fix

tags/2.0.0-beta
Alexander Kochetov 12 years ago
parent
commit
b9ea7e6fd8
  1. 16
      yii/rbac/DbManager.php

16
yii/rbac/DbManager.php

@ -10,9 +10,11 @@ namespace yii\rbac;
use Yii; use Yii;
use yii\db\Connection; use yii\db\Connection;
use yii\db\Query; use yii\db\Query;
use yii\db\Expression;
use yii\base\Exception; use yii\base\Exception;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\base\InvalidCallException; use yii\base\InvalidCallException;
use yii\base\InvalidParamException;
/** /**
* DbManager represents an authorization manager that stores authorization information in database. * DbManager represents an authorization manager that stores authorization information in database.
@ -222,8 +224,7 @@ class DbManager extends Manager
$this->itemTable, $this->itemTable,
$this->itemChildTable $this->itemChildTable
)) ))
->where(array('parent'=>$names)) ->where(array('parent' => $names, 'name' => new Expression('child')))
->andWhere('name=child')
->createCommand($this->db) ->createCommand($this->db)
->queryAll(); ->queryAll();
$children = array(); $children = array();
@ -244,12 +245,12 @@ class DbManager extends Manager
* for this particular authorization item. * for this particular authorization item.
* @param mixed $data additional data associated with this assignment * @param mixed $data additional data associated with this assignment
* @return Assignment the authorization assignment information. * @return Assignment the authorization assignment information.
* @throws Exception if the item does not exist or if the item has already been assigned to the user * @throws InvalidParamException if the item does not exist or if the item has already been assigned to the user
*/ */
public function assign($userId, $itemName, $bizRule = null, $data = null) public function assign($userId, $itemName, $bizRule = null, $data = null)
{ {
if ($this->usingSqlite() && $this->getItem($itemName) === null) { if ($this->usingSqlite() && $this->getItem($itemName) === null) {
throw new Exception("The item '$itemName' does not exist."); throw new InvalidParamException("The item '$itemName' does not exist.");
} }
$this->db->createCommand() $this->db->createCommand()
->insert($this->assignmentTable, array( ->insert($this->assignmentTable, array(
@ -385,8 +386,7 @@ class DbManager extends Manager
$this->itemTable . ' t1', $this->itemTable . ' t1',
$this->assignmentTable . ' t2' $this->assignmentTable . ' t2'
)) ))
->where(array('userid' => $userId)) ->where(array('userid' => $userId, 'name' => new Expression('itemname')))
->andWhere('name=itemname')
->createCommand($this->db); ->createCommand($this->db);
} else { } else {
$command = $query->select('name', 'type', 'description', 't1.bizrule', 't1.data') $command = $query->select('name', 'type', 'description', 't1.bizrule', 't1.data')
@ -396,9 +396,9 @@ class DbManager extends Manager
)) ))
->where(array( ->where(array(
'userid' => $userId, 'userid' => $userId,
'type' => $type 'type' => $type,
'name' => new Expression('itemname'),
)) ))
->andWhere('name=itemname')
->createCommand($this->db); ->createCommand($this->db);
} }
$items = array(); $items = array();

Loading…
Cancel
Save