From 61e73f4dd8ca177c28069f72e408c22e1be55007 Mon Sep 17 00:00:00 2001 From: Paul Mitchum Date: Wed, 20 Nov 2024 10:12:01 -0800 Subject: [PATCH] Handle missing resource when dropping a datastore (#4343) --- modules/datastore/src/DatastoreService.php | 35 +++++++++++++--------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/modules/datastore/src/DatastoreService.php b/modules/datastore/src/DatastoreService.php index 627343b582..02230c3383 100644 --- a/modules/datastore/src/DatastoreService.php +++ b/modules/datastore/src/DatastoreService.php @@ -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) {