Skip to content

Commit

Permalink
Merge pull request #1016 from SlovakNationalGallery/WEBUMENIA-2082
Browse files Browse the repository at this point in the history
[harvest] catch exception of processed record
  • Loading branch information
rastislav-chynoransky authored Jun 18, 2024
2 parents a667dc9 + 75a1ff4 commit 5247032
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 48 deletions.
33 changes: 18 additions & 15 deletions app/Harvest/Harvesters/AbstractHarvester.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,27 @@ public function harvestRecord(SpiceHarvesterRecord $record, Progress $progress,
$row = $this->repository->getRow($record);
}

if ($record->trashed() || $this->isExcluded($row)) {
$progress->incrementSkipped();
return null;
}
$this->processRecord($record, $progress, $row);
}, $progress);
}

if ($this->isForDeletion($row)) {
$this->deleteRecord($record);
$progress->incrementDeleted();
return null;
}
protected function processRecord(SpiceHarvesterRecord $record, Progress $progress, array $row) {
if ($record->trashed() || $this->isExcluded($row)) {
$progress->incrementSkipped();
return null;
}

$this->importer->import($row, $progress);
if ($this->isForDeletion($row)) {
$this->deleteRecord($record);
$progress->incrementDeleted();
return null;
}

if (Arr::get($row, 'datestamp.0')) {
$record->datestamp = Carbon::parse(Arr::get($row, 'datestamp.0'));
}

}, $progress);
$this->importer->import($row, $progress);

if (Arr::get($row, 'datestamp.0')) {
$record->datestamp = Carbon::parse(Arr::get($row, 'datestamp.0'));
}
}

/**
Expand Down
13 changes: 2 additions & 11 deletions app/Harvest/Harvesters/AuthorityHarvester.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@

use App\Harvest\Importers\AuthorityImporter;
use App\Harvest\Repositories\AuthorityRepository;
use App\Harvest\Progress;
use App\SpiceHarvesterRecord;

class AuthorityHarvester extends AbstractHarvester
{
public function __construct(AuthorityRepository $repository, AuthorityImporter $importer) {
public function __construct(AuthorityRepository $repository, AuthorityImporter $importer)
{
parent::__construct($repository, $importer);
}

public function harvestRecord(SpiceHarvesterRecord $record, Progress $progress, array $row = null) {
if ($row === null) {
$row = $this->repository->getRow($record);
}

parent::harvestRecord($record, $progress, $row);
}
}
25 changes: 3 additions & 22 deletions app/Harvest/Harvesters/ItemHarvester.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,20 @@
use App\Harvest\Importers\ItemImporter;
use App\Harvest\Repositories\ItemRepository;
use App\Harvest\Progress;
use App\Item;
use App\SpiceHarvesterRecord;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Monolog\Logger;

class ItemHarvester extends AbstractHarvester
{
/** @var array */
protected $excludePrefix = ['x'];

/** @var Logger */
protected $logger;

public function __construct(ItemRepository $repository, ItemImporter $importer) {
parent::__construct($repository, $importer);
$this->logger = new Logger('oai_harvest');
}

public function harvestRecord(SpiceHarvesterRecord $record, Progress $progress, array $row = null) {
if ($row === null) {
$row = $this->repository->getRow($record);
}

protected function processRecord(SpiceHarvesterRecord $record, Progress $progress, array $row) {
// @todo responsibility of repository?
$iipimgUrls = $this->fetchItemImageIipimgUrls($row);

Expand All @@ -45,19 +35,10 @@ public function harvestRecord(SpiceHarvesterRecord $record, Progress $progress,
];
}

parent::harvestRecord($record, $progress, $row);
parent::processRecord($record, $progress, $row);

if ($record->item && $record->item->img_url) {
$this->trySaveImage($record->item);
}
}

protected function trySaveImage(Item $item) {
try {
$item->saveImage($item->img_url);
} catch (\Exception $e) {
$error = sprintf('%s: %s', $item->img_url, $e->getMessage());
$this->logger->error($error);
$record->item->saveImage($record->item->img_url);
}
}

Expand Down

0 comments on commit 5247032

Please sign in to comment.