Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/datastore/src/DatastoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions modules/datastore/src/Form/ResourceSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. <p>Note that when a dataset is deleted, any localized resource for that dataset will also be deleted.</p>'),
];
$form['drop_datastore_on_post_import_error'] = [
'#type' => 'checkbox',
Expand Down
36 changes: 25 additions & 11 deletions modules/datastore/src/Service/ResourceLocalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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()
Expand Down