Skip to content

Commit

Permalink
Merge pull request #882 from SlovakNationalGallery/feature/WEBUMENIA-…
Browse files Browse the repository at this point in the history
…1994

[import] skip unmodified jpg images
  • Loading branch information
rastislav-chynoransky authored Aug 16, 2023
2 parents 93042f5 + f233bac commit b34e867
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 11 additions & 0 deletions app/ImportRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
Expand Down Expand Up @@ -56,4 +57,14 @@ public function readStream(SplFileInfo $file)
{
return $this->import->readStream($file);
}

public function lastModified(SplFileInfo $file)
{
return $this->import->lastModified($file);
}

public function scopeCompleted(Builder $query)
{
$query->where('status', self::STATUS_COMPLETED);
}
}
15 changes: 12 additions & 3 deletions app/Importers/AbstractImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Item;
use App\Matchers\AuthorityMatcher;
use App\Repositories\IFileRepository;
use Carbon\Carbon;
use DateTime;
use Illuminate\Contracts\Translation\Translator;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -138,9 +139,17 @@ protected function importSingle(array $record, ImportRecord $import_record): ?It

$jpgFile = $this->getJpgFile($import_record, $image_filename_format);
if ($jpgFile) {
$stream = $import_record->readStream($jpgFile);
$item->saveImage($stream);
$import_record->imported_images++;
$lastModified = $import_record->lastModified($jpgFile);
$lastStartedAt = $import_record->import
->records()
->completed()
->max('started_at');

if (Carbon::createFromTimestamp($lastModified) > Carbon::make($lastStartedAt)) {
$stream = $import_record->readStream($jpgFile);
$item->saveImage($stream);
$import_record->imported_images++;
}
}

$this->getJp2Files($import_record, $image_filename_format)
Expand Down

0 comments on commit b34e867

Please sign in to comment.