diff --git a/modules/harvest/src/Entity/HarvestRunRepository.php b/modules/harvest/src/Entity/HarvestRunRepository.php index b7f7e63f5a..c404ff927a 100644 --- a/modules/harvest/src/Entity/HarvestRunRepository.php +++ b/modules/harvest/src/Entity/HarvestRunRepository.php @@ -22,7 +22,7 @@ class HarvestRunRepository { /** * Entity storage service for the harvest_run entity type. */ - public EntityStorageInterface $runStorage; + protected EntityStorageInterface $runStorage; /** * Database connection service. diff --git a/modules/harvest/src/HarvestPlanListBuilder.php b/modules/harvest/src/HarvestPlanListBuilder.php index 2010845dd2..0c667f7116 100644 --- a/modules/harvest/src/HarvestPlanListBuilder.php +++ b/modules/harvest/src/HarvestPlanListBuilder.php @@ -4,6 +4,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; +use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Link; use Drupal\Core\Url; @@ -28,13 +29,20 @@ class HarvestPlanListBuilder extends EntityListBuilder { */ protected HarvestRunRepository $harvestRunRepository; + /** + * Entity storage service for the harvest_run entity type. + * + * @var \Drupal\Core\Entity\EntityStorageInterface + */ + protected EntityStorageInterface $harvestRunStorage; + /** * {@inheritDoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { $builder = parent::createInstance($container, $entity_type); - $builder->harvestService = $container->get('dkan.harvest.service'); $builder->harvestRunRepository = $container->get('dkan.harvest.storage.harvest_run_repository'); + $builder->harvestRunStorage = $container->get('entity_type.manager')->getStorage('harvest_run'); return $builder; } @@ -70,9 +78,10 @@ public function buildRow(EntityInterface $entity) { $harvest_plan_id = $entity->get('id')->getString(); $run_entity = NULL; - if ($run_id = $this->harvestService->runRepository->getLastHarvestRunId($harvest_plan_id)) { + if ($run_id = $this->harvestRunRepository->getLastHarvestRunId($harvest_plan_id)) { // There is a run identifier, so we should get that info. - $run_entity = $this->harvestRunRepository->runStorage->load($run_id); + /** @var \Drupal\harvest\HarvestRunInterface $run_entity */ + $run_entity = $this->harvestRunStorage->load($run_id); } // Default values for a row if there's no info. @@ -96,7 +105,7 @@ public function buildRow(EntityInterface $entity) { 'data' => $extract_status, 'class' => strtolower($extract_status), ]; - $row['last_run'] = date('m/d/y H:m:s T', $run_id); + $row['last_run'] = date('m/d/y H:m:s T', $run_entity->get('timestamp')->value); $row['dataset_count'] = $interpreter->countProcessed(); } // Don't call parent::buildRow() because we don't want operations (yet). diff --git a/modules/harvest/src/HarvestService.php b/modules/harvest/src/HarvestService.php index a30e3a1a22..e890a2ce57 100644 --- a/modules/harvest/src/HarvestService.php +++ b/modules/harvest/src/HarvestService.php @@ -207,7 +207,7 @@ public function runHarvest($plan_id) { $result['status']['orphan_ids'] = $this->getOrphanIdsFromResult($plan_id, $result['status']['extracted_items_ids']); $this->processOrphanIds($result['status']['orphan_ids']); - + // For legacy reasons, the identifier is the timestamp. $result['identifier'] = $timestamp; $this->runRepository->storeRun($result, $plan_id, $timestamp); diff --git a/modules/harvest/tests/src/Kernel/HarvestPlanListBuilderTest.php b/modules/harvest/tests/src/Kernel/HarvestPlanListBuilderTest.php index d2cddc790d..e3a96e30be 100644 --- a/modules/harvest/tests/src/Kernel/HarvestPlanListBuilderTest.php +++ b/modules/harvest/tests/src/Kernel/HarvestPlanListBuilderTest.php @@ -101,7 +101,6 @@ public function testGoodHarvestRun() { $this->registerHarvestPlan($harvest_service, $plan_id); $run_result = $harvest_service->runHarvest($plan_id); $this->assertEquals('SUCCESS', $run_result['status']['extract'] ?? 'not_a_successful_run'); - $run_id = $harvest_service->runRepository->getLastHarvestRunId($plan_id); $response = $list_builder->render(); @@ -109,7 +108,7 @@ public function testGoodHarvestRun() { $strings = array_merge(self::HARVEST_HEADERS, [ 'harvest_link', 'SUCCESS', - json_encode(date('m/d/y H:m:s T', $run_id)), + json_encode(date('m/d/y H:m:s T', $run_result['identifier'])), '2', ]); foreach ($strings as $string) {