Commit 220b60f3 by Alexander Makarov

Fixes #4275: Added `removeChildren()` to `yii\rbac\ManagerInterface` and implementations

parent 45e472cc
......@@ -4,7 +4,7 @@ Yii Framework 2 Change Log
2.0.0 under development
-----------------------
- no changes in this release.
- Enh #4275: Added `removeChildren()` to `yii\rbac\ManagerInterface` and implementations (samdark)
2.0.0-rc September 27, 2014
......
......@@ -542,6 +542,16 @@ class DbManager extends BaseManager
/**
* @inheritdoc
*/
public function removeChildren($parent)
{
return $this->db->createCommand()
->delete($this->itemChildTable, ['parent' => $parent->name])
->execute() > 0;
}
/**
* @inheritdoc
*/
public function hasChild($parent, $child)
{
return (new Query)
......
......@@ -146,6 +146,14 @@ interface ManagerInterface
public function removeChild($parent, $child);
/**
* Removed all children form their parent.
* Note, the children items are not deleted. Only the parent-child relationships are removed.
* @param Item $parent
* @return boolean whether the removal is successful
*/
public function removeChildren($parent);
/**
* Returns a value indicating whether the child already exists for the parent.
* @param Item $parent
* @param Item $child
......
......@@ -218,6 +218,20 @@ class PhpManager extends BaseManager
/**
* @inheritdoc
*/
public function removeChildren($parent)
{
if (isset($this->children[$parent->name])) {
unset($this->children[$parent->name]);
$this->saveItems();
return true;
} else {
return false;
}
}
/**
* @inheritdoc
*/
public function hasChild($parent, $child)
{
return isset($this->children[$parent->name][$child->name]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment