Skip to content

Commit

Permalink
avoid crash and die (#2690)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Nov 15, 2024
1 parent 14514f4 commit c83b5c9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
14 changes: 11 additions & 3 deletions app/Console/Commands/ImageProcessing/GenerateThumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Contracts\Exceptions\LycheeException;
use App\Contracts\Models\SizeVariantFactory;
use App\Enum\SizeVariantType;
use App\Exceptions\MediaFileOperationException;
use App\Exceptions\UnexpectedException;
use App\Models\Photo;
use Illuminate\Console\Command;
Expand Down Expand Up @@ -101,12 +102,19 @@ public function handle(): int
$sizeVariantFactory = resolve(SizeVariantFactory::class);
/** @var Photo $photo */
foreach ($photos as $photo) {
$sizeVariantFactory->init($photo);
$sizeVariant = $sizeVariantFactory->createSizeVariantCond($sizeVariantType);
$sizeVariant = null;

try {
$sizeVariantFactory->init($photo);
$sizeVariant = $sizeVariantFactory->createSizeVariantCond($sizeVariantType);
} catch (MediaFileOperationException $e) {
$sizeVariant = null;
}

if ($sizeVariant !== null) {
$this->line(' ' . $sizeVariantName . ' (' . $sizeVariant->width . 'x' . $sizeVariant->height . ') for ' . $photo->title . ' created.');
} else {
$this->line(' Did not create ' . $sizeVariantName . ' for ' . $photo->title . '.');
$this->line(' Did not create ' . $sizeVariantName . ' for ' . $photo->id . ' .');
}
$bar->advance();
}
Expand Down
23 changes: 14 additions & 9 deletions app/Http/Controllers/Admin/Maintenance/GenSizeVariants.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Contracts\Models\SizeVariantFactory;
use App\Enum\SizeVariantType;
use App\Exceptions\MediaFileOperationException;
use App\Http\Requests\Maintenance\CreateThumbsRequest;
use App\Image\PlaceholderEncoder;
use App\Image\SizeVariantDimensionHelpers;
Expand Down Expand Up @@ -41,15 +42,19 @@ public function do(CreateThumbsRequest $request, SizeVariantFactory $sizeVariant
foreach ($photos as $photo) {
// @codeCoverageIgnoreStart
$sizeVariantFactory->init($photo);
$sizeVariant = $sizeVariantFactory->createSizeVariantCond($request->kind());
if ($request->kind() === SizeVariantType::PLACEHOLDER && $sizeVariant !== null) {
$placeholderEncoder->do($sizeVariant);
}
if ($sizeVariant !== null) {
$generated++;
Log::notice($request->kind()->value . ' (' . $sizeVariant->width . 'x' . $sizeVariant->height . ') for ' . $photo->title . ' created.');
} else {
Log::error('Did not create ' . $request->kind()->value . ' for ' . $photo->title . '.');
try {
$sizeVariant = $sizeVariantFactory->createSizeVariantCond($request->kind());
if ($request->kind() === SizeVariantType::PLACEHOLDER && $sizeVariant !== null) {
$placeholderEncoder->do($sizeVariant);
}
if ($sizeVariant !== null) {
$generated++;
Log::notice($request->kind()->value . ' (' . $sizeVariant->width . 'x' . $sizeVariant->height . ') for ' . $photo->title . ' created.');
} else {
Log::error('Did not create ' . $request->kind()->value . ' for ' . $photo->title . '.');
}
} catch (MediaFileOperationException $e) {
Log::error('Failed to create ' . $request->kind()->value . ' for photo id ' . $photo->id . '');
}
// @codeCoverageIgnoreEnd
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function do(MaintenanceRequest $request): void
} else {
$generated++;
}
} catch (UnableToRetrieveMetadata $e) {
} catch (UnableToRetrieveMetadata) {
Log::error($variant->id . ' : Failed to get filesize for ' . $variantFile->getRelativePath() . '.');
}
} else {
Expand Down

0 comments on commit c83b5c9

Please sign in to comment.