diff --git a/modules/datastore/src/Drush.php b/modules/datastore/src/Drush.php index ca34b55db4..0a3e500b56 100755 --- a/modules/datastore/src/Drush.php +++ b/modules/datastore/src/Drush.php @@ -223,10 +223,18 @@ private function createRow($uuid, $item) { */ public function drop(string $identifier, array $options = ['keep-local' => FALSE]) { $local_resource = $options['keep-local'] ? FALSE : TRUE; - $this->datastoreService->drop($identifier, NULL, $local_resource); - $this->logger->notice("Successfully dropped the datastore for resource {$identifier}"); + try { + $this->datastoreService->drop($identifier, NULL, $local_resource); + $this->logger->notice('Successfully dropped the datastore for resource ' . $identifier); + } + catch (\InvalidArgumentException $e) { + // We get an invalid argument exception when the datastore does not exist. + // This can be because it was never imported, or because the resource + // is a type that will never be imported, such as a ZIP file. + $this->logger->warning('Unable to drop datastore for ' . $identifier); + } $this->postImport->removeJobStatus($identifier); - $this->logger->notice("Successfully removed the post import job status for resource {$identifier}"); + $this->logger->notice('Successfully removed the post import job status for resource ' . $identifier); } /** @@ -235,9 +243,11 @@ public function drop(string $identifier, array $options = ['keep-local' => FALSE * @command dkan:datastore:drop-all */ public function dropAll() { + /** @var \RootedData\RootedJsonData $distribution*/ foreach ($this->metastoreService->getAll('distribution') as $distribution) { - $uuid = $distribution->data->{'%Ref:downloadURL'}[0]->data->identifier; - $this->drop($uuid); + if ($uuid = $distribution->get('$[data]["%Ref:downloadURL"][0][data][identifier]') ?? FALSE) { + $this->drop($uuid); + } } }