Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
+34 -56
View File
@@ -12,8 +12,7 @@
namespace Symfony\Component\Security\Acl\Dbal;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Statement;
use Symfony\Component\Security\Acl\Model\AclInterface;
use Doctrine\DBAL\Result;
use Symfony\Component\Security\Acl\Domain\Acl;
use Symfony\Component\Security\Acl\Domain\Entry;
use Symfony\Component\Security\Acl\Domain\FieldEntry;
@@ -23,6 +22,7 @@ use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Exception\AclNotFoundException;
use Symfony\Component\Security\Acl\Exception\NotAllAclsFoundException;
use Symfony\Component\Security\Acl\Model\AclCacheInterface;
use Symfony\Component\Security\Acl\Model\AclInterface;
use Symfony\Component\Security\Acl\Model\AclProviderInterface;
use Symfony\Component\Security\Acl\Model\ObjectIdentityInterface;
use Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface;
@@ -47,8 +47,8 @@ class AclProvider implements AclProviderInterface
* @var Connection
*/
protected $connection;
protected $loadedAces = array();
protected $loadedAcls = array();
protected $loadedAces = [];
protected $loadedAcls = [];
protected $options;
/**
@@ -59,10 +59,7 @@ class AclProvider implements AclProviderInterface
/**
* Constructor.
*
* @param Connection $connection
* @param PermissionGrantingStrategyInterface $permissionGrantingStrategy
* @param array $options
* @param AclCacheInterface $cache
* @param AclCacheInterface $cache
*/
public function __construct(Connection $connection, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $options, AclCacheInterface $cache = null)
{
@@ -79,8 +76,8 @@ class AclProvider implements AclProviderInterface
{
$sql = $this->getFindChildrenSql($parentOid, $directChildrenOnly);
$children = array();
foreach ($this->connection->executeQuery($sql)->fetchAll() as $data) {
$children = [];
foreach ($this->connection->executeQuery($sql)->fetchAllAssociative() as $data) {
$children[] = new ObjectIdentity($data['object_identifier'], $data['class_type']);
}
@@ -90,21 +87,21 @@ class AclProvider implements AclProviderInterface
/**
* {@inheritdoc}
*/
public function findAcl(ObjectIdentityInterface $oid, array $sids = array())
public function findAcl(ObjectIdentityInterface $oid, array $sids = [])
{
return $this->findAcls(array($oid), $sids)->offsetGet($oid);
return $this->findAcls([$oid], $sids)->offsetGet($oid);
}
/**
* {@inheritdoc}
*/
public function findAcls(array $oids, array $sids = array())
public function findAcls(array $oids, array $sids = [])
{
$result = new \SplObjectStorage();
$currentBatch = array();
$oidLookup = array();
$currentBatch = [];
$oidLookup = [];
for ($i = 0, $c = count($oids); $i < $c; ++$i) {
for ($i = 0, $c = \count($oids); $i < $c; ++$i) {
$oid = $oids[$i];
$oidLookupKey = $oid->getIdentifier().$oid->getType();
$oidLookup[$oidLookupKey] = $oid;
@@ -173,7 +170,7 @@ class AclProvider implements AclProviderInterface
}
// Is it time to load the current batch?
$currentBatchesCount = count($currentBatch);
$currentBatchesCount = \count($currentBatch);
if ($currentBatchesCount > 0 && (self::MAX_BATCH_SIZE === $currentBatchesCount || ($i + 1) === $c)) {
try {
$loadedBatch = $this->lookupObjectIdentities($currentBatch, $sids, $oidLookup);
@@ -198,15 +195,15 @@ class AclProvider implements AclProviderInterface
}
}
$currentBatch = array();
$currentBatch = [];
}
}
// check that we got ACLs for all the identities
foreach ($oids as $oid) {
if (!$result->contains($oid)) {
if (1 === count($oids)) {
$objectName = method_exists($oid, '__toString') ? $oid : get_class($oid);
if (1 === \count($oids)) {
$objectName = method_exists($oid, '__toString') ? $oid : \get_class($oid);
throw new AclNotFoundException(sprintf('No ACL found for %s.', $objectName));
}
@@ -224,8 +221,6 @@ class AclProvider implements AclProviderInterface
* Constructs the query used for looking up object identities and associated
* ACEs, and security identities.
*
* @param array $ancestorIds
*
* @return string
*/
protected function getLookupSql(array $ancestorIds)
@@ -279,8 +274,8 @@ SELECTCLAUSE;
WHERE (
SELECTCLAUSE;
$types = array();
$count = count($batch);
$types = [];
$count = \count($batch);
for ($i = 0; $i < $count; ++$i) {
if (!isset($types[$batch[$i]->getType()])) {
$types[$batch[$i]->getType()] = true;
@@ -288,14 +283,14 @@ SELECTCLAUSE;
// if there is more than one type we can safely break out of the
// loop, because it is the differentiator factor on whether to
// query for only one or more class types
if (count($types) > 1) {
if (\count($types) > 1) {
break;
}
}
}
if (1 === count($types)) {
$ids = array();
if (1 === \count($types)) {
$ids = [];
for ($i = 0; $i < $count; ++$i) {
$identifier = (string) $batch[$i]->getIdentifier();
$ids[] = $this->connection->quote($identifier);
@@ -330,8 +325,7 @@ SELECTCLAUSE;
* Constructs the SQL for retrieving child object identities for the given
* object identities.
*
* @param ObjectIdentityInterface $oid
* @param bool $directChildrenOnly
* @param bool $directChildrenOnly
*
* @return string
*/
@@ -363,8 +357,6 @@ FINDCHILDREN;
* Constructs the SQL for retrieving the primary key of the given object
* identity.
*
* @param ObjectIdentityInterface $oid
*
* @return string
*/
protected function getSelectObjectIdentityIdSql(ObjectIdentityInterface $oid)
@@ -388,23 +380,19 @@ QUERY;
/**
* Returns the primary key of the passed object identity.
*
* @param ObjectIdentityInterface $oid
*
* @return int
*/
final protected function retrieveObjectIdentityPrimaryKey(ObjectIdentityInterface $oid)
{
return $this->connection->executeQuery($this->getSelectObjectIdentityIdSql($oid))->fetchColumn();
return $this->connection->executeQuery($this->getSelectObjectIdentityIdSql($oid))->fetchOne();
}
/**
* This method is called when an ACL instance is retrieved from the cache.
*
* @param AclInterface $acl
*/
private function updateAceIdentityMap(AclInterface $acl)
{
foreach (array('classAces', 'classFieldAces', 'objectAces', 'objectFieldAces') as $property) {
foreach (['classAces', 'classFieldAces', 'objectAces', 'objectFieldAces'] as $property) {
$reflection = new \ReflectionProperty($acl, $property);
$reflection->setAccessible(true);
$value = $reflection->getValue($acl);
@@ -426,16 +414,14 @@ QUERY;
* Retrieves all the ids which need to be queried from the database
* including the ids of parent ACLs.
*
* @param array $batch
*
* @return array
*/
private function getAncestorIds(array $batch)
{
$sql = $this->getAncestorLookupSql($batch);
$ancestorIds = array();
foreach ($this->connection->executeQuery($sql)->fetchAll() as $data) {
$ancestorIds = [];
foreach ($this->connection->executeQuery($sql)->fetchAllAssociative() as $data) {
// FIXME: skip ancestors which are cached
// Fix: Oracle returns keys in uppercase
$ancestorIds[] = reset($data);
@@ -465,10 +451,6 @@ QUERY;
* This method is called for object identities which could not be retrieved
* from the cache, and for which thus a database query is required.
*
* @param array $batch
* @param array $sids
* @param array $oidLookup
*
* @return \SplObjectStorage mapping object identities to ACL instances
*
* @throws AclNotFoundException
@@ -495,18 +477,14 @@ QUERY;
* Keep in mind that changes to this method might severely reduce the
* performance of the entire ACL system.
*
* @param Statement $stmt
* @param array $oidLookup
* @param array $sids
*
* @return \SplObjectStorage
*
* @throws \RuntimeException
*/
private function hydrateObjectIdentities(Statement $stmt, array $oidLookup, array $sids)
private function hydrateObjectIdentities(Result $stmt, array $oidLookup, array $sids)
{
$parentIdToFill = new \SplObjectStorage();
$acls = $aces = $emptyArray = array();
$acls = $aces = $emptyArray = [];
$oidCache = $oidLookup;
$result = new \SplObjectStorage();
$loadedAces = &$this->loadedAces;
@@ -528,8 +506,8 @@ QUERY;
// fetchAll() consumes more memory than consecutive calls to fetch(),
// but it is faster
foreach ($stmt->fetchAll(\PDO::FETCH_NUM) as $data) {
list($aclId,
foreach ($stmt->fetchAllNumeric() as $data) {
[$aclId,
$objectIdentifier,
$parentObjectIdentityId,
$entriesInheriting,
@@ -544,7 +522,7 @@ QUERY;
$auditSuccess,
$auditFailure,
$username,
$securityIdentifier) = array_values($data);
$securityIdentifier] = array_values($data);
// has the ACL been hydrated during this hydration cycle?
if (isset($acls[$aclId])) {
@@ -595,7 +573,7 @@ QUERY;
if (null !== $aceId) {
// have we already hydrated ACEs for this ACL?
if (!isset($aces[$aclId])) {
$aces[$aclId] = array($emptyArray, $emptyArray, $emptyArray, $emptyArray);
$aces[$aclId] = [$emptyArray, $emptyArray, $emptyArray, $emptyArray];
}
// has this ACE already been hydrated during a previous cycle, or
@@ -686,7 +664,7 @@ QUERY;
$aclParentAclProperty->setAccessible(false);
// this should never be true if the database integrity hasn't been compromised
if ($processed < count($parentIdToFill)) {
if ($processed < \count($parentIdToFill)) {
throw new \RuntimeException('Not all parent ids were populated. This implies an integrity problem.');
}
+61 -85
View File
@@ -11,8 +11,8 @@
namespace Symfony\Component\Security\Acl\Dbal;
use Doctrine\Common\PropertyChangedListener;
use Doctrine\DBAL\Connection;
use Doctrine\Persistence\PropertyChangedListener;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Exception\AclAlreadyExistsException;
@@ -51,7 +51,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
public function createAcl(ObjectIdentityInterface $oid)
{
if (false !== $this->retrieveObjectIdentityPrimaryKey($oid)) {
$objectName = method_exists($oid, '__toString') ? $oid : get_class($oid);
$objectName = method_exists($oid, '__toString') ? $oid : \get_class($oid);
throw new AclAlreadyExistsException(sprintf('%s is already associated with an ACL.', $objectName));
}
@@ -60,7 +60,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
$this->createObjectIdentity($oid);
$pk = $this->retrieveObjectIdentityPrimaryKey($oid);
$this->connection->executeQuery($this->getInsertObjectIdentityRelationSql($pk, $pk));
$this->connection->executeStatement($this->getInsertObjectIdentityRelationSql($pk, $pk));
$this->connection->commit();
} catch (\Exception $e) {
@@ -113,19 +113,17 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
* Deletes the security identity from the database.
* ACL entries have the CASCADE option on their foreign key so they will also get deleted.
*
* @param SecurityIdentityInterface $sid
*
* @throws \InvalidArgumentException
*/
public function deleteSecurityIdentity(SecurityIdentityInterface $sid)
{
$this->connection->executeQuery($this->getDeleteSecurityIdentityIdSql($sid));
$this->connection->executeStatement($this->getDeleteSecurityIdentityIdSql($sid));
}
/**
* {@inheritdoc}
*/
public function findAcls(array $oids, array $sids = array())
public function findAcls(array $oids, array $sids = [])
{
$result = parent::findAcls($oids, $sids);
@@ -134,14 +132,14 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
if (false === $this->propertyChanges->contains($acl) && $acl instanceof MutableAclInterface) {
$acl->addPropertyChangedListener($this);
$this->propertyChanges->attach($acl, array());
$this->propertyChanges->attach($acl, []);
}
$parentAcl = $acl->getParentAcl();
while (null !== $parentAcl) {
if (false === $this->propertyChanges->contains($parentAcl) && $acl instanceof MutableAclInterface) {
$parentAcl->addPropertyChangedListener($this);
$this->propertyChanges->attach($parentAcl, array());
$this->propertyChanges->attach($parentAcl, []);
}
$parentAcl = $parentAcl->getParentAcl();
@@ -192,35 +190,35 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
if ($oldValue === $newValue) {
unset($propertyChanges[$propertyName]);
} else {
$propertyChanges[$propertyName] = array($oldValue, $newValue);
$propertyChanges[$propertyName] = [$oldValue, $newValue];
}
} else {
$propertyChanges[$propertyName] = array($oldValue, $newValue);
$propertyChanges[$propertyName] = [$oldValue, $newValue];
}
} else {
if (!isset($propertyChanges['aces'])) {
$propertyChanges['aces'] = new \SplObjectStorage();
}
$acePropertyChanges = $propertyChanges['aces']->contains($ace) ? $propertyChanges['aces']->offsetGet($ace) : array();
$acePropertyChanges = $propertyChanges['aces']->contains($ace) ? $propertyChanges['aces']->offsetGet($ace) : [];
if (isset($acePropertyChanges[$propertyName])) {
$oldValue = $acePropertyChanges[$propertyName][0];
if ($oldValue === $newValue) {
unset($acePropertyChanges[$propertyName]);
} else {
$acePropertyChanges[$propertyName] = array($oldValue, $newValue);
$acePropertyChanges[$propertyName] = [$oldValue, $newValue];
}
} else {
$acePropertyChanges[$propertyName] = array($oldValue, $newValue);
$acePropertyChanges[$propertyName] = [$oldValue, $newValue];
}
if (count($acePropertyChanges) > 0) {
if (\count($acePropertyChanges) > 0) {
$propertyChanges['aces']->offsetSet($ace, $acePropertyChanges);
} else {
$propertyChanges['aces']->offsetUnset($ace);
if (0 === count($propertyChanges['aces'])) {
if (0 === \count($propertyChanges['aces'])) {
unset($propertyChanges['aces']);
}
}
@@ -240,11 +238,11 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
$propertyChanges = $this->propertyChanges->offsetGet($acl);
// check if any changes were made to this ACL
if (0 === count($propertyChanges)) {
if (0 === \count($propertyChanges)) {
return;
}
$sets = $sharedPropertyChanges = array();
$sets = $sharedPropertyChanges = [];
$this->connection->beginTransaction();
try {
@@ -307,7 +305,7 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
// if there have been changes to shared properties, we need to synchronize other
// ACL instances for object identities of the same type that are already in-memory
if (count($sharedPropertyChanges) > 0) {
if (\count($sharedPropertyChanges) > 0) {
$classAcesProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Acl', 'classAces');
$classAcesProperty->setAccessible(true);
$classFieldAcesProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Acl', 'classFieldAces');
@@ -333,8 +331,8 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
}
// persist any changes to the acl_object_identities table
if (count($sets) > 0) {
$this->connection->executeQuery($this->getUpdateObjectIdentitySql($acl->getId(), $sets));
if (\count($sets) > 0) {
$this->connection->executeStatement($this->getUpdateObjectIdentitySql($acl->getId(), $sets));
}
$this->connection->commit();
@@ -344,10 +342,10 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
throw $e;
}
$this->propertyChanges->offsetSet($acl, array());
$this->propertyChanges->offsetSet($acl, []);
if (null !== $this->cache) {
if (count($sharedPropertyChanges) > 0) {
if (\count($sharedPropertyChanges) > 0) {
// FIXME: Currently, there is no easy way to clear the cache for ACLs
// of a certain type. The problem here is that we need to make
// sure to clear the cache of all child ACLs as well, and these
@@ -368,12 +366,11 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
/**
* Updates a user security identity when the user's username changes.
*
* @param UserSecurityIdentity $usid
* @param string $oldUsername
* @param string $oldUsername
*/
public function updateUserSecurityIdentity(UserSecurityIdentity $usid, $oldUsername)
{
$this->connection->executeQuery($this->getUpdateUserSecurityIdentitySql($usid, $oldUsername));
$this->connection->executeStatement($this->getUpdateUserSecurityIdentitySql($usid, $oldUsername));
}
/**
@@ -552,8 +549,6 @@ QUERY;
/**
* Constructs the SQL for inserting a security identity.
*
* @param SecurityIdentityInterface $sid
*
* @throws \InvalidArgumentException
*
* @return string
@@ -624,8 +619,6 @@ QUERY;
/**
* Constructs the SQL for selecting the primary key of a security identity.
*
* @param SecurityIdentityInterface $sid
*
* @throws \InvalidArgumentException
*
* @return string
@@ -653,8 +646,6 @@ QUERY;
/**
* Constructs the SQL to delete a security identity.
*
* @param SecurityIdentityInterface $sid
*
* @throws \InvalidArgumentException
*
* @return string
@@ -670,8 +661,7 @@ QUERY;
/**
* Constructs the SQL for updating an object identity.
*
* @param int $pk
* @param array $changes
* @param int $pk
*
* @throws \InvalidArgumentException
*
@@ -679,7 +669,7 @@ QUERY;
*/
protected function getUpdateObjectIdentitySql($pk, array $changes)
{
if (0 === count($changes)) {
if (0 === \count($changes)) {
throw new \InvalidArgumentException('There are no changes.');
}
@@ -694,8 +684,7 @@ QUERY;
/**
* Constructs the SQL for updating a user security identity.
*
* @param UserSecurityIdentity $usid
* @param string $oldUsername
* @param string $oldUsername
*
* @return string
*/
@@ -720,8 +709,7 @@ QUERY;
/**
* Constructs the SQL for updating an ACE.
*
* @param int $pk
* @param array $sets
* @param int $pk
*
* @throws \InvalidArgumentException
*
@@ -729,7 +717,7 @@ QUERY;
*/
protected function getUpdateAccessControlEntrySql($pk, array $sets)
{
if (0 === count($sets)) {
if (0 === \count($sets)) {
throw new \InvalidArgumentException('There are no changes.');
}
@@ -743,14 +731,12 @@ QUERY;
/**
* Creates the ACL for the passed object identity.
*
* @param ObjectIdentityInterface $oid
*/
private function createObjectIdentity(ObjectIdentityInterface $oid)
{
$classId = $this->createOrRetrieveClassId($oid->getType());
$this->connection->executeQuery($this->getInsertObjectIdentitySql($oid->getIdentifier(), $classId, true));
$this->connection->executeStatement($this->getInsertObjectIdentitySql($oid->getIdentifier(), $classId, true));
}
/**
@@ -764,13 +750,13 @@ QUERY;
*/
private function createOrRetrieveClassId($classType)
{
if (false !== $id = $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn()) {
if (false !== $id = $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchOne()) {
return $id;
}
$this->connection->executeQuery($this->getInsertClassSql($classType));
$this->connection->executeStatement($this->getInsertClassSql($classType));
return $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn();
return $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchOne();
}
/**
@@ -779,19 +765,17 @@ QUERY;
* If the security identity does not yet exist in the database, it will be
* created.
*
* @param SecurityIdentityInterface $sid
*
* @return int
*/
private function createOrRetrieveSecurityIdentityId(SecurityIdentityInterface $sid)
{
if (false !== $id = $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn()) {
if (false !== $id = $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchOne()) {
return $id;
}
$this->connection->executeQuery($this->getInsertSecurityIdentitySql($sid));
$this->connection->executeStatement($this->getInsertSecurityIdentitySql($sid));
return $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn();
return $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchOne();
}
/**
@@ -801,7 +785,7 @@ QUERY;
*/
private function deleteAccessControlEntries($oidPK)
{
$this->connection->executeQuery($this->getDeleteAccessControlEntriesSql($oidPK));
$this->connection->executeStatement($this->getDeleteAccessControlEntriesSql($oidPK));
}
/**
@@ -811,7 +795,7 @@ QUERY;
*/
private function deleteObjectIdentity($pk)
{
$this->connection->executeQuery($this->getDeleteObjectIdentitySql($pk));
$this->connection->executeStatement($this->getDeleteObjectIdentitySql($pk));
}
/**
@@ -821,23 +805,21 @@ QUERY;
*/
private function deleteObjectIdentityRelations($pk)
{
$this->connection->executeQuery($this->getDeleteObjectIdentityRelationsSql($pk));
$this->connection->executeStatement($this->getDeleteObjectIdentityRelationsSql($pk));
}
/**
* This regenerates the ancestor table which is used for fast read access.
*
* @param AclInterface $acl
*/
private function regenerateAncestorRelations(AclInterface $acl)
{
$pk = $acl->getId();
$this->connection->executeQuery($this->getDeleteObjectIdentityRelationsSql($pk));
$this->connection->executeQuery($this->getInsertObjectIdentityRelationSql($pk, $pk));
$this->connection->executeStatement($this->getDeleteObjectIdentityRelationsSql($pk));
$this->connection->executeStatement($this->getInsertObjectIdentityRelationSql($pk, $pk));
$parentAcl = $acl->getParentAcl();
while (null !== $parentAcl) {
$this->connection->executeQuery($this->getInsertObjectIdentityRelationSql($pk, $parentAcl->getId()));
$this->connection->executeStatement($this->getInsertObjectIdentityRelationSql($pk, $parentAcl->getId()));
$parentAcl = $parentAcl->getParentAcl();
}
@@ -847,14 +829,13 @@ QUERY;
* This processes new entries changes on an ACE related property (classFieldAces, or objectFieldAces).
*
* @param string $name
* @param array $changes
*/
private function updateNewFieldAceProperty($name, array $changes)
{
$sids = new \SplObjectStorage();
$classIds = new \SplObjectStorage();
foreach ($changes[1] as $field => $new) {
for ($i = 0, $c = count($new); $i < $c; ++$i) {
for ($i = 0, $c = \count($new); $i < $c; ++$i) {
$ace = $new[$i];
if (null === $ace->getId()) {
@@ -871,10 +852,10 @@ QUERY;
$classId = $this->createOrRetrieveClassId($oid->getType());
}
$objectIdentityId = $name === 'classFieldAces' ? null : $ace->getAcl()->getId();
$objectIdentityId = 'classFieldAces' === $name ? null : $ace->getAcl()->getId();
$this->connection->executeQuery($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, $field, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, $field, $i))->fetchColumn();
$this->connection->executeStatement($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, $field, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, $field, $i))->fetchOne();
$this->loadedAces[$aceId] = $ace;
$aceIdProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Entry', 'id');
@@ -889,13 +870,12 @@ QUERY;
* This processes old entries changes on an ACE related property (classFieldAces, or objectFieldAces).
*
* @param string $name
* @param array $changes
*/
private function updateOldFieldAceProperty($name, array $changes)
{
$currentIds = array();
$currentIds = [];
foreach ($changes[1] as $field => $new) {
for ($i = 0, $c = count($new); $i < $c; ++$i) {
for ($i = 0, $c = \count($new); $i < $c; ++$i) {
$ace = $new[$i];
if (null !== $ace->getId()) {
@@ -905,11 +885,11 @@ QUERY;
}
foreach ($changes[0] as $old) {
for ($i = 0, $c = count($old); $i < $c; ++$i) {
for ($i = 0, $c = \count($old); $i < $c; ++$i) {
$ace = $old[$i];
if (!isset($currentIds[$ace->getId()])) {
$this->connection->executeQuery($this->getDeleteAccessControlEntrySql($ace->getId()));
$this->connection->executeStatement($this->getDeleteAccessControlEntrySql($ace->getId()));
unset($this->loadedAces[$ace->getId()]);
}
}
@@ -920,15 +900,14 @@ QUERY;
* This processes new entries changes on an ACE related property (classAces, or objectAces).
*
* @param string $name
* @param array $changes
*/
private function updateNewAceProperty($name, array $changes)
{
list($old, $new) = $changes;
[$old, $new] = $changes;
$sids = new \SplObjectStorage();
$classIds = new \SplObjectStorage();
for ($i = 0, $c = count($new); $i < $c; ++$i) {
for ($i = 0, $c = \count($new); $i < $c; ++$i) {
$ace = $new[$i];
if (null === $ace->getId()) {
@@ -945,10 +924,10 @@ QUERY;
$classId = $this->createOrRetrieveClassId($oid->getType());
}
$objectIdentityId = $name === 'classAces' ? null : $ace->getAcl()->getId();
$objectIdentityId = 'classAces' === $name ? null : $ace->getAcl()->getId();
$this->connection->executeQuery($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, null, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, null, $i))->fetchColumn();
$this->connection->executeStatement($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, null, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, null, $i))->fetchOne();
$this->loadedAces[$aceId] = $ace;
$aceIdProperty = new \ReflectionProperty($ace, 'id');
@@ -962,14 +941,13 @@ QUERY;
* This processes old entries changes on an ACE related property (classAces, or objectAces).
*
* @param string $name
* @param array $changes
*/
private function updateOldAceProperty($name, array $changes)
{
list($old, $new) = $changes;
$currentIds = array();
[$old, $new] = $changes;
$currentIds = [];
for ($i = 0, $c = count($new); $i < $c; ++$i) {
for ($i = 0, $c = \count($new); $i < $c; ++$i) {
$ace = $new[$i];
if (null !== $ace->getId()) {
@@ -977,11 +955,11 @@ QUERY;
}
}
for ($i = 0, $c = count($old); $i < $c; ++$i) {
for ($i = 0, $c = \count($old); $i < $c; ++$i) {
$ace = $old[$i];
if (!isset($currentIds[$ace->getId()])) {
$this->connection->executeQuery($this->getDeleteAccessControlEntrySql($ace->getId()));
$this->connection->executeStatement($this->getDeleteAccessControlEntrySql($ace->getId()));
unset($this->loadedAces[$ace->getId()]);
}
}
@@ -989,8 +967,6 @@ QUERY;
/**
* Persists the changes which were made to ACEs to the database.
*
* @param \SplObjectStorage $aces
*/
private function updateAces(\SplObjectStorage $aces)
{
@@ -1002,7 +978,7 @@ QUERY;
private function updateAce(\SplObjectStorage $aces, $ace)
{
$propertyChanges = $aces->offsetGet($ace);
$sets = array();
$sets = [];
if (isset($propertyChanges['aceOrder'])
&& $propertyChanges['aceOrder'][1] > $propertyChanges['aceOrder'][0]
@@ -1029,6 +1005,6 @@ QUERY;
$sets[] = sprintf('audit_failure = %s', $this->connection->getDatabasePlatform()->convertBooleans($propertyChanges['auditFailure'][1]));
}
$this->connection->executeQuery($this->getUpdateAccessControlEntrySql($ace->getId(), $sets));
$this->connection->executeStatement($this->getUpdateAccessControlEntrySql($ace->getId(), $sets));
}
}
+36 -38
View File
@@ -11,8 +11,8 @@
namespace Symfony\Component\Security\Acl\Dbal;
use Doctrine\DBAL\Schema\Schema as BaseSchema;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema as BaseSchema;
/**
* The schema used for the ACL system.
@@ -33,7 +33,7 @@ final class Schema extends BaseSchema
{
$schemaConfig = null === $connection ? null : $connection->getSchemaManager()->createSchemaConfig();
parent::__construct(array(), array(), $schemaConfig);
parent::__construct([], [], $schemaConfig);
$this->options = $options;
@@ -46,8 +46,6 @@ final class Schema extends BaseSchema
/**
* Merges ACL schema with the given schema.
*
* @param BaseSchema $schema
*/
public function addToSchema(BaseSchema $schema)
{
@@ -66,10 +64,10 @@ final class Schema extends BaseSchema
protected function addClassTable()
{
$table = $this->createTable($this->options['class_table_name']);
$table->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
$table->addColumn('class_type', 'string', array('length' => 200));
$table->setPrimaryKey(array('id'));
$table->addUniqueIndex(array('class_type'));
$table->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]);
$table->addColumn('class_type', 'string', ['length' => 200]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['class_type']);
}
/**
@@ -79,25 +77,25 @@ final class Schema extends BaseSchema
{
$table = $this->createTable($this->options['entry_table_name']);
$table->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
$table->addColumn('class_id', 'integer', array('unsigned' => true));
$table->addColumn('object_identity_id', 'integer', array('unsigned' => true, 'notnull' => false));
$table->addColumn('field_name', 'string', array('length' => 50, 'notnull' => false));
$table->addColumn('ace_order', 'smallint', array('unsigned' => true));
$table->addColumn('security_identity_id', 'integer', array('unsigned' => true));
$table->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]);
$table->addColumn('class_id', 'integer', ['unsigned' => true]);
$table->addColumn('object_identity_id', 'integer', ['unsigned' => true, 'notnull' => false]);
$table->addColumn('field_name', 'string', ['length' => 50, 'notnull' => false]);
$table->addColumn('ace_order', 'smallint', ['unsigned' => true]);
$table->addColumn('security_identity_id', 'integer', ['unsigned' => true]);
$table->addColumn('mask', 'integer');
$table->addColumn('granting', 'boolean');
$table->addColumn('granting_strategy', 'string', array('length' => 30));
$table->addColumn('granting_strategy', 'string', ['length' => 30]);
$table->addColumn('audit_success', 'boolean');
$table->addColumn('audit_failure', 'boolean');
$table->setPrimaryKey(array('id'));
$table->addUniqueIndex(array('class_id', 'object_identity_id', 'field_name', 'ace_order'));
$table->addIndex(array('class_id', 'object_identity_id', 'security_identity_id'));
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['class_id', 'object_identity_id', 'field_name', 'ace_order']);
$table->addIndex(['class_id', 'object_identity_id', 'security_identity_id']);
$table->addForeignKeyConstraint($this->getTable($this->options['class_table_name']), array('class_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE'));
$table->addForeignKeyConstraint($this->getTable($this->options['oid_table_name']), array('object_identity_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE'));
$table->addForeignKeyConstraint($this->getTable($this->options['sid_table_name']), array('security_identity_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE'));
$table->addForeignKeyConstraint($this->getTable($this->options['class_table_name']), ['class_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
$table->addForeignKeyConstraint($this->getTable($this->options['oid_table_name']), ['object_identity_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
$table->addForeignKeyConstraint($this->getTable($this->options['sid_table_name']), ['security_identity_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
}
/**
@@ -107,17 +105,17 @@ final class Schema extends BaseSchema
{
$table = $this->createTable($this->options['oid_table_name']);
$table->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
$table->addColumn('class_id', 'integer', array('unsigned' => true));
$table->addColumn('object_identifier', 'string', array('length' => 100));
$table->addColumn('parent_object_identity_id', 'integer', array('unsigned' => true, 'notnull' => false));
$table->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]);
$table->addColumn('class_id', 'integer', ['unsigned' => true]);
$table->addColumn('object_identifier', 'string', ['length' => 100]);
$table->addColumn('parent_object_identity_id', 'integer', ['unsigned' => true, 'notnull' => false]);
$table->addColumn('entries_inheriting', 'boolean');
$table->setPrimaryKey(array('id'));
$table->addUniqueIndex(array('object_identifier', 'class_id'));
$table->addIndex(array('parent_object_identity_id'));
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['object_identifier', 'class_id']);
$table->addIndex(['parent_object_identity_id']);
$table->addForeignKeyConstraint($table, array('parent_object_identity_id'), array('id'));
$table->addForeignKeyConstraint($table, ['parent_object_identity_id'], ['id']);
}
/**
@@ -127,14 +125,14 @@ final class Schema extends BaseSchema
{
$table = $this->createTable($this->options['oid_ancestors_table_name']);
$table->addColumn('object_identity_id', 'integer', array('unsigned' => true));
$table->addColumn('ancestor_id', 'integer', array('unsigned' => true));
$table->addColumn('object_identity_id', 'integer', ['unsigned' => true]);
$table->addColumn('ancestor_id', 'integer', ['unsigned' => true]);
$table->setPrimaryKey(array('object_identity_id', 'ancestor_id'));
$table->setPrimaryKey(['object_identity_id', 'ancestor_id']);
$oidTable = $this->getTable($this->options['oid_table_name']);
$table->addForeignKeyConstraint($oidTable, array('object_identity_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE'));
$table->addForeignKeyConstraint($oidTable, array('ancestor_id'), array('id'), array('onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE'));
$table->addForeignKeyConstraint($oidTable, ['object_identity_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
$table->addForeignKeyConstraint($oidTable, ['ancestor_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']);
}
/**
@@ -144,11 +142,11 @@ final class Schema extends BaseSchema
{
$table = $this->createTable($this->options['sid_table_name']);
$table->addColumn('id', 'integer', array('unsigned' => true, 'autoincrement' => true));
$table->addColumn('identifier', 'string', array('length' => 200));
$table->addColumn('id', 'integer', ['unsigned' => true, 'autoincrement' => true]);
$table->addColumn('identifier', 'string', ['length' => 200]);
$table->addColumn('username', 'boolean');
$table->setPrimaryKey(array('id'));
$table->addUniqueIndex(array('identifier', 'username'));
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['identifier', 'username']);
}
}