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

Catch exception on product image generation #265

Merged
merged 7 commits into from
Nov 27, 2024
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
if: github.event_name == 'push'
steps:
- name: Download artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: ${{ github.event.repository.name }}
Expand Down
29 changes: 19 additions & 10 deletions src/Commands/Image/ImageGenerateAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
}
Expand Down
Loading