Skip to content

Commit 61e73f4

Browse files
authored
Handle missing resource when dropping a datastore (#4343)
1 parent bf01f56 commit 61e73f4

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

modules/datastore/src/DatastoreService.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,29 @@ public function getDataDictionaryFields(?string $identifier = NULL): ?array {
269269
*/
270270
public function drop(string $identifier, ?string $version = NULL, bool $remove_local_resource = TRUE) {
271271
if ($storage = $this->getStorage($identifier, $version)) {
272-
$resource = $this->resourceLocalizer->get($identifier, $version);
273-
// Dispatch the pre-drop event.
274-
$this->eventDispatcher->dispatch(
275-
new DatastorePreDropEvent($resource),
276-
self::EVENT_DATASTORE_PRE_DROP
277-
);
272+
$resource = NULL;
273+
// Check for the resource before sending the pre-drop event.
274+
if ($resource = $this->resourceLocalizer->get($identifier, $version)) {
275+
// Dispatch the pre-drop event.
276+
$this->eventDispatcher->dispatch(
277+
new DatastorePreDropEvent($resource),
278+
self::EVENT_DATASTORE_PRE_DROP
279+
);
280+
}
278281
// Drop.
279282
$storage->destruct();
280-
// Remove the info from the job store.
281-
$this->importJobStoreFactory->getInstance()
282-
->remove(md5($resource->getUniqueIdentifier()));
283-
// Dispatch the dropped event.
284-
$this->eventDispatcher->dispatch(
285-
new DatastoreDroppedEvent($resource),
286-
self::EVENT_DATASTORE_DROPPED
287-
);
283+
// Check for the resource before removing the job store or sending the
284+
// dropped event.
285+
if ($resource) {
286+
// Remove the info from the job store.
287+
$this->importJobStoreFactory->getInstance()
288+
->remove(md5($resource->getUniqueIdentifier()));
289+
// Dispatch the dropped event.
290+
$this->eventDispatcher->dispatch(
291+
new DatastoreDroppedEvent($resource),
292+
self::EVENT_DATASTORE_DROPPED
293+
);
294+
}
288295
}
289296

290297
if ($remove_local_resource) {

0 commit comments

Comments
 (0)