From 66c22d7817ee861a38c7e9d7d804ec4427038116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Viguier?= Date: Mon, 25 Nov 2024 17:35:08 +0100 Subject: [PATCH] Catch exception on product image generation to avoid process stopping on resize error --- src/Commands/Image/ImageGenerateAbstract.php | 29 +++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Commands/Image/ImageGenerateAbstract.php b/src/Commands/Image/ImageGenerateAbstract.php index 88cf3478..0644a529 100644 --- a/src/Commands/Image/ImageGenerateAbstract.php +++ b/src/Commands/Image/ImageGenerateAbstract.php @@ -302,22 +302,31 @@ protected function regenerateNewImages(string $dir, array $type, bool $productsI if (file_exists($existing_img) && filesize($existing_img)) { foreach ($type as $imageType) { if (!file_exists($dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg')) { - if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height'])) { - $this->errors[] = sprintf( - 'Original image is corrupt %s for product ID %s or bad permission on folder.', - $existing_img, - (int) $imageObj->id_product - ); - } - - if ($generate_hight_dpi_images) { - if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '2x.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) { + try { + if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height'])) { $this->errors[] = sprintf( 'Original image is corrupt %s for product ID %s or bad permission on folder.', $existing_img, (int) $imageObj->id_product ); } + + if ($generate_hight_dpi_images) { + if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '2x.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) { + $this->errors[] = sprintf( + 'Original image is corrupt %s for product ID %s or bad permission on folder.', + $existing_img, + (int) $imageObj->id_product + ); + } + } + } catch (\Exception $e) { + $this->errors[] = sprintf( + 'Unable to resize image %s for product ID %s. error: %s', + $existing_img, + (int) $imageObj->id_product, + $e->getMessage() + ); } } }