Skip to content

Commit 61fe3c7

Browse files
committed
Fix compatibility with Doctrine DBAL 3
1 parent 3cbe1ef commit 61fe3c7

File tree

6 files changed

+89
-91
lines changed

6 files changed

+89
-91
lines changed

Dbal/AclProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function findChildren(ObjectIdentityInterface $parentOid, $directChildren
7777
$sql = $this->getFindChildrenSql($parentOid, $directChildrenOnly);
7878

7979
$children = [];
80-
foreach ($this->connection->executeQuery($sql)->fetchAll() as $data) {
80+
foreach ($this->connection->executeQuery($sql)->fetchAllAssociative() as $data) {
8181
$children[] = new ObjectIdentity($data['object_identifier'], $data['class_type']);
8282
}
8383

@@ -384,7 +384,7 @@ protected function getSelectObjectIdentityIdSql(ObjectIdentityInterface $oid)
384384
*/
385385
final protected function retrieveObjectIdentityPrimaryKey(ObjectIdentityInterface $oid)
386386
{
387-
return $this->connection->executeQuery($this->getSelectObjectIdentityIdSql($oid))->fetchColumn();
387+
return $this->connection->executeQuery($this->getSelectObjectIdentityIdSql($oid))->fetchOne();
388388
}
389389

390390
/**
@@ -421,7 +421,7 @@ private function getAncestorIds(array $batch)
421421
$sql = $this->getAncestorLookupSql($batch);
422422

423423
$ancestorIds = [];
424-
foreach ($this->connection->executeQuery($sql)->fetchAll() as $data) {
424+
foreach ($this->connection->executeQuery($sql)->fetchAllAssociative() as $data) {
425425
// FIXME: skip ancestors which are cached
426426
// Fix: Oracle returns keys in uppercase
427427
$ancestorIds[] = reset($data);
@@ -506,7 +506,7 @@ private function hydrateObjectIdentities(Result $stmt, array $oidLookup, array $
506506

507507
// fetchAll() consumes more memory than consecutive calls to fetch(),
508508
// but it is faster
509-
foreach ($stmt->fetchAll(\PDO::FETCH_NUM) as $data) {
509+
foreach ($stmt->fetchAllNumeric() as $data) {
510510
list($aclId,
511511
$objectIdentifier,
512512
$parentObjectIdentityId,

Dbal/MutableAclProvider.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function createAcl(ObjectIdentityInterface $oid)
6060
$this->createObjectIdentity($oid);
6161

6262
$pk = $this->retrieveObjectIdentityPrimaryKey($oid);
63-
$this->connection->executeUpdate($this->getInsertObjectIdentityRelationSql($pk, $pk));
63+
$this->connection->executeStatement($this->getInsertObjectIdentityRelationSql($pk, $pk));
6464

6565
$this->connection->commit();
6666
} catch (\Exception $e) {
@@ -117,7 +117,7 @@ public function deleteAcl(ObjectIdentityInterface $oid)
117117
*/
118118
public function deleteSecurityIdentity(SecurityIdentityInterface $sid)
119119
{
120-
$this->connection->executeUpdate($this->getDeleteSecurityIdentityIdSql($sid));
120+
$this->connection->executeStatement($this->getDeleteSecurityIdentityIdSql($sid));
121121
}
122122

123123
/**
@@ -332,7 +332,7 @@ public function updateAcl(MutableAclInterface $acl)
332332

333333
// persist any changes to the acl_object_identities table
334334
if (\count($sets) > 0) {
335-
$this->connection->executeUpdate($this->getUpdateObjectIdentitySql($acl->getId(), $sets));
335+
$this->connection->executeStatement($this->getUpdateObjectIdentitySql($acl->getId(), $sets));
336336
}
337337

338338
$this->connection->commit();
@@ -370,7 +370,7 @@ public function updateAcl(MutableAclInterface $acl)
370370
*/
371371
public function updateUserSecurityIdentity(UserSecurityIdentity $usid, $oldUsername)
372372
{
373-
$this->connection->executeUpdate($this->getUpdateUserSecurityIdentitySql($usid, $oldUsername));
373+
$this->connection->executeStatement($this->getUpdateUserSecurityIdentitySql($usid, $oldUsername));
374374
}
375375

376376
/**
@@ -736,7 +736,7 @@ private function createObjectIdentity(ObjectIdentityInterface $oid)
736736
{
737737
$classId = $this->createOrRetrieveClassId($oid->getType());
738738

739-
$this->connection->executeUpdate($this->getInsertObjectIdentitySql($oid->getIdentifier(), $classId, true));
739+
$this->connection->executeStatement($this->getInsertObjectIdentitySql($oid->getIdentifier(), $classId, true));
740740
}
741741

742742
/**
@@ -750,13 +750,13 @@ private function createObjectIdentity(ObjectIdentityInterface $oid)
750750
*/
751751
private function createOrRetrieveClassId($classType)
752752
{
753-
if (false !== $id = $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn()) {
753+
if (false !== $id = $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchOne()) {
754754
return $id;
755755
}
756756

757-
$this->connection->executeUpdate($this->getInsertClassSql($classType));
757+
$this->connection->executeStatement($this->getInsertClassSql($classType));
758758

759-
return $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn();
759+
return $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchOne();
760760
}
761761

762762
/**
@@ -769,13 +769,13 @@ private function createOrRetrieveClassId($classType)
769769
*/
770770
private function createOrRetrieveSecurityIdentityId(SecurityIdentityInterface $sid)
771771
{
772-
if (false !== $id = $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn()) {
772+
if (false !== $id = $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchOne()) {
773773
return $id;
774774
}
775775

776-
$this->connection->executeUpdate($this->getInsertSecurityIdentitySql($sid));
776+
$this->connection->executeStatement($this->getInsertSecurityIdentitySql($sid));
777777

778-
return $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn();
778+
return $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchOne();
779779
}
780780

781781
/**
@@ -785,7 +785,7 @@ private function createOrRetrieveSecurityIdentityId(SecurityIdentityInterface $s
785785
*/
786786
private function deleteAccessControlEntries($oidPK)
787787
{
788-
$this->connection->executeUpdate($this->getDeleteAccessControlEntriesSql($oidPK));
788+
$this->connection->executeStatement($this->getDeleteAccessControlEntriesSql($oidPK));
789789
}
790790

791791
/**
@@ -795,7 +795,7 @@ private function deleteAccessControlEntries($oidPK)
795795
*/
796796
private function deleteObjectIdentity($pk)
797797
{
798-
$this->connection->executeUpdate($this->getDeleteObjectIdentitySql($pk));
798+
$this->connection->executeStatement($this->getDeleteObjectIdentitySql($pk));
799799
}
800800

801801
/**
@@ -805,7 +805,7 @@ private function deleteObjectIdentity($pk)
805805
*/
806806
private function deleteObjectIdentityRelations($pk)
807807
{
808-
$this->connection->executeUpdate($this->getDeleteObjectIdentityRelationsSql($pk));
808+
$this->connection->executeStatement($this->getDeleteObjectIdentityRelationsSql($pk));
809809
}
810810

811811
/**
@@ -814,12 +814,12 @@ private function deleteObjectIdentityRelations($pk)
814814
private function regenerateAncestorRelations(AclInterface $acl)
815815
{
816816
$pk = $acl->getId();
817-
$this->connection->executeUpdate($this->getDeleteObjectIdentityRelationsSql($pk));
818-
$this->connection->executeUpdate($this->getInsertObjectIdentityRelationSql($pk, $pk));
817+
$this->connection->executeStatement($this->getDeleteObjectIdentityRelationsSql($pk));
818+
$this->connection->executeStatement($this->getInsertObjectIdentityRelationSql($pk, $pk));
819819

820820
$parentAcl = $acl->getParentAcl();
821821
while (null !== $parentAcl) {
822-
$this->connection->executeUpdate($this->getInsertObjectIdentityRelationSql($pk, $parentAcl->getId()));
822+
$this->connection->executeStatement($this->getInsertObjectIdentityRelationSql($pk, $parentAcl->getId()));
823823

824824
$parentAcl = $parentAcl->getParentAcl();
825825
}
@@ -854,8 +854,8 @@ private function updateNewFieldAceProperty($name, array $changes)
854854

855855
$objectIdentityId = 'classFieldAces' === $name ? null : $ace->getAcl()->getId();
856856

857-
$this->connection->executeUpdate($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, $field, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
858-
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, $field, $i))->fetchColumn();
857+
$this->connection->executeStatement($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, $field, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
858+
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, $field, $i))->fetchOne();
859859
$this->loadedAces[$aceId] = $ace;
860860

861861
$aceIdProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Entry', 'id');
@@ -889,7 +889,7 @@ private function updateOldFieldAceProperty($name, array $changes)
889889
$ace = $old[$i];
890890

891891
if (!isset($currentIds[$ace->getId()])) {
892-
$this->connection->executeUpdate($this->getDeleteAccessControlEntrySql($ace->getId()));
892+
$this->connection->executeStatement($this->getDeleteAccessControlEntrySql($ace->getId()));
893893
unset($this->loadedAces[$ace->getId()]);
894894
}
895895
}
@@ -926,8 +926,8 @@ private function updateNewAceProperty($name, array $changes)
926926

927927
$objectIdentityId = 'classAces' === $name ? null : $ace->getAcl()->getId();
928928

929-
$this->connection->executeUpdate($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, null, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
930-
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, null, $i))->fetchColumn();
929+
$this->connection->executeStatement($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, null, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
930+
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, null, $i))->fetchOne();
931931
$this->loadedAces[$aceId] = $ace;
932932

933933
$aceIdProperty = new \ReflectionProperty($ace, 'id');
@@ -959,7 +959,7 @@ private function updateOldAceProperty($name, array $changes)
959959
$ace = $old[$i];
960960

961961
if (!isset($currentIds[$ace->getId()])) {
962-
$this->connection->executeUpdate($this->getDeleteAccessControlEntrySql($ace->getId()));
962+
$this->connection->executeStatement($this->getDeleteAccessControlEntrySql($ace->getId()));
963963
unset($this->loadedAces[$ace->getId()]);
964964
}
965965
}
@@ -1005,6 +1005,6 @@ private function updateAce(\SplObjectStorage $aces, $ace)
10051005
$sets[] = sprintf('audit_failure = %s', $this->connection->getDatabasePlatform()->convertBooleans($propertyChanges['auditFailure'][1]));
10061006
}
10071007

1008-
$this->connection->executeUpdate($this->getUpdateAccessControlEntrySql($ace->getId(), $sets));
1008+
$this->connection->executeStatement($this->getUpdateAccessControlEntrySql($ace->getId(), $sets));
10091009
}
10101010
}

Tests/Dbal/AclProviderBenchmarkTest.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Component\Security\Acl\Tests\Dbal;
1313

14+
use Doctrine\DBAL\Connection;
1415
use Doctrine\DBAL\DriverManager;
16+
use PHPUnit\Framework\TestCase;
1517
use Symfony\Component\Security\Acl\Dbal\AclProvider;
1618
use Symfony\Component\Security\Acl\Dbal\Schema;
1719
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
@@ -20,10 +22,10 @@
2022
/**
2123
* @group benchmark
2224
*/
23-
class AclProviderBenchmarkTest extends \PHPUnit\Framework\TestCase
25+
class AclProviderBenchmarkTest extends TestCase
2426
{
25-
/** @var \Doctrine\DBAL\Connection */
26-
protected $con;
27+
/** @var Connection */
28+
protected $connection;
2729
protected $insertClassStmt;
2830
protected $insertSidStmt;
2931
protected $insertOidAncestorStmt;
@@ -33,21 +35,21 @@ class AclProviderBenchmarkTest extends \PHPUnit\Framework\TestCase
3335
protected function setUp(): void
3436
{
3537
try {
36-
$this->con = DriverManager::getConnection([
38+
$this->connection = DriverManager::getConnection([
3739
'driver' => 'pdo_mysql',
3840
'host' => 'localhost',
3941
'user' => 'root',
4042
'dbname' => 'testdb',
4143
]);
42-
$this->con->connect();
44+
$this->connection->connect();
4345
} catch (\Exception $e) {
4446
$this->markTestSkipped('Unable to connect to the database: '.$e->getMessage());
4547
}
4648
}
4749

4850
protected function tearDown(): void
4951
{
50-
$this->con = null;
52+
$this->connection = null;
5153
}
5254

5355
public function testFindAcls()
@@ -56,8 +58,8 @@ public function testFindAcls()
5658

5759
// get some random test object identities from the database
5860
$oids = [];
59-
$stmt = $this->con->executeQuery('SELECT object_identifier, class_type FROM acl_object_identities o INNER JOIN acl_classes c ON c.id = o.class_id ORDER BY RAND() LIMIT 25');
60-
foreach ($stmt->fetchAll() as $oid) {
61+
$stmt = $this->connection->executeQuery('SELECT object_identifier, class_type FROM acl_object_identities o INNER JOIN acl_classes c ON c.id = o.class_id ORDER BY RAND() LIMIT 25');
62+
foreach ($stmt->fetchAllAssociative() as $oid) {
6163
$oids[] = new ObjectIdentity($oid['object_identifier'], $oid['class_type']);
6264
}
6365

@@ -75,22 +77,22 @@ public function testFindAcls()
7577
*/
7678
protected function generateTestData()
7779
{
78-
$sm = $this->con->getSchemaManager();
80+
$sm = $this->connection->getSchemaManager();
7981
$sm->dropAndCreateDatabase('testdb');
80-
$this->con->exec('USE testdb');
82+
$this->connection->exec('USE testdb');
8183

8284
// import the schema
8385
$schema = new Schema($options = $this->getOptions());
84-
foreach ($schema->toSql($this->con->getDatabasePlatform()) as $sql) {
85-
$this->con->exec($sql);
86+
foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
87+
$this->connection->exec($sql);
8688
}
8789

8890
// setup prepared statements
89-
$this->insertClassStmt = $this->con->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
90-
$this->insertSidStmt = $this->con->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
91-
$this->insertOidStmt = $this->con->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)');
92-
$this->insertEntryStmt = $this->con->prepare('INSERT INTO acl_entries (id, class_id, object_identity_id, field_name, ace_order, security_identity_id, mask, granting, granting_strategy, audit_success, audit_failure) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
93-
$this->insertOidAncestorStmt = $this->con->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
91+
$this->insertClassStmt = $this->connection->prepare('INSERT INTO acl_classes (id, class_type) VALUES (?, ?)');
92+
$this->insertSidStmt = $this->connection->prepare('INSERT INTO acl_security_identities (id, identifier, username) VALUES (?, ?, ?)');
93+
$this->insertOidStmt = $this->connection->prepare('INSERT INTO acl_object_identities (id, class_id, object_identifier, parent_object_identity_id, entries_inheriting) VALUES (?, ?, ?, ?, ?)');
94+
$this->insertEntryStmt = $this->connection->prepare('INSERT INTO acl_entries (id, class_id, object_identity_id, field_name, ace_order, security_identity_id, mask, granting, granting_strategy, audit_success, audit_failure) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
95+
$this->insertOidAncestorStmt = $this->connection->prepare('INSERT INTO acl_object_identity_ancestors (object_identity_id, ancestor_id) VALUES (?, ?)');
9496

9597
for ($i = 0; $i < 40000; ++$i) {
9698
$this->generateAclHierarchy();
@@ -121,7 +123,7 @@ protected function chooseClassId()
121123
static $id = 1000;
122124

123125
if (1000 === $id || ($id < 1500 && rand(0, 1))) {
124-
$this->insertClassStmt->execute([$id, $this->getRandomString(rand(20, 100), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\\_')]);
126+
$this->insertClassStmt->executeStatement([$id, $this->getRandomString(rand(20, 100), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\\_')]);
125127
++$id;
126128

127129
return $id - 1;
@@ -134,17 +136,17 @@ protected function generateAcl($classId, $parentId, $ancestors)
134136
{
135137
static $id = 1000;
136138

137-
$this->insertOidStmt->execute([
139+
$this->insertOidStmt->executeStatement([
138140
$id,
139141
$classId,
140142
$this->getRandomString(rand(20, 50)),
141143
$parentId,
142144
rand(0, 1),
143145
]);
144146

145-
$this->insertOidAncestorStmt->execute([$id, $id]);
147+
$this->insertOidAncestorStmt->executeStatement([$id, $id]);
146148
foreach ($ancestors as $ancestor) {
147-
$this->insertOidAncestorStmt->execute([$id, $ancestor]);
149+
$this->insertOidAncestorStmt->executeStatement([$id, $ancestor]);
148150
}
149151

150152
$this->generateAces($classId, $id);
@@ -158,7 +160,7 @@ protected function chooseSid()
158160
static $id = 1000;
159161

160162
if (1000 === $id || ($id < 11000 && rand(0, 1))) {
161-
$this->insertSidStmt->execute([
163+
$this->insertSidStmt->executeStatement([
162164
$id,
163165
$this->getRandomString(rand(5, 30)),
164166
rand(0, 1),
@@ -201,7 +203,7 @@ protected function generateAces($classId, $objectId)
201203
}
202204

203205
// id, cid, oid, field, order, sid, mask, granting, strategy, a success, a failure
204-
$this->insertEntryStmt->execute([
206+
$this->insertEntryStmt->executeStatement([
205207
$id,
206208
$classId,
207209
rand(0, 5) ? $objectId : null,
@@ -262,6 +264,6 @@ protected function getStrategy()
262264

263265
protected function getProvider()
264266
{
265-
return new AclProvider($this->con, $this->getStrategy(), $this->getOptions());
267+
return new AclProvider($this->connection, $this->getStrategy(), $this->getOptions());
266268
}
267269
}

0 commit comments

Comments
 (0)