From 5cb30556ee0b4f02eb52c472e67b4d1ac1025c23 Mon Sep 17 00:00:00 2001 From: Steve Wirt Date: Thu, 12 Dec 2024 17:52:27 -0500 Subject: [PATCH] Add proper injection of HarvestRunRepository to HarvestPlanListBuilder. --- .../src/Entity/HarvestRunRepository.php | 2 +- .../harvest/src/HarvestPlanListBuilder.php | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/modules/harvest/src/Entity/HarvestRunRepository.php b/modules/harvest/src/Entity/HarvestRunRepository.php index d5765c2776..165ea349f5 100644 --- a/modules/harvest/src/Entity/HarvestRunRepository.php +++ b/modules/harvest/src/Entity/HarvestRunRepository.php @@ -24,7 +24,7 @@ class HarvestRunRepository { * * @var \Drupal\Core\Entity\EntityStorageInterface */ - public EntityStorageInterface $runStorage; + protected EntityStorageInterface $runStorage; /** * Database connection service. diff --git a/modules/harvest/src/HarvestPlanListBuilder.php b/modules/harvest/src/HarvestPlanListBuilder.php index b3d6a8c44b..de9a14733c 100644 --- a/modules/harvest/src/HarvestPlanListBuilder.php +++ b/modules/harvest/src/HarvestPlanListBuilder.php @@ -4,9 +4,11 @@ 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; +use Drupal\harvest\HarvestRunInterface; use Drupal\harvest\Entity\HarvestRunRepository; use Harvest\ResultInterpreter; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -19,26 +21,26 @@ class HarvestPlanListBuilder extends EntityListBuilder { /** - * Harvest service. + * Harvest run repository service. * - * @var \Drupal\harvest\HarvestService + * @var \Drupal\harvest\Entity\HarvestRunRepository */ - protected HarvestService $harvestService; + protected HarvestRunRepository $harvestRunRepository; /** - * Harvest run repository service. + * Entity storage service for the harvest_run entity type. * - * @var \Drupal\harvest\Entity\HarvestRunRepository + * @var \Drupal\Core\Entity\EntityStorageInterface */ - protected HarvestRunRepository $harvestRunRepository; + 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; } @@ -74,9 +76,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. @@ -100,7 +103,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).