From f28417e59f199807be2e13f0bc5462068735122b Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Tue, 2 Dec 2025 15:10:34 +0100 Subject: [PATCH 1/7] POC: allow tu pull ozu data from inside worker --- src/Console/FetchDataFromOzu.php | 32 ++++++++++++++++++-------------- src/OzuServiceProvider.php | 6 +++--- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Console/FetchDataFromOzu.php b/src/Console/FetchDataFromOzu.php index 1d8fe92..9144640 100644 --- a/src/Console/FetchDataFromOzu.php +++ b/src/Console/FetchDataFromOzu.php @@ -12,7 +12,7 @@ class FetchDataFromOzu extends Command { - protected $signature = 'ozu:fetch-ozu-data'; + protected $signature = 'ozu:fetch-ozu-data {--force : Do not ask for confirmation} {--withoutAssets : Do not download assets}'; protected $aliases = ['ozu:fetch-data', 'ozu:pull']; @@ -26,14 +26,16 @@ class FetchDataFromOzu extends Command public function handle(Client $ozuClient): int { - - $this->warn('⚠️ This action will erase your local database and assets.'); - - if (!confirm( - 'Are you sure you want to continue? This cannot be undone.', - default: false, - )) { - return self::SUCCESS; + $this->newLine(2); + $this->warn('⚠️ This action will erase your local database and assets.'); + + if (!$this->option('force')) { + if (!confirm( + 'Are you sure you want to continue? This cannot be undone.', + default: false, + )) { + return self::SUCCESS; + } } $this->initializePaths($ozuClient); @@ -46,12 +48,14 @@ public function handle(Client $ozuClient): int return self::FAILURE; } - if (!$this->downloadAssets($ozuClient)) { - return self::FAILURE; - } + if (!$this->option('withoutAssets')) { + if (!$this->downloadAssets($ozuClient)) { + return self::FAILURE; + } - if (!$this->extractAssets()) { - return self::FAILURE; + if (!$this->extractAssets()) { + return self::FAILURE; + } } $this->cleanTemporaryFiles(); diff --git a/src/OzuServiceProvider.php b/src/OzuServiceProvider.php index 807fffc..9f323e9 100644 --- a/src/OzuServiceProvider.php +++ b/src/OzuServiceProvider.php @@ -50,16 +50,16 @@ public function register() $this->app->bind(Paginator::class, StaticPaginator::class); $this->app->bind(LengthAwarePaginator::class, StaticLengthAwarePaginator::class); $this->app->bind(Thumbnail::class, function ($app) { - if (!$app->environment('production') || !config('ozu-client.cdn_url')) { + if (!config('ozu-client.cdn_url')) { + // if no CDN URL is set, use the local storage return $app->make(LocalThumbnail::class); } - // Have to rely on the URL to determine the CDN provider for now, - // because we are limited to 10 params for the deployment script :/ if (str(config('ozu-client.cdn_url'))->contains('kxcdn.com')) { return $app->make(KeyCdnThumbnail::class); } + // ImageKit CDN also serves as a fallback return $app->make(ImageKitThumbnail::class); }); } From f25d14826889c8ecf1ff7090e526189cbd2ad697 Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Tue, 2 Dec 2025 16:13:14 +0100 Subject: [PATCH 2/7] Smart use of imagick or Gd image driver --- src/Support/Thumbnails/LocalThumbnail.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Support/Thumbnails/LocalThumbnail.php b/src/Support/Thumbnails/LocalThumbnail.php index cb6d8f6..9c7f9a5 100644 --- a/src/Support/Thumbnails/LocalThumbnail.php +++ b/src/Support/Thumbnails/LocalThumbnail.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Filesystem\FilesystemManager; use Illuminate\Support\Str; +use Intervention\Image\Drivers\Gd\Driver as GdDriver; use Intervention\Image\Drivers\Imagick\Driver; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\ImageManager; @@ -27,7 +28,13 @@ class LocalThumbnail extends Thumbnail public function __construct() { - $this->imageManager = new ImageManager(new Driver()); + $hasGd = extension_loaded('gd'); + $hasImagick = extension_loaded('imagick'); + if (!$hasGd && !$hasImagick) { + throw new \RuntimeException('Neither GD nor Imagick extension is installed. One of them is required to generate thumbnails.'); + } + + $this->imageManager = new ImageManager($hasImagick ? new Driver() : new GdDriver()); $this->storage = app(FilesystemManager::class); } From 43bced9c0a0b0603b9af07fd7b77cbf2553de30b Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Tue, 2 Dec 2025 16:19:27 +0100 Subject: [PATCH 3/7] Fix smart select of image driver --- src/Support/Thumbnails/LocalThumbnail.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Support/Thumbnails/LocalThumbnail.php b/src/Support/Thumbnails/LocalThumbnail.php index 9c7f9a5..a75dac6 100644 --- a/src/Support/Thumbnails/LocalThumbnail.php +++ b/src/Support/Thumbnails/LocalThumbnail.php @@ -6,7 +6,7 @@ use Illuminate\Filesystem\FilesystemManager; use Illuminate\Support\Str; use Intervention\Image\Drivers\Gd\Driver as GdDriver; -use Intervention\Image\Drivers\Imagick\Driver; +use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\ImageManager; @@ -28,13 +28,13 @@ class LocalThumbnail extends Thumbnail public function __construct() { - $hasGd = extension_loaded('gd'); - $hasImagick = extension_loaded('imagick'); + $hasGd = (!extension_loaded('gd') || !function_exists('gd_info')); + $hasImagick = (!extension_loaded('imagick') || !class_exists('Imagick')); if (!$hasGd && !$hasImagick) { throw new \RuntimeException('Neither GD nor Imagick extension is installed. One of them is required to generate thumbnails.'); } - $this->imageManager = new ImageManager($hasImagick ? new Driver() : new GdDriver()); + $this->imageManager = new ImageManager($hasImagick ? new ImagickDriver() : new GdDriver()); $this->storage = app(FilesystemManager::class); } From 9f6d4c5649cce74d48ce2682e5914cfea23ded9d Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Tue, 2 Dec 2025 16:23:17 +0100 Subject: [PATCH 4/7] Fix smart select of image driver --- src/Support/Thumbnails/LocalThumbnail.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Support/Thumbnails/LocalThumbnail.php b/src/Support/Thumbnails/LocalThumbnail.php index a75dac6..eb8db77 100644 --- a/src/Support/Thumbnails/LocalThumbnail.php +++ b/src/Support/Thumbnails/LocalThumbnail.php @@ -28,8 +28,8 @@ class LocalThumbnail extends Thumbnail public function __construct() { - $hasGd = (!extension_loaded('gd') || !function_exists('gd_info')); - $hasImagick = (!extension_loaded('imagick') || !class_exists('Imagick')); + $hasGd = (extension_loaded('gd') && function_exists('gd_info')); + $hasImagick = (extension_loaded('imagick') && class_exists('Imagick')); if (!$hasGd && !$hasImagick) { throw new \RuntimeException('Neither GD nor Imagick extension is installed. One of them is required to generate thumbnails.'); } From da0c8c35966c1f69e3d3902d4718fc21e3823430 Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Tue, 2 Dec 2025 16:35:43 +0100 Subject: [PATCH 5/7] Fix smart select of image driver --- src/Support/Thumbnails/LocalThumbnail.php | 44 ++++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/Support/Thumbnails/LocalThumbnail.php b/src/Support/Thumbnails/LocalThumbnail.php index eb8db77..488cecc 100644 --- a/src/Support/Thumbnails/LocalThumbnail.php +++ b/src/Support/Thumbnails/LocalThumbnail.php @@ -4,6 +4,7 @@ use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Filesystem\FilesystemManager; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; use Intervention\Image\Drivers\Gd\Driver as GdDriver; use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; @@ -28,13 +29,46 @@ class LocalThumbnail extends Thumbnail public function __construct() { - $hasGd = (extension_loaded('gd') && function_exists('gd_info')); - $hasImagick = (extension_loaded('imagick') && class_exists('Imagick')); - if (!$hasGd && !$hasImagick) { - throw new \RuntimeException('Neither GD nor Imagick extension is installed. One of them is required to generate thumbnails.'); + $hasGd = extension_loaded('gd') && function_exists('gd_info'); + $hasImagickExt = extension_loaded('imagick') && class_exists(\Imagick::class); + + $driver = null; + + // Try to use Imagick driver first + if ($hasImagickExt && class_exists(ImagickDriver::class)) { + try { + $driver = new ImagickDriver(); + } catch (\Throwable $e) { + // log pour diagnostic — très utile en prod + Log::warning('ImagickDriver instantiation failed', [ + 'message' => $e->getMessage(), + 'trace' => $e->getTraceAsString(), + 'sapi' => php_sapi_name(), + 'php_version' => phpversion(), + ]); + $driver = null; + } + } + + // 2) Fallback sur GD si Imagick non disponible ou instanciation échoue + if ($driver === null && $hasGd && class_exists(GdDriver::class)) { + try { + $driver = new GdDriver(); + } catch (\Throwable $e) { + Log::warning('GdDriver instantiation failed', [ + 'message' => $e->getMessage(), + 'sapi' => php_sapi_name(), + ]); + $driver = null; + } + } + + // 3) Si toujours rien -> exception claire + if ($driver === null) { + throw new \RuntimeException('Neither GD nor Imagick driver can be instantiated. Check PHP extensions (gd, imagick) and ImageMagick binaries for the SAPI running this code.'); } - $this->imageManager = new ImageManager($hasImagick ? new ImagickDriver() : new GdDriver()); + $this->imageManager = new ImageManager($driver); $this->storage = app(FilesystemManager::class); } From f6fb3b27ec8d1967873f37336db14a19a6c89b60 Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Tue, 2 Dec 2025 16:41:05 +0100 Subject: [PATCH 6/7] Remove smart select of image driver --- src/Support/Thumbnails/LocalThumbnail.php | 44 +---------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/src/Support/Thumbnails/LocalThumbnail.php b/src/Support/Thumbnails/LocalThumbnail.php index 488cecc..fbade9c 100644 --- a/src/Support/Thumbnails/LocalThumbnail.php +++ b/src/Support/Thumbnails/LocalThumbnail.php @@ -4,10 +4,7 @@ use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Filesystem\FilesystemManager; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; -use Intervention\Image\Drivers\Gd\Driver as GdDriver; -use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\ImageManager; @@ -29,46 +26,7 @@ class LocalThumbnail extends Thumbnail public function __construct() { - $hasGd = extension_loaded('gd') && function_exists('gd_info'); - $hasImagickExt = extension_loaded('imagick') && class_exists(\Imagick::class); - - $driver = null; - - // Try to use Imagick driver first - if ($hasImagickExt && class_exists(ImagickDriver::class)) { - try { - $driver = new ImagickDriver(); - } catch (\Throwable $e) { - // log pour diagnostic — très utile en prod - Log::warning('ImagickDriver instantiation failed', [ - 'message' => $e->getMessage(), - 'trace' => $e->getTraceAsString(), - 'sapi' => php_sapi_name(), - 'php_version' => phpversion(), - ]); - $driver = null; - } - } - - // 2) Fallback sur GD si Imagick non disponible ou instanciation échoue - if ($driver === null && $hasGd && class_exists(GdDriver::class)) { - try { - $driver = new GdDriver(); - } catch (\Throwable $e) { - Log::warning('GdDriver instantiation failed', [ - 'message' => $e->getMessage(), - 'sapi' => php_sapi_name(), - ]); - $driver = null; - } - } - - // 3) Si toujours rien -> exception claire - if ($driver === null) { - throw new \RuntimeException('Neither GD nor Imagick driver can be instantiated. Check PHP extensions (gd, imagick) and ImageMagick binaries for the SAPI running this code.'); - } - - $this->imageManager = new ImageManager($driver); + $this->imageManager = new ImageManager(Driver); $this->storage = app(FilesystemManager::class); } From 1ea357a34f7e67efb55359e3f11dfeccfa9808da Mon Sep 17 00:00:00 2001 From: PatrickePatate Date: Tue, 2 Dec 2025 16:41:22 +0100 Subject: [PATCH 7/7] Remove smart select of image driver --- src/Support/Thumbnails/LocalThumbnail.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Support/Thumbnails/LocalThumbnail.php b/src/Support/Thumbnails/LocalThumbnail.php index fbade9c..7dc9edf 100644 --- a/src/Support/Thumbnails/LocalThumbnail.php +++ b/src/Support/Thumbnails/LocalThumbnail.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Filesystem\FilesystemManager; use Illuminate\Support\Str; +use Intervention\Image\Drivers\Gd\Driver; use Intervention\Image\Exceptions\DecoderException; use Intervention\Image\ImageManager; @@ -26,7 +27,7 @@ class LocalThumbnail extends Thumbnail public function __construct() { - $this->imageManager = new ImageManager(Driver); + $this->imageManager = new ImageManager(new Driver()); $this->storage = app(FilesystemManager::class); }