AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

PrepareBannerPhoto.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Jobs;
  3. use App\Models\StoreImage;
  4. use App\StorePlan\BannerPhoto;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Queue\Queueable;
  7. use Illuminate\Support\Facades\Log;
  8. use Illuminate\Support\Facades\Storage;
  9. use Throwable;
  10. /**
  11. * Runs after a banner photo is uploaded: enlarges small photos, shrinks huge ones, and saves WebP
  12. * (see BannerPhoto). The design points to the photo by its id, so it picks up the new file by itself.
  13. * If anything goes wrong, the photo as uploaded stays in use.
  14. */
  15. class PrepareBannerPhoto implements ShouldQueue
  16. {
  17. use Queueable;
  18. public int $tries = 2;
  19. public int $timeout = 120;
  20. /** The merchant may delete the photo before this runs. Then there is nothing to do. */
  21. public bool $deleteWhenMissingModels = true;
  22. public function __construct(public StoreImage $image) {}
  23. public function handle(BannerPhoto $banner): void
  24. {
  25. $original = $this->image->path;
  26. if (str_ends_with($original, '.webp') && str_starts_with(basename($original), 'banner-')) {
  27. return; // Already done.
  28. }
  29. try {
  30. $prepared = $banner->prepare($original);
  31. } catch (Throwable $error) {
  32. Log::warning('Banner photo could not be prepared; the uploaded photo stays in use.', [
  33. 'store_image_id' => $this->image->id,
  34. 'error' => $error->getMessage(),
  35. ]);
  36. return;
  37. }
  38. $this->image->update(['path' => $prepared]);
  39. Storage::disk('public')->delete($original);
  40. }
  41. }