Skip to content

Commit

Permalink
Updated Post Import Result Factory class method name and arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
kaise-lafrai committed Jan 16, 2025
1 parent 6102c95 commit 596af6b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modules/datastore/src/Drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ 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);
}
$post_import_result = $this->postImportResultFactory->InitializeFromDatasetInfo(['resource_id' => $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
2 changes: 1 addition & 1 deletion modules/datastore/src/Form/DashboardForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ protected function buildRevisionRow(array $rev, int $resourceCount, string $harv
*/
protected function buildResourcesRow($dist): array {
if (is_array($dist) && isset($dist['distribution_uuid'])) {
$postImportResult = $this->postImportResultFactory->initializeFromDatasetInfo($dist);
$postImportResult = $this->postImportResultFactory->initializeFromDistribution($dist);
$postImportInfo = $postImportResult->retrieveJobStatus();
$status = $postImportInfo ? $postImportInfo['post_import_status'] : "waiting";
$error = $postImportInfo ? $postImportInfo['post_import_error'] : NULL;
Expand Down
15 changes: 8 additions & 7 deletions modules/datastore/src/PostImportResultFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,20 @@ public function initializeFromResource($status, $message, DataResource $resource
/**
* Creates a PostImportResult instance.
*
* Passes the dataset info when initialized.
* Passes the distribution when initialized.
*
* @param array $datasetInfo
* The dataset info.
* @param array $distribution
* The distribution.
*
* @return \Drupal\datastore\PostImportResult
* The PostImportResult object.
*/
public function initializeFromDatasetInfo(array $datasetInfo): PostImportResult {
$resource = $this->resourceMapper->get($datasetInfo['resource_id']);
public function initializeFromDistribution(array $distribution): PostImportResult {
// Retrieve the data resource object.
$resource = $this->resourceMapper->get($distribution['resource_id']);
return new PostImportResult(
'',
'',
NULL,
NULL,
$resource,
$this->connection,
);
Expand Down
8 changes: 4 additions & 4 deletions modules/datastore/tests/src/Unit/Form/DashboardFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function testBuildTableRowsWithHarvestIdFilter() {
$container = $this->buildContainerChain()
->add(RequestStack::class, 'getCurrentRequest', new Request(['harvest_id' => 'dataset-1']))
->add(DatasetInfo::class, 'gather', ['latest_revision' => $info + ['distributions' => [$distribution]]])
->add(PostImportResultFactory::class, 'initializeFromDatasetInfo', $postImportResultMock)
->add(PostImportResultFactory::class, 'initializeFromDistribution', $postImportResultMock)
->getMock();
\Drupal::setContainer($container);
$form = DashboardForm::create($container)->buildForm([], new FormState());
Expand Down Expand Up @@ -194,7 +194,7 @@ public function testBuildTableRowsWithUuidFilter() {
$container = $this->buildContainerChain()
->add(RequestStack::class, 'getCurrentRequest', new Request(['uuid' => 'test']))
->add(DatasetInfo::class, 'gather', ['latest_revision' => $info + ['distributions' => [$distribution]]])
->add(PostImportResultFactory::class, 'initializeFromDatasetInfo', $postImportResultMock)
->add(PostImportResultFactory::class, 'initializeFromDistribution', $postImportResultMock)
->getMock();
\Drupal::setContainer($container);
$form = DashboardForm::create($container)->buildForm([], new FormState());
Expand Down Expand Up @@ -285,7 +285,7 @@ public function testBuildTableRowsWithAllDatasets() {
->add(MetastoreService::class, 'count', 2)
->add(MetastoreService::class, 'getIdentifiers', [$datasetInfo['latest_revision']['uuid'], $nonHarvestDatasetInfo['latest_revision']['uuid']])
->add(DatasetInfo::class, 'gather', $datasetInfoOptions)
->add(PostImportResultFactory::class, 'initializeFromDatasetInfo', $postImportResultMock);
->add(PostImportResultFactory::class, 'initializeFromDistribution', $postImportResultMock);

\Drupal::setContainer($container->getMock());
$form = DashboardForm::create($container->getMock())->buildForm([], new FormState());
Expand Down Expand Up @@ -392,7 +392,7 @@ public function testBuildTableRowsDatasetMultipleDistribution() {
->add(MetastoreService::class, 'count', 1)
->add(MetastoreService::class, 'getIdentifiers', [$datasetInfo['latest_revision']['uuid']])
->add(DatasetInfo::class, 'gather', $datasetInfo)
->add(PostImportResultFactory::class, 'initializeFromDatasetInfo', $postImportResultMock)
->add(PostImportResultFactory::class, 'initializeFromDistribution', $postImportResultMock)
->getMock();
\Drupal::setContainer($container);

Expand Down

0 comments on commit 596af6b

Please sign in to comment.