From 2afa233693f43a3c456035ef7f8154c096775ecf Mon Sep 17 00:00:00 2001 From: kissifrot Date: Thu, 24 Oct 2024 19:56:47 +0200 Subject: [PATCH] Fix compatibility with DBAL 4.x --- Dbal/MutableAclProvider.php | 3 +++ Dbal/Schema.php | 12 ++++++------ Tests/Dbal/MutableAclProviderTest.php | 22 +++++++++++++++++----- composer.json | 2 +- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Dbal/MutableAclProvider.php b/Dbal/MutableAclProvider.php index 0d69ca6..12555d9 100644 --- a/Dbal/MutableAclProvider.php +++ b/Dbal/MutableAclProvider.php @@ -80,6 +80,9 @@ public function createAcl(ObjectIdentityInterface $oid) */ public function deleteAcl(ObjectIdentityInterface $oid) { + if (!$this->connection->isTransactionActive()) { + $this->connection->setNestTransactionsWithSavepoints(true); + } $this->connection->beginTransaction(); try { foreach ($this->findChildren($oid, true) as $childOid) { diff --git a/Dbal/Schema.php b/Dbal/Schema.php index 56ea9dc..ff9ee01 100644 --- a/Dbal/Schema.php +++ b/Dbal/Schema.php @@ -94,9 +94,9 @@ protected function addEntryTable() $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']), ['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']); + $table->addForeignKeyConstraint($this->getTable($this->options['class_table_name'])->getName(), ['class_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); + $table->addForeignKeyConstraint($this->getTable($this->options['oid_table_name'])->getName(), ['object_identity_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); + $table->addForeignKeyConstraint($this->getTable($this->options['sid_table_name'])->getName(), ['security_identity_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => 'CASCADE']); } /** @@ -116,7 +116,7 @@ protected function addObjectIdentitiesTable() $table->addUniqueIndex(['object_identifier', 'class_id']); $table->addIndex(['parent_object_identity_id']); - $table->addForeignKeyConstraint($table, ['parent_object_identity_id'], ['id']); + $table->addForeignKeyConstraint($table->getName(), ['parent_object_identity_id'], ['id']); } /** @@ -137,8 +137,8 @@ protected function addObjectIdentityAncestorsTable() // MS SQL Server does not support recursive cascading $action = 'NO ACTION'; } - $table->addForeignKeyConstraint($oidTable, ['object_identity_id'], ['id'], ['onDelete' => $action, 'onUpdate' => $action]); - $table->addForeignKeyConstraint($oidTable, ['ancestor_id'], ['id'], ['onDelete' => $action, 'onUpdate' => $action]); + $table->addForeignKeyConstraint($oidTable->getName(), ['object_identity_id'], ['id'], ['onDelete' => $action, 'onUpdate' => $action]); + $table->addForeignKeyConstraint($oidTable->getName(), ['ancestor_id'], ['id'], ['onDelete' => $action, 'onUpdate' => $action]); } /** diff --git a/Tests/Dbal/MutableAclProviderTest.php b/Tests/Dbal/MutableAclProviderTest.php index d29a0d9..0822ee8 100644 --- a/Tests/Dbal/MutableAclProviderTest.php +++ b/Tests/Dbal/MutableAclProviderTest.php @@ -261,10 +261,18 @@ public function testUpdateDoesNothingWhenThereAreNoChanges() ->expects($this->never()) ->method('beginTransaction') ; - $con - ->expects($this->never()) - ->method('executeUpdate') - ; + if (method_exists(Connection::class, 'executeUpdate')) { + // DBAL < 4.0 + $con + ->expects($this->never()) + ->method('executeUpdate') + ; + } else { + $con + ->expects($this->never()) + ->method('executeStatement') + ; + } $provider = new MutableAclProvider($con, new PermissionGrantingStrategy(), []); $acl = new Acl(1, new ObjectIdentity(1, 'Foo'), new PermissionGrantingStrategy(), [], true); @@ -536,7 +544,10 @@ protected function setUp(): void ], $configuration ); - $this->connection->setNestTransactionsWithSavepoints(true); + if (method_exists($configuration, 'setNestTransactionsWithSavepoints')) { + // DBAL < 4.0 + $this->connection->setNestTransactionsWithSavepoints(true); + } // import the schema $schema = new Schema($this->getOptions()); @@ -547,6 +558,7 @@ protected function setUp(): void protected function tearDown(): void { + $this->connection->close(); $this->connection = null; } diff --git a/composer.json b/composer.json index 22eaea5..d3fa7e3 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "doctrine/cache": "^1.11|^2.0", "doctrine/common": "^2.2|^3", "doctrine/persistence": "^1.3.3|^2|^3", - "doctrine/dbal": "^2.13.1|^3.1", + "doctrine/dbal": "^2.13.1|^3.1|^4.0", "psr/log": "^1|^2|^3" }, "autoload": {