Skip to content

Commit

Permalink
Handle missing resource when dropping a datastore (#4343)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-m authored Nov 20, 2024
1 parent bf01f56 commit 61e73f4
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions modules/datastore/src/DatastoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,22 +269,29 @@ public function getDataDictionaryFields(?string $identifier = NULL): ?array {
*/
public function drop(string $identifier, ?string $version = NULL, bool $remove_local_resource = TRUE) {
if ($storage = $this->getStorage($identifier, $version)) {
$resource = $this->resourceLocalizer->get($identifier, $version);
// Dispatch the pre-drop event.
$this->eventDispatcher->dispatch(
new DatastorePreDropEvent($resource),
self::EVENT_DATASTORE_PRE_DROP
);
$resource = NULL;
// Check for the resource before sending the pre-drop event.
if ($resource = $this->resourceLocalizer->get($identifier, $version)) {
// Dispatch the pre-drop event.
$this->eventDispatcher->dispatch(
new DatastorePreDropEvent($resource),
self::EVENT_DATASTORE_PRE_DROP
);
}
// Drop.
$storage->destruct();
// Remove the info from the job store.
$this->importJobStoreFactory->getInstance()
->remove(md5($resource->getUniqueIdentifier()));
// Dispatch the dropped event.
$this->eventDispatcher->dispatch(
new DatastoreDroppedEvent($resource),
self::EVENT_DATASTORE_DROPPED
);
// Check for the resource before removing the job store or sending the
// dropped event.
if ($resource) {
// Remove the info from the job store.
$this->importJobStoreFactory->getInstance()
->remove(md5($resource->getUniqueIdentifier()));
// Dispatch the dropped event.
$this->eventDispatcher->dispatch(
new DatastoreDroppedEvent($resource),
self::EVENT_DATASTORE_DROPPED
);
}
}

if ($remove_local_resource) {
Expand Down

0 comments on commit 61e73f4

Please sign in to comment.