Skip to content

Commit

Permalink
Allow null on getHarvestRunResult (#4182)
Browse files Browse the repository at this point in the history
  • Loading branch information
janette authored May 10, 2024
1 parent 94d9297 commit 75eb012
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/harvest/src/Entity/HarvestRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public function toResult(): array {
$result['status']['extracted_items_ids'][] = $field->getString();
}

$result['status']['orphan_ids'] = [];
foreach ($this->get('orphan_uuid') as $field) {
$result['status']['orphan_ids'][] = $field->getString();
}
Expand Down
7 changes: 6 additions & 1 deletion modules/harvest/src/HarvestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ public function getHarvestRunInfo(string $plan_id, string $run_id): bool|string
* Array of status info from the run.
*/
public function getHarvestRunResult(string $plan_id, string $run_id): array {
return $this->runRepository->loadEntity($plan_id, $run_id)->toResult();
if ($entity = $this->runRepository->loadEntity($plan_id, $run_id)) {
return $entity->toResult();
}
else {
return [];
}
}

/**
Expand Down
32 changes: 32 additions & 0 deletions modules/harvest/tests/src/Kernel/HarvestServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,36 @@ public function testPlanWithChangingDataset() {
);
}

/**
* @covers ::getHarvestRunResult
*/
public function testGetHarvestRunResult() {
// There should be no harvest runs at the beginning of this test method, so
// getHarvestRunResult should return an empty array.
/** @var \Drupal\harvest\HarvestService $harvest_service */
$harvest_service = $this->container->get('dkan.harvest.service');
$this->assertEquals([], $harvest_service->getHarvestRunResult('any_plan', 'any_id'));

// Register a harvest and run it.
$plan_identifier = 'test_plan';
$plan = (object) [
'identifier' => $plan_identifier,
'extract' => (object) [
'type' => DataJson::class,
'uri' => 'file://' . realpath(__DIR__ . '/../../files/data.json'),
],
'transforms' => [],
'load' => (object) [
'type' => Simple::class,
],
];
$this->assertEquals($plan_identifier, $harvest_service->registerHarvest($plan));

$run_result = $harvest_service->runHarvest($plan_identifier);
$this->assertNotEmpty($run_id = $run_result['identifier']);

// Compare the reloaded results to the ones from the original run.
$this->assertEquals($run_result, $harvest_service->getHarvestRunResult($plan_identifier, $run_id));
}

}

0 comments on commit 75eb012

Please sign in to comment.