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
+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));
}
}