Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Fix #1224 [Deletion of m2o/o2m field error for enabled cache] (#1241)
Browse files Browse the repository at this point in the history
  • Loading branch information
binal-7span committed Sep 2, 2019
1 parent efa8410 commit 3102972
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 0 additions & 9 deletions src/core/Directus/Application/CoreServicesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,6 @@ protected function getEmitter()
$emitter->addAction($action, $cacheTableTagInvalidator);
}

$cacheEntityTagInvalidator = function ($tableName, $ids) use ($cachePool) {
foreach ($ids as $id) {
$cachePool->invalidateTags(['entity_' . $tableName . '_' . $id]);
}
};
foreach (['item.delete:after'] as $action) {
$emitter->addAction($action, $cacheEntityTagInvalidator);
}

$emitter->addAction('item.update.directus_permissions:after', function ($data) use ($container, $cachePool) {
$acl = $container->get('acl');
$dbConnection = $container->get('database');
Expand Down
14 changes: 12 additions & 2 deletions src/core/Directus/Database/TableGateway/BaseTableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ protected function executeDelete(Delete $delete)

$deleteState = $delete->getRawState();
$deleteTable = $this->getRawTableNameFromQueryStateTable($deleteState['table']);

// Runs select PK with passed delete's $where before deleting, to use those for the even hook
if ($pk = $this->primaryKeyFieldName) {
$select = $this->sql->select();
Expand All @@ -924,7 +924,7 @@ protected function executeDelete(Delete $delete)
$delete = $this->sql->delete();
$expression = new In($pk, $ids);
$delete->where($expression);

foreach ($ids as $id) {
$deleteData = [$this->primaryKeyFieldName => $id];
$this->runHook('item.delete:before', [$deleteTable, $deleteData]);
Expand All @@ -940,14 +940,24 @@ protected function executeDelete(Delete $delete)
);
}


//Invalidate individual cache
$config = static::$container->get('config');

foreach ($ids as $id) {
$deleteData = $deletedObject[$id];
$this->runHook('item.delete', [$deleteTable, $deleteData]);
$this->runHook('item.delete:after', [$deleteTable, $deleteData]);
$this->runHook('item.delete.' . $deleteTable, [$deleteData]);
$this->runHook('item.delete.' . $deleteTable . ':after', [$deleteData]);
if ($config->get('cache.enabled')) {
$cachePool = static::$container->get('cache');
$cachePool->invalidateTags(['entity_' . $deleteTable . '_' . $deleteData[$this->primaryKeyFieldName]]);
}
}



return $result;
}
}
Expand Down

1 comment on commit 3102972

@jbalatero
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Please sign in to comment.