Skip to content

Commit

Permalink
Fix compatibility with DBAL 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
kissifrot committed Nov 23, 2024
1 parent 96a1d7e commit f50a430
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
18 changes: 15 additions & 3 deletions Dbal/MutableAclProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
class MutableAclProvider extends AclProvider implements MutableAclProviderInterface, PropertyChangedListener
{
private $propertyChanges;
private $transactionStarted = false;

/**
* {@inheritdoc}
Expand Down Expand Up @@ -80,7 +81,12 @@ public function createAcl(ObjectIdentityInterface $oid)
*/
public function deleteAcl(ObjectIdentityInterface $oid)
{
$this->connection->beginTransaction();
// DBAL 4.0 does not support nested transactions, so we need to keep track of the transaction state
// @see https://github.com/doctrine/dbal/pull/5383 and https://github.com/doctrine/dbal/pull/5401
if (!$this->transactionStarted) {
$this->connection->beginTransaction();
$this->transactionStarted = true;
}
try {
foreach ($this->findChildren($oid, true) as $childOid) {
$this->deleteAcl($childOid);
Expand All @@ -92,9 +98,15 @@ public function deleteAcl(ObjectIdentityInterface $oid)
$this->deleteObjectIdentityRelations($oidPK);
$this->deleteObjectIdentity($oidPK);

$this->connection->commit();
if ($this->transactionStarted) {
$this->connection->commit();
$this->transactionStarted = false;
}
} catch (\Exception $e) {
$this->connection->rollBack();
if ($this->transactionStarted) {
$this->connection->rollBack();
$this->transactionStarted = false;
}

throw $e;
}
Expand Down
12 changes: 6 additions & 6 deletions Dbal/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand All @@ -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']);
}

/**
Expand All @@ -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]);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Tests/Dbal/MutableAclProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function testUpdateDoesNothingWhenThereAreNoChanges()
;
$con
->expects($this->never())
->method('executeUpdate')
->method('executeStatement')
;

$provider = new MutableAclProvider($con, new PermissionGrantingStrategy(), []);
Expand Down Expand Up @@ -536,7 +536,6 @@ protected function setUp(): void
],
$configuration
);
$this->connection->setNestTransactionsWithSavepoints(true);

// import the schema
$schema = new Schema($this->getOptions());
Expand All @@ -547,6 +546,7 @@ protected function setUp(): void

protected function tearDown(): void
{
$this->connection->close();
$this->connection = null;
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"psr/log": "^1|^2|^3"
},
"autoload": {
Expand Down

0 comments on commit f50a430

Please sign in to comment.