Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Post Import Service #4370

Merged
merged 7 commits into from
Jan 16, 2025
Merged
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
14 changes: 12 additions & 2 deletions modules/datastore/datastore.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ services:
dkan.datastore.service.post_import:
class: \Drupal\datastore\Service\PostImport
arguments:
- '@database'
- '@dkan.metastore.resource_mapper'
- '@config.factory'
- '@dkan.datastore.logger_channel'
- '@dkan.datastore.service.resource_processor_collector'
- '@dkan.metastore.data_dictionary_discovery'
- '@dkan.datastore.service'
- '@dkan.datastore.post_import_result_factory'

dkan.datastore.post_import_result_factory:
class: Drupal\datastore\PostImportResultFactory
arguments:
- '@database'
- '@dkan.metastore.resource_mapper'

dkan.datastore.query:
class: \Drupal\datastore\Service\Query
Expand Down
2 changes: 1 addition & 1 deletion modules/datastore/drush.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ services:
arguments:
- '@dkan.metastore.service'
- '@dkan.datastore.service'
- '@dkan.datastore.service.post_import'
- '@dkan.datastore.service.resource_localizer'
- '@dkan.metastore.resource_mapper'
- '@dkan.datastore.import_info_list'
- '@dkan.datastore.post_import_result_factory'
tags:
- { name: drush.command }
datastore.purger.commands:
Expand Down
12 changes: 11 additions & 1 deletion modules/datastore/src/DatastoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,18 @@ public function getQueueFactory(): QueueFactory {
* @param mixed $resourceId
* A resource ID.
*/
protected function invalidateCacheTags(mixed $resourceId) {
public function invalidateCacheTags(mixed $resourceId) {
$this->referenceLookup->invalidateReferencerCacheTags('distribution', $resourceId, 'downloadURL');
}

/**
* Return the resource mapper.
*
* @return \Drupal\metastore\ResourceMapper
* Resource mapper.
*/
public function getResourceMapper(): ResourceMapper {
return $this->resourceMapper;
}

}
24 changes: 13 additions & 11 deletions modules/datastore/src/Drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace Drupal\datastore;

use Drupal\Component\Utility\DeprecationHelper;
use Drupal\Core\StringTranslation\ByteSizeMarkup;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Consolidation\OutputFormatters\StructuredData\UnstructuredListData;
use Drupal\common\DataResource;
use Drupal\Component\Utility\DeprecationHelper;
use Drupal\Core\StringTranslation\ByteSizeMarkup;
use Drupal\datastore\Service\Info\ImportInfoList;
use Drupal\datastore\Service\ResourceLocalizer;
use Drupal\metastore\MetastoreService;
use Drupal\datastore\Service\PostImport;
use Drupal\metastore\ResourceMapper;
use Drush\Commands\DrushCommands;
use Procrastinator\Result;
Expand All @@ -36,11 +35,6 @@ class Drush extends DrushCommands {
*/
protected $datastoreService;

/**
* The PostImport service.
*/
protected PostImport $postImport;

/**
* The datastore resource localizer.
*/
Expand All @@ -56,24 +50,31 @@ class Drush extends DrushCommands {
*/
private ImportInfoList $importInfoList;

/**
* The PostImportResultFactory service.
*
* @var \Drupal\datastore\PostImportResultFactory
*/
protected PostImportResultFactory $postImportResultFactory;

/**
* Constructor for DkanDatastoreCommands.
*/
public function __construct(
MetastoreService $metastoreService,
DatastoreService $datastoreService,
PostImport $postImport,
ResourceLocalizer $resourceLocalizer,
ResourceMapper $resourceMapper,
ImportInfoList $importInfoList,
PostImportResultFactory $postImportResultFactory
) {
parent::__construct();
$this->metastoreService = $metastoreService;
$this->datastoreService = $datastoreService;
$this->postImport = $postImport;
$this->resourceLocalizer = $resourceLocalizer;
$this->resourceMapper = $resourceMapper;
$this->importInfoList = $importInfoList;
$this->postImportResultFactory = $postImportResultFactory;
}

/**
Expand Down Expand Up @@ -241,7 +242,8 @@ public function drop(string $identifier, array $options = ['keep-local' => FALSE
// 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);
$post_import_result = $this->postImportResultFactory->initializeFromDistribution(['resource_id' => $identifier]);
$post_import_result->removeJobStatus();
$this->logger->notice('Successfully removed the post import job status for resource ' . $identifier);
}

Expand Down
22 changes: 11 additions & 11 deletions modules/datastore/src/Form/DashboardForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use Drupal\common\UrlHostTokenResolver;
use Drupal\harvest\HarvestService;
use Drupal\metastore\MetastoreService;
use Drupal\datastore\Service\PostImport;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\datastore\PostImportResultFactory;

/**
* Datastore Import Dashboard form.
Expand Down Expand Up @@ -65,11 +65,11 @@ class DashboardForm extends FormBase {
protected $dateFormatter;

/**
* The PostImport service.
* The PostImportResultFactory service.
*
* @var \Drupal\datastore\Service\PostImport
* @var \Drupal\datastore\PostImportResultFactory
*/
protected $postImport;
protected PostImportResultFactory $postImportResultFactory;

/**
* DashboardController constructor.
Expand All @@ -84,24 +84,24 @@ class DashboardForm extends FormBase {
* Pager manager service.
* @param \Drupal\Core\Datetime\DateFormatter $dateFormatter
* Date formatter service.
* @param \Drupal\datastore\Service\PostImport $post_import
* The post import service.
* @param \Drupal\datastore\PostImportResultFactory $postImportResultFactory
* The PostImportResultFactory service..
*/
public function __construct(
HarvestService $harvestService,
DatasetInfo $datasetInfo,
MetastoreService $metastoreService,
PagerManagerInterface $pagerManager,
DateFormatter $dateFormatter,
PostImport $post_import
PostImportResultFactory $postImportResultFactory
) {
$this->harvest = $harvestService;
$this->datasetInfo = $datasetInfo;
$this->metastore = $metastoreService;
$this->pagerManager = $pagerManager;
$this->dateFormatter = $dateFormatter;
$this->postImport = $post_import;
$this->itemsPerPage = 10;
$this->postImportResultFactory = $postImportResultFactory;
}

/**
Expand All @@ -114,7 +114,7 @@ public static function create(ContainerInterface $container): self {
$container->get('dkan.metastore.service'),
$container->get('pager.manager'),
$container->get('date.formatter'),
$container->get('dkan.datastore.service.post_import'),
$container->get('dkan.datastore.post_import_result_factory'),
);
}

Expand Down Expand Up @@ -461,8 +461,8 @@ protected function buildRevisionRow(array $rev, int $resourceCount, string $harv
*/
protected function buildResourcesRow($dist): array {
if (is_array($dist) && isset($dist['distribution_uuid'])) {

$postImportInfo = $this->postImport->retrieveJobStatus($dist['resource_id'], $dist['resource_version']);
$postImportResult = $this->postImportResultFactory->initializeFromDistribution($dist);
$postImportInfo = $postImportResult->retrieveJobStatus();
$status = $postImportInfo ? $postImportInfo['post_import_status'] : "waiting";
$error = $postImportInfo ? $postImportInfo['post_import_error'] : NULL;

Expand Down
Loading