// Added the new image type names in the updater
This commit is contained in:
@@ -28,29 +28,33 @@
|
||||
function p15018_change_image_types()
|
||||
{
|
||||
$replace_types = array(
|
||||
'small' => 'small_default',
|
||||
'medium' => 'medium_default',
|
||||
'large' => 'large_default',
|
||||
'thickbox' => 'thickbox_default',
|
||||
'category' => 'category_default',
|
||||
'home' => 'home_default',
|
||||
'large_scene' => 'scene_default',
|
||||
'thumb_scene' => 'm_scene_default'
|
||||
'products' => array(
|
||||
'small' => 'small_default',
|
||||
'medium' => 'medium_default',
|
||||
'large' => 'large_default',
|
||||
'thickbox' => 'thickbox_default',
|
||||
'home' => 'home_default'
|
||||
),
|
||||
'others' => array(
|
||||
'category' => 'category_default',
|
||||
'large_scene' => 'scene_default',
|
||||
'thumb_scene' => 'm_scene_default'
|
||||
)
|
||||
);
|
||||
|
||||
$option = false;
|
||||
if (Db::getInstance()->getValue('SELECT id_theme FROM `'._DB_PREFIX_.'theme` WHERE directory != "default"'))
|
||||
$option = true;
|
||||
|
||||
$option = (bool)Db::getInstance()->getValue('SELECT id_theme FROM `'._DB_PREFIX_.'theme` WHERE directory != "default"');
|
||||
|
||||
// If there is another theme than the default one, duplicate
|
||||
if ($option)
|
||||
foreach ($replace_types as $old_type => $new_type)
|
||||
foreach ($replace_types as $type => $type_array)
|
||||
foreach ($type_array as $old_type => $new_type)
|
||||
Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'image_type` (
|
||||
SELECT "'.$new_type.'", width, height, products, categories, manufacturers, suppliers, scenes, stores
|
||||
FROM `'._DB_PREFIX_.'image_type` WHERE name = "'.$old_type.'" LIMIT 1');
|
||||
// But if there is only the default one, we can update de names
|
||||
else
|
||||
foreach ($replace_types as $old_type => $new_type)
|
||||
foreach ($replace_types as $type => $type_array)
|
||||
foreach ($type_array as $old_type => $new_type)
|
||||
Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'image_type` SET name = "'.$new_type.'" WHERE name = "'.$old_type.'"');
|
||||
|
||||
// If there is less than 500 images, copy to the new format (if there is more, the merchant will have to click "regenerate thumbnails")
|
||||
@@ -61,19 +65,23 @@ function p15018_change_image_types()
|
||||
define('_PS_ROOT_DIR_', realpath(INSTALL_PATH.'/../'));
|
||||
foreach ($result as $row)
|
||||
{
|
||||
if (file_exists(_PS_ROOT_DIR_.'img/p/'.$row['id_product'].'-'.$row['id_image'].'.jpg'))
|
||||
foreach ($replace_types as $old_type => $new_type)
|
||||
if (file_exists(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$row['id_product'].'-'.$row['id_image'].'.jpg'))
|
||||
foreach ($replace_types['products'] as $old_type => $new_type)
|
||||
if ($option)
|
||||
@copy(_PS_ROOT_DIR_.'img/p/'.$row['id_product'].'-'.$row['id_image'].'-'.$old_type.'.jpg', _PS_ROOT_DIR_.'img/p/'.$row['id_product'].'-'.$row['id_image'].'-'.$new_type.'.jpg');
|
||||
copy(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$row['id_product'].'-'.$row['id_image'].'-'.$old_type.'.jpg',
|
||||
_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$row['id_product'].'-'.$row['id_image'].'-'.$new_type.'.jpg');
|
||||
else
|
||||
@rename(_PS_ROOT_DIR_.'img/p/'.$row['id_product'].'-'.$row['id_image'].'-'.$old_type.'.jpg', _PS_ROOT_DIR_.'img/p/'.$row['id_product'].'-'.$row['id_image'].'-'.$new_type.'.jpg');
|
||||
$folder = Image::getImgFolderStatic($row['id_image']);
|
||||
if (file_exists(_PS_ROOT_DIR_.'img/p/'.$folder.$row['id_image'].'.jpg'))
|
||||
foreach ($replace_types as $old_type => $new_type)
|
||||
rename(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$row['id_product'].'-'.$row['id_image'].'-'.$old_type.'.jpg',
|
||||
_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$row['id_product'].'-'.$row['id_image'].'-'.$new_type.'.jpg');
|
||||
$folder = implode(DIRECTORY_SEPARATOR, str_split((string)$row['id_image'])).DIRECTORY_SEPARATOR;
|
||||
if (file_exists(_PS_ROOT_DIR_.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$folder.$row['id_image'].'.jpg'))
|
||||
foreach ($replace_types['products'] as $old_type => $new_type)
|
||||
if ($option)
|
||||
@copy(_PS_ROOT_DIR_.'img/p/'.$folder.$row['id_image'].'-'.$old_type.'.jpg', _PS_ROOT_DIR_.'img/p/'.$folder.$row['id_image'].'-'.$new_type.'.jpg');
|
||||
copy(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$folder.$row['id_image'].'-'.$old_type.'.jpg',
|
||||
_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$folder.$row['id_image'].'-'.$new_type.'.jpg');
|
||||
else
|
||||
@rename(_PS_ROOT_DIR_.'img/p/'.$folder.$row['id_image'].'-'.$old_type.'.jpg', _PS_ROOT_DIR_.'img/p/'.$folder.$row['id_image'].'-'.$new_type.'.jpg');
|
||||
rename(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$folder.$row['id_image'].'-'.$old_type.'.jpg',
|
||||
_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$folder.$row['id_image'].'-'.$new_type.'.jpg');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user