|
|
@ -160,7 +160,8 @@ class DbManager extends Manager |
|
|
|
throw new InvalidCallException("Cannot add '$childName' as a child of '$itemName'. A loop has been detected."); |
|
|
|
throw new InvalidCallException("Cannot add '$childName' as a child of '$itemName'. A loop has been detected."); |
|
|
|
} |
|
|
|
} |
|
|
|
$this->db->createCommand() |
|
|
|
$this->db->createCommand() |
|
|
|
->insert($this->itemChildTable, array('parent' => $itemName, 'child' => $childName)); |
|
|
|
->insert($this->itemChildTable, array('parent' => $itemName, 'child' => $childName)) |
|
|
|
|
|
|
|
->execute(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
throw new Exception("Either '$itemName' or '$childName' does not exist."); |
|
|
|
throw new Exception("Either '$itemName' or '$childName' does not exist."); |
|
|
@ -177,7 +178,8 @@ class DbManager extends Manager |
|
|
|
public function removeItemChild($itemName, $childName) |
|
|
|
public function removeItemChild($itemName, $childName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->db->createCommand() |
|
|
|
return $this->db->createCommand() |
|
|
|
->delete($this->itemChildTable, array('parent' => $itemName, 'child' => $childName)) > 0; |
|
|
|
->delete($this->itemChildTable, array('parent' => $itemName, 'child' => $childName)) |
|
|
|
|
|
|
|
->execute() > 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -248,7 +250,8 @@ class DbManager extends Manager |
|
|
|
'item_name' => $itemName, |
|
|
|
'item_name' => $itemName, |
|
|
|
'biz_rule' => $bizRule, |
|
|
|
'biz_rule' => $bizRule, |
|
|
|
'data' => serialize($data), |
|
|
|
'data' => serialize($data), |
|
|
|
)); |
|
|
|
)) |
|
|
|
|
|
|
|
->execute(); |
|
|
|
return new Assignment(array( |
|
|
|
return new Assignment(array( |
|
|
|
'manager' => $this, |
|
|
|
'manager' => $this, |
|
|
|
'userId' => $userId, |
|
|
|
'userId' => $userId, |
|
|
@ -267,7 +270,8 @@ class DbManager extends Manager |
|
|
|
public function revoke($userId, $itemName) |
|
|
|
public function revoke($userId, $itemName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return $this->db->createCommand() |
|
|
|
return $this->db->createCommand() |
|
|
|
->delete($this->assignmentTable, array('user_id' => $userId, 'item_name' => $itemName)) > 0; |
|
|
|
->delete($this->assignmentTable, array('user_id' => $userId, 'item_name' => $itemName)) |
|
|
|
|
|
|
|
->execute() > 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -358,7 +362,8 @@ class DbManager extends Manager |
|
|
|
), array( |
|
|
|
), array( |
|
|
|
'user_id' => $assignment->userId, |
|
|
|
'user_id' => $assignment->userId, |
|
|
|
'item_name' => $assignment->itemName, |
|
|
|
'item_name' => $assignment->itemName, |
|
|
|
)); |
|
|
|
)) |
|
|
|
|
|
|
|
->execute(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -424,6 +429,7 @@ class DbManager extends Manager |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function createItem($name, $type, $description = '', $bizRule = null, $data = null) |
|
|
|
public function createItem($name, $type, $description = '', $bizRule = null, $data = null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
echo $name; |
|
|
|
$this->db->createCommand() |
|
|
|
$this->db->createCommand() |
|
|
|
->insert($this->itemTable, array( |
|
|
|
->insert($this->itemTable, array( |
|
|
|
'name' => $name, |
|
|
|
'name' => $name, |
|
|
@ -431,7 +437,8 @@ class DbManager extends Manager |
|
|
|
'description' => $description, |
|
|
|
'description' => $description, |
|
|
|
'biz_rule' => $bizRule, |
|
|
|
'biz_rule' => $bizRule, |
|
|
|
'data' => serialize($data), |
|
|
|
'data' => serialize($data), |
|
|
|
)); |
|
|
|
)) |
|
|
|
|
|
|
|
->execute(); |
|
|
|
return new Item(array( |
|
|
|
return new Item(array( |
|
|
|
'manager' => $this, |
|
|
|
'manager' => $this, |
|
|
|
'name' => $name, |
|
|
|
'name' => $name, |
|
|
@ -451,12 +458,15 @@ class DbManager extends Manager |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($this->usingSqlite()) { |
|
|
|
if ($this->usingSqlite()) { |
|
|
|
$this->db->createCommand() |
|
|
|
$this->db->createCommand() |
|
|
|
->delete($this->itemChildTable, array('or', 'parent=:name', 'child=:name'), array(':name' => $name)); |
|
|
|
->delete($this->itemChildTable, array('or', 'parent=:name', 'child=:name'), array(':name' => $name)) |
|
|
|
|
|
|
|
->execute(); |
|
|
|
$this->db->createCommand() |
|
|
|
$this->db->createCommand() |
|
|
|
->delete($this->assignmentTable, array('item_name' => $name)); |
|
|
|
->delete($this->assignmentTable, array('item_name' => $name)) |
|
|
|
|
|
|
|
->execute(); |
|
|
|
} |
|
|
|
} |
|
|
|
return $this->db->createCommand() |
|
|
|
return $this->db->createCommand() |
|
|
|
->delete($this->itemTable, array('name' => $name)) > 0; |
|
|
|
->delete($this->itemTable, array('name' => $name)) |
|
|
|
|
|
|
|
->execute() > 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -497,11 +507,14 @@ class DbManager extends Manager |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($this->usingSqlite() && $oldName !== null && $item->getName() !== $oldName) { |
|
|
|
if ($this->usingSqlite() && $oldName !== null && $item->getName() !== $oldName) { |
|
|
|
$this->db->createCommand() |
|
|
|
$this->db->createCommand() |
|
|
|
->update($this->itemChildTable, array('parent' => $item->getName()), array('parent' => $oldName)); |
|
|
|
->update($this->itemChildTable, array('parent' => $item->getName()), array('parent' => $oldName)) |
|
|
|
|
|
|
|
->execute(); |
|
|
|
$this->db->createCommand() |
|
|
|
$this->db->createCommand() |
|
|
|
->update($this->itemChildTable, array('child' => $item->getName()), array('child' => $oldName)); |
|
|
|
->update($this->itemChildTable, array('child' => $item->getName()), array('child' => $oldName)) |
|
|
|
|
|
|
|
->execute(); |
|
|
|
$this->db->createCommand() |
|
|
|
$this->db->createCommand() |
|
|
|
->update($this->assignmentTable, array('item_name' => $item->getName()), array('item_name' => $oldName)); |
|
|
|
->update($this->assignmentTable, array('item_name' => $item->getName()), array('item_name' => $oldName)) |
|
|
|
|
|
|
|
->execute(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$this->db->createCommand() |
|
|
|
$this->db->createCommand() |
|
|
@ -513,7 +526,8 @@ class DbManager extends Manager |
|
|
|
'data' => serialize($item->data), |
|
|
|
'data' => serialize($item->data), |
|
|
|
), array( |
|
|
|
), array( |
|
|
|
'name' => $oldName === null ? $item->getName() : $oldName, |
|
|
|
'name' => $oldName === null ? $item->getName() : $oldName, |
|
|
|
)); |
|
|
|
)) |
|
|
|
|
|
|
|
->execute(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -529,8 +543,8 @@ class DbManager extends Manager |
|
|
|
public function clearAll() |
|
|
|
public function clearAll() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->clearAssignments(); |
|
|
|
$this->clearAssignments(); |
|
|
|
$this->db->createCommand()->delete($this->itemChildTable); |
|
|
|
$this->db->createCommand()->delete($this->itemChildTable)->execute(); |
|
|
|
$this->db->createCommand()->delete($this->itemTable); |
|
|
|
$this->db->createCommand()->delete($this->itemTable)->execute(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -538,7 +552,7 @@ class DbManager extends Manager |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function clearAssignments() |
|
|
|
public function clearAssignments() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->db->createCommand()->delete($this->assignmentTable); |
|
|
|
$this->db->createCommand()->delete($this->assignmentTable)->execute(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|