diff --git a/modules/datastore/src/DatastoreService.php b/modules/datastore/src/DatastoreService.php index a8670d74fe..e7a0ee5b4f 100644 --- a/modules/datastore/src/DatastoreService.php +++ b/modules/datastore/src/DatastoreService.php @@ -278,7 +278,7 @@ public function drop(string $identifier, ?string $version = NULL, bool $remove_l if ($storage = $this->getStorage($identifier, $version)) { $resource = NULL; // Check for the resource before sending the pre-drop event. - if ($resource = $this->resourceLocalizer->get($identifier, $version)) { + if ($resource = $this->resourceLocalizer->get($identifier, $version, ResourceLocalizer::LOCAL_FILE_PERSPECTIVE, FALSE)) { // Dispatch the pre-drop event. $this->eventDispatcher->dispatch( new DatastorePreDropEvent($resource), diff --git a/modules/datastore/src/Form/ResourceSettingsForm.php b/modules/datastore/src/Form/ResourceSettingsForm.php index 3cad146d6d..957af151a8 100644 --- a/modules/datastore/src/Form/ResourceSettingsForm.php +++ b/modules/datastore/src/Form/ResourceSettingsForm.php @@ -45,9 +45,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; $form['delete_local_resource'] = [ '#type' => 'checkbox', - '#title' => $this->t('Delete local resource'), + '#title' => $this->t('Delete localized resource'), '#config_target' => 'datastore.settings:delete_local_resource', - '#description' => $this->t('Delete local copy of remote files after the datastore import is complete'), + '#description' => $this->t('Delete localized copy of remote files after the datastore import is complete. If your catalog will rely on the remote source for downloads this can keep your web server file storage lean.
Note that when a dataset is deleted, any localized resource for that dataset will also be deleted.
'), ]; $form['drop_datastore_on_post_import_error'] = [ '#type' => 'checkbox', diff --git a/modules/datastore/src/Service/ResourceLocalizer.php b/modules/datastore/src/Service/ResourceLocalizer.php index 56ee9aa27e..2943e50105 100644 --- a/modules/datastore/src/Service/ResourceLocalizer.php +++ b/modules/datastore/src/Service/ResourceLocalizer.php @@ -157,29 +157,43 @@ public function localizeTask(string $identifier, ?string $version = NULL, bool $ } /** - * Create local file and URL perspectives in the mapper, get a perspective. + * Get a perspective, and optionally reate local file and URL perspectives. * - * Requires the localized file to exist so it can be checksummed. + * @param string $identifier + * The resource id. + * @param string $version + * The resource version. + * @param string $perspective + * The resource perspective. Defaults to LOCAL_FILE_PERSPECTIVE. + * @param bool $create + * If true, creates directory for local file and adds perspective to mapper. * * @return \Drupal\common\DataResource|null * Return the perspective, or NULL if the source perspective did not exist. */ - public function get($identifier, $version = NULL, $perpective = self::LOCAL_FILE_PERSPECTIVE): ?DataResource { + public function get( + string $identifier, + ?string $version = NULL, + string $perspective = self::LOCAL_FILE_PERSPECTIVE, + bool $create = TRUE, + ): ?DataResource { $resource = $this->getResourceSource($identifier, $version); if (!$resource) { return NULL; } - $ff = $this->getFileFetcher($resource); + if ($create) { + $ff = $this->getFileFetcher($resource); - if ($ff->getResult()->getStatus() != Result::DONE) { - return NULL; - } + if ($ff->getResult()->getStatus() != Result::DONE) { + return NULL; + } - $this->registerNewPerspectives($resource, $ff->getStateProperty('destination')); + $this->registerNewPerspectives($resource, $ff->getStateProperty('destination')); + } - return $this->resourceMapper->get($resource->getIdentifier(), $perpective, $resource->getVersion()); + return $this->resourceMapper->get($resource->getIdentifier(), $perspective, $resource->getVersion()); } /** @@ -215,11 +229,11 @@ private function registerNewPerspectives(DataResource $resource, string $localFi */ public function remove($identifier, $version = NULL): void { // Remove the LOCAL_URL_PERSPECTIVE if it exists. - if ($local_url_resource = $this->get($identifier, $version, self::LOCAL_URL_PERSPECTIVE)) { + if ($local_url_resource = $this->get($identifier, $version, self::LOCAL_URL_PERSPECTIVE, FALSE)) { $this->resourceMapper->remove($local_url_resource); } // Remove the LOCAL_FILE_PERSPECTIVE if it exists. - if ($resource = $this->get($identifier, $version, self::LOCAL_FILE_PERSPECTIVE)) { + if ($resource = $this->get($identifier, $version, self::LOCAL_FILE_PERSPECTIVE, FALSE)) { // Remove the file. if (file_exists($resource->getFilePath())) { $this->drupalFiles->getFilesystem()