[-] BO : image regeneration now gives a better reporting and crash less #PSCFV-5519
This commit is contained in:
@@ -119,7 +119,7 @@ class ImageManagerCore
|
|||||||
*/
|
*/
|
||||||
public static function resize($src_file, $dst_file, $dst_width = null, $dst_height = null, $file_type = 'jpg', $force_type = false)
|
public static function resize($src_file, $dst_file, $dst_width = null, $dst_height = null, $file_type = 'jpg', $force_type = false)
|
||||||
{
|
{
|
||||||
if (!file_exists($src_file))
|
if (!file_exists($src_file) || !filesize($src_file))
|
||||||
return false;
|
return false;
|
||||||
list($src_width, $src_height, $type) = getimagesize($src_file);
|
list($src_width, $src_height, $type) = getimagesize($src_file);
|
||||||
|
|
||||||
|
|||||||
@@ -343,16 +343,18 @@ class AdminImagesControllerCore extends AdminController
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->errors[] = Tools::displayError('You do not have permission to edit here.');
|
$this->errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||||
}elseif (Tools::getValue('submitMoveImages'.$this->table))
|
}
|
||||||
|
elseif (Tools::getValue('submitMoveImages'.$this->table))
|
||||||
{
|
{
|
||||||
if ($this->tabAccess['edit'] === '1')
|
if ($this->tabAccess['edit'] === '1')
|
||||||
{
|
{
|
||||||
if ($this->_moveImagesToNewFileSystem())
|
if ($this->_moveImagesToNewFileSystem())
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&conf=25'.'&token='.$this->token);
|
Tools::redirectAdmin(self::$currentIndex.'&conf=25'.'&token='.$this->token);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->errors[] = Tools::displayError('You do not have permission to edit here.');
|
$this->errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||||
}elseif (Tools::getValue('submitImagePreferences'))
|
}
|
||||||
|
elseif (Tools::getValue('submitImagePreferences'))
|
||||||
{
|
{
|
||||||
if ($this->tabAccess['edit'] === '1')
|
if ($this->tabAccess['edit'] === '1')
|
||||||
{
|
{
|
||||||
@@ -459,11 +461,11 @@ class AdminImagesControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
if (!is_dir($dir))
|
if (!is_dir($dir))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$errors = false;
|
$errors = false;
|
||||||
$toRegen = scandir($dir);
|
|
||||||
if (!$productsImages)
|
if (!$productsImages)
|
||||||
{
|
{
|
||||||
foreach ($toRegen as $image)
|
foreach (scandir($dir) as $image)
|
||||||
if (preg_match('/^[0-9]*\.jpg$/', $image))
|
if (preg_match('/^[0-9]*\.jpg$/', $image))
|
||||||
foreach ($type as $k => $imageType)
|
foreach ($type as $k => $imageType)
|
||||||
{
|
{
|
||||||
@@ -474,41 +476,39 @@ class AdminImagesControllerCore extends AdminController
|
|||||||
if (!file_exists($newDir))
|
if (!file_exists($newDir))
|
||||||
continue;
|
continue;
|
||||||
if (!file_exists($newDir.substr($image, 0, -4).'-'.stripslashes($imageType['name']).'.jpg'))
|
if (!file_exists($newDir.substr($image, 0, -4).'-'.stripslashes($imageType['name']).'.jpg'))
|
||||||
if (!ImageManager::resize($dir.$image, $newDir.substr($image, 0, -4).'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])))
|
{
|
||||||
|
if (!file_exists($dir.$image) || !filesize($dir.$image))
|
||||||
|
{
|
||||||
$errors = true;
|
$errors = true;
|
||||||
|
$this->errors[] = sprintf(Tools::displayError('Source file does not exist or is empty (%s)', $dir.$image));
|
||||||
|
}
|
||||||
|
elseif (!ImageManager::resize($dir.$image, $newDir.substr($image, 0, -4).'-'.stripslashes($imageType['name']).'.jpg', (int)$imageType['width'], (int)$imageType['height']))
|
||||||
|
$errors = true;
|
||||||
|
}
|
||||||
if (time() - $this->start_time > $this->max_execution_time - 4) // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
|
if (time() - $this->start_time > $this->max_execution_time - 4) // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
|
||||||
return 'timeout';
|
return 'timeout';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$productsImages = Image::getAllImages();
|
foreach (Image::getAllImages() as $image)
|
||||||
foreach ($productsImages as $image)
|
|
||||||
{
|
{
|
||||||
$imageObj = new Image($image['id_image']);
|
$imageObj = new Image($image['id_image']);
|
||||||
if (file_exists($dir.$imageObj->getExistingImgPath().'.jpg'))
|
$existing_img = $dir.$imageObj->getExistingImgPath().'.jpg';
|
||||||
|
if (file_exists($existing_img) && filesize($existing_img))
|
||||||
{
|
{
|
||||||
foreach ($type as $imageType)
|
foreach ($type as $imageType)
|
||||||
{
|
if (!file_exists($dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg'))
|
||||||
$existing_img = $dir.$imageObj->getExistingImgPath().'.jpg';
|
if (!ImageManager::resize($existing_img, $dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])))
|
||||||
|
|
||||||
if (!file_exists($existing_img)) //test if original file exist
|
|
||||||
{
|
|
||||||
$errors = true;
|
|
||||||
$this->errors[] = Tools::displayError('Can\'t find original image '.$dir.$imageObj->getExistingImgPath().'.jpg');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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'])))
|
$errors = true;
|
||||||
{
|
$this->errors[] = Tools::displayError(sprintf('Original image is corrupt (%s) or bad permission on folder', $existing_img));
|
||||||
$errors = true;
|
|
||||||
$this->errors[] = Tools::displayError(sprintf('Original image is corrupt (%s) or bad permission on folder'), $existing_img);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
$errors = true;
|
||||||
|
$this->errors[] = Tools::displayError(sprintf('Original image is missing or empty (%s)', $existing_img));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -608,7 +608,10 @@ class AdminImagesControllerCore extends AdminController
|
|||||||
if ($deleteOldImages)
|
if ($deleteOldImages)
|
||||||
$this->_deleteOldImages($proc['dir'], $formats, ($proc['type'] == 'products' ? true : false));
|
$this->_deleteOldImages($proc['dir'], $formats, ($proc['type'] == 'products' ? true : false));
|
||||||
if (($return = $this->_regenerateNewImages($proc['dir'], $formats, ($proc['type'] == 'products' ? true : false))) === true)
|
if (($return = $this->_regenerateNewImages($proc['dir'], $formats, ($proc['type'] == 'products' ? true : false))) === true)
|
||||||
$this->errors[] = sprintf(Tools::displayError('Cannot write %s images. Please check the folder\'s writing permissions %s.'), $proc['type'], $proc['dir']);
|
{
|
||||||
|
if (!count($this->errors))
|
||||||
|
$this->errors[] = sprintf(Tools::displayError('Cannot write %s images. Please check the folder\'s writing permissions %s.'), $proc['type'], $proc['dir']);
|
||||||
|
}
|
||||||
elseif ($return == 'timeout')
|
elseif ($return == 'timeout')
|
||||||
$this->errors[] = Tools::displayError('Only part of the images have been regenerated, server timed out before finishing.');
|
$this->errors[] = Tools::displayError('Only part of the images have been regenerated, server timed out before finishing.');
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user