Skip to content

Commit

Permalink
Add proper injection of HarvestRunRepository to HarvestPlanListBuilder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Wirt authored and Steve Wirt committed Dec 13, 2024
1 parent 1a382f6 commit f6a4484
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modules/harvest/src/Entity/HarvestRunRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HarvestRunRepository {
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
public EntityStorageInterface $runStorage;
protected EntityStorageInterface $runStorage;

/**
* Database connection service.
Expand Down
22 changes: 12 additions & 10 deletions modules/harvest/src/HarvestPlanListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,26 +20,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;
}

Expand Down Expand Up @@ -74,9 +75,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.
Expand All @@ -100,7 +102,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).
Expand Down
2 changes: 1 addition & 1 deletion modules/harvest/src/HarvestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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', $response['identifier'])),
'2',
]);
foreach ($strings as $string) {
Expand Down

0 comments on commit f6a4484

Please sign in to comment.