make use of \PropelObjectCollection

This commit is contained in:
Toni Uebernickel 2012-02-04 15:18:44 +01:00
parent e73bc1098b
commit 04e7970312
12 changed files with 43 additions and 50 deletions

View file

@ -27,7 +27,7 @@ class EntryQuery extends BaseEntryQuery
* @param array $securityIdentities A list of SecurityIdentity to filter by.
* @param \PropelPDO $con
*
* @return \PropelCollection
* @return \PropelObjectCollection
*/
public function findByAclIdentity(ObjectIdentityInterface $objectIdentity, array $securityIdentities = array(), \PropelPDO $con = null)
{

View file

@ -41,15 +41,13 @@ class ObjectIdentity extends BaseObjectIdentity
public function preDelete(\PropelPDO $con = null)
{
$objIds = array($this->getId());
// Only retrieve direct children, it's faster and grand children will be retrieved recursively.
$children = ObjectIdentityQuery::create()->findChildren($this, $con);
foreach ($children as $eachChild) {
$objIds[] = $eachChild->getId();
$eachChild->delete($con);
}
$objIds = $children->getPrimaryKeys(false);
$objIds[] = $this->getId();
$children->delete($con);
// Manually delete those for DBAdapter not capable of cascading the DELETE.
ObjectIdentityAncestorQuery::create()

View file

@ -162,7 +162,7 @@ class AclProvider implements AclProviderInterface
/**
* Create an ACL.
*
* @param \PropelCollection $collection
* @param \PropelObjectCollection $collection
* @param \Symfony\Component\Security\Acl\Model\ObjectIdentityInterface $objectIdentity
* @param array $loadedSecurityIdentities
* @param \Symfony\Component\Security\Acl\Model\AclInterface $parentAcl
@ -170,7 +170,7 @@ class AclProvider implements AclProviderInterface
*
* @return \Propel\PropelBundle\Security\Acl\Domain\Acl
*/
protected function getAcl(\PropelCollection $collection, ObjectIdentityInterface $objectIdentity, array $loadedSecurityIdentities = array(), AclInterface $parentAcl = null, $inherited = true)
protected function getAcl(\PropelObjectCollection $collection, ObjectIdentityInterface $objectIdentity, array $loadedSecurityIdentities = array(), AclInterface $parentAcl = null, $inherited = true)
{
return new Acl($collection, $objectIdentity, $this->permissionGrantingStrategy, $loadedSecurityIdentities, $parentAcl, $inherited);
}

View file

@ -23,7 +23,7 @@ class AuditableAclProvider extends MutableAclProvider
/**
* Get an ACL for this provider.
*
* @param \PropelCollection $collection
* @param \PropelObjectCollection $collection
* @param \Symfony\Component\Security\Acl\Model\ObjectIdentityInterface $objectIdentity
* @param array $loadedSecurityIdentities
* @param \Symfony\Component\Security\Acl\Model\AclInterface $parentAcl
@ -31,7 +31,7 @@ class AuditableAclProvider extends MutableAclProvider
*
* @return \Propel\PropelBundle\Security\Acl\Domain\AuditableAcl
*/
protected function getAcl(\PropelCollection $collection, ObjectIdentityInterface $objectIdentity, array $loadedSecurityIdentities = array(), AclInterface $parentAcl = null, $inherited = true)
protected function getAcl(\PropelObjectCollection $collection, ObjectIdentityInterface $objectIdentity, array $loadedSecurityIdentities = array(), AclInterface $parentAcl = null, $inherited = true)
{
return new AuditableAcl($collection, $objectIdentity, $this->permissionGrantingStrategy, $loadedSecurityIdentities, $parentAcl, $inherited, $this->connection);
}

View file

@ -21,7 +21,7 @@ use Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface;
use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface;
/**
* An ACL implementation that is immutable based on data from a PropelCollection of Propel\PropelBundle\Model\Acl\Entry.
* An ACL implementation that is immutable based on data from a PropelObjectCollection of Propel\PropelBundle\Model\Acl\Entry.
*
* @author Toni Uebernickel <tuebernickel@gmail.com>
*/
@ -51,14 +51,14 @@ class Acl implements AclInterface
/**
* Constructor.
*
* @param \PropelCollection $entries
* @param \PropelObjectCollection $entries
* @param \Symfony\Component\Security\Acl\Model\ObjectIdentityInterface $objectIdentity
* @param \Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface $permissionGrantingStrategy
* @param array $loadedSecurityIdentities
* @param \Symfony\Component\Security\Acl\Model\AclInterface $parentAcl
* @param bool $inherited
*/
public function __construct(\PropelCollection $entries, ObjectIdentityInterface $objectIdentity, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $loadedSecurityIdentities = array(), AclInterface $parentAcl = null, $inherited = true)
public function __construct(\PropelObjectCollection $entries, ObjectIdentityInterface $objectIdentity, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $loadedSecurityIdentities = array(), AclInterface $parentAcl = null, $inherited = true)
{
if ($entries->getModel() !== $this->model) {
throw new AclException(sprintf('The given collection does not contain models of class "%s" but of class "%s".', $this->model, $entries->getModel()));
@ -222,6 +222,7 @@ class Acl implements AclInterface
}
$found = 0;
$loadedSecurityIds = array_keys($this->loadedSecurityIdentities);
foreach ($securityIdentities as $eachSecurityIdentity) {
if (!$eachSecurityIdentity instanceof SecurityIdentityInterface) {
@ -229,12 +230,8 @@ class Acl implements AclInterface
}
$modelIdentity = SecurityIdentity::fromAclIdentity($eachSecurityIdentity);
foreach ($this->loadedSecurityIdentities as $id => $eachLoadedIdentity) {
if ($id === $modelIdentity->getId()) {
$found++;
break;
}
if (in_array($modelIdentity->getId(), $loadedSecurityIds)) {
$found++;
}
}

View file

@ -43,7 +43,7 @@ class MutableAcl extends Acl implements MutableAclInterface
*
* Contains instances of \Propel\PropelBundle\Model\Acl\Entry.
*
* @var \PropelCollection
* @var \PropelObjectCollection
*/
protected $entries;
@ -64,7 +64,7 @@ class MutableAcl extends Acl implements MutableAclInterface
/**
* Constructor.
*
* @param \PropelCollection $entries
* @param \PropelObjectCollection $entries
* @param \Symfony\Component\Security\Acl\Model\ObjectIdentityInterface $objectIdentity
* @param \Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface $permissionGrantingStrategy
* @param array $loadedSecurityIdentities
@ -72,7 +72,7 @@ class MutableAcl extends Acl implements MutableAclInterface
* @param bool $inherited
* @param \PropelPDO $con
*/
public function __construct(\PropelCollection $entries, ObjectIdentityInterface $objectIdentity, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $loadedSecurityIdentities = array(), AclInterface $parentAcl = null, $inherited = true, \PropelPDO $con = null)
public function __construct(\PropelObjectCollection $entries, ObjectIdentityInterface $objectIdentity, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $loadedSecurityIdentities = array(), AclInterface $parentAcl = null, $inherited = true, \PropelPDO $con = null)
{
parent::__construct($entries, $objectIdentity, $permissionGrantingStrategy, $loadedSecurityIdentities, $parentAcl, $inherited);

View file

@ -121,9 +121,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
// In case this is the last of its kind, delete the class and class-field ACEs.
$count = ObjectIdentityQuery::create()->filterByClassId($objIdentity->getClassId())->count($this->connection);
if (1 === $count) {
foreach ($aces as $eachAce) {
$eachAce->delete($this->connection);
}
$aces->delete($this->connection);
}
}
@ -305,7 +303,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
/**
* Get an ACL for this provider.
*
* @param \PropelCollection $collection
* @param \PropelObjectCollection $collection
* @param \Symfony\Component\Security\Acl\Model\ObjectIdentityInterface $objectIdentity
* @param array $loadedSecurityIdentities
* @param \Symfony\Component\Security\Acl\Model\AclInterface $parentAcl
@ -313,7 +311,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
*
* @return \Propel\PropelBundle\Security\Acl\Domain\MutableAcl
*/
protected function getAcl(\PropelCollection $collection, ObjectIdentityInterface $objectIdentity, array $loadedSecurityIdentities = array(), AclInterface $parentAcl = null, $inherited = true)
protected function getAcl(\PropelObjectCollection $collection, ObjectIdentityInterface $objectIdentity, array $loadedSecurityIdentities = array(), AclInterface $parentAcl = null, $inherited = true)
{
return new MutableAcl($collection, $objectIdentity, $this->permissionGrantingStrategy, $loadedSecurityIdentities, $parentAcl, $inherited, $this->connection);
}

View file

@ -26,7 +26,7 @@ class AclTest extends AclTestCase
{
public function testConstructorInvalidCollection()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\AclClass');
$this->setExpectedException('Symfony\Component\Security\Acl\Exception\Exception');
@ -35,7 +35,7 @@ class AclTest extends AclTestCase
public function testConstructorEmptyCollection()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$aclObj = $this->getAclObjectIdentity();
@ -54,7 +54,7 @@ class AclTest extends AclTestCase
*/
public function testConstructorWithAces()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$obj = $this->createModelObjectIdentity(1);
@ -123,7 +123,7 @@ class AclTest extends AclTestCase
public function testIsSidLoadedNoneLoaded()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$acl = new Acl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());
@ -132,7 +132,7 @@ class AclTest extends AclTestCase
public function testIsSidLoadedInvalid()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$aclObj = $this->getAclObjectIdentity();
@ -144,7 +144,7 @@ class AclTest extends AclTestCase
public function testIsGrantedNoAces()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$acl = new Acl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());
@ -155,7 +155,7 @@ class AclTest extends AclTestCase
public function testIsGrantedNoMatchingSecurityIdentity()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$entry = $this->createEntry();
@ -173,7 +173,7 @@ class AclTest extends AclTestCase
public function testIsFieldGrantedNoAces()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$acl = new Acl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());
@ -184,7 +184,7 @@ class AclTest extends AclTestCase
public function testSerializeUnserialize()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$entry = $this->createEntry();

View file

@ -26,7 +26,7 @@ class AuditableAclTest extends AclTestCase
{
public function testUpdateAuditingInvalidIndex()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$acl = new AuditableAcl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());
@ -37,7 +37,7 @@ class AuditableAclTest extends AclTestCase
public function testUpdateAuditingInvalidField()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$obj = $this->createModelObjectIdentity(1);
@ -57,7 +57,7 @@ class AuditableAclTest extends AclTestCase
public function testUpdateAuditingInvalidFlag()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$obj = $this->createModelObjectIdentity(1);
@ -76,7 +76,7 @@ class AuditableAclTest extends AclTestCase
public function testUpdateObjectAuditing()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$obj = $this->createModelObjectIdentity(1);
@ -118,7 +118,7 @@ class AuditableAclTest extends AclTestCase
*/
public function testUpdateObjectFieldAuditing()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$obj = $this->createModelObjectIdentity(1);
@ -152,7 +152,7 @@ class AuditableAclTest extends AclTestCase
*/
public function testUpdateClassAuditing()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$entry = $this->createEntry();
@ -183,7 +183,7 @@ class AuditableAclTest extends AclTestCase
*/
public function testUpdateClassFieldAuditing()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$entry = $this->createEntry();

View file

@ -27,7 +27,7 @@ class EntryTest extends AclTestCase
{
public function testConstruct()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$acl = new Acl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());

View file

@ -27,7 +27,7 @@ class FieldEntryTest extends AclTestCase
{
public function testConstruct()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$acl = new Acl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());

View file

@ -27,7 +27,7 @@ class MutableAclTest extends AclTestCase
{
public function testConstructorInvalidCollection()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\AclClass');
$this->setExpectedException('Symfony\Component\Security\Acl\Exception\Exception');
@ -225,7 +225,7 @@ class MutableAclTest extends AclTestCase
*/
public function testUpdatePersistedAceKeepsId()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$entry = $this->createEntry();
@ -246,7 +246,7 @@ class MutableAclTest extends AclTestCase
public function testSerializeUnserialize()
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
$entry = $this->createEntry();
@ -268,7 +268,7 @@ class MutableAclTest extends AclTestCase
protected function createEmptyAcl($identifier = 1, array $securityIdentities = array(), AclInterface $parentAcl = null, $inherited = null)
{
$collection = new \PropelCollection();
$collection = new \PropelObjectCollection();
$collection->setModel('Propel\PropelBundle\Model\Acl\Entry');
return new MutableAcl($collection, $this->getAclObjectIdentity($identifier), new PermissionGrantingStrategy(), $securityIdentities, $parentAcl, $inherited, $this->con);