Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crash and die when generating smaller size variants #2690

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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