// Added the new image type names in the updater
This commit is contained in:
@@ -28,29 +28,33 @@
|
|||||||
function p15018_change_image_types()
|
function p15018_change_image_types()
|
||||||
{
|
{
|
||||||
$replace_types = array(
|
$replace_types = array(
|
||||||
'small' => 'small_default',
|
'products' => array(
|
||||||
'medium' => 'medium_default',
|
'small' => 'small_default',
|
||||||
'large' => 'large_default',
|
'medium' => 'medium_default',
|
||||||
'thickbox' => 'thickbox_default',
|
'large' => 'large_default',
|
||||||
'category' => 'category_default',
|
'thickbox' => 'thickbox_default',
|
||||||
'home' => 'home_default',
|
'home' => 'home_default'
|
||||||
'large_scene' => 'scene_default',
|
),
|
||||||
'thumb_scene' => 'm_scene_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 there is another theme than the default one, duplicate
|
||||||
if ($option)
|
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` (
|
Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'image_type` (
|
||||||
SELECT "'.$new_type.'", width, height, products, categories, manufacturers, suppliers, scenes, stores
|
SELECT "'.$new_type.'", width, height, products, categories, manufacturers, suppliers, scenes, stores
|
||||||
FROM `'._DB_PREFIX_.'image_type` WHERE name = "'.$old_type.'" LIMIT 1');
|
FROM `'._DB_PREFIX_.'image_type` WHERE name = "'.$old_type.'" LIMIT 1');
|
||||||
// But if there is only the default one, we can update de names
|
// But if there is only the default one, we can update de names
|
||||||
else
|
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.'"');
|
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")
|
// 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.'/../'));
|
define('_PS_ROOT_DIR_', realpath(INSTALL_PATH.'/../'));
|
||||||
foreach ($result as $row)
|
foreach ($result as $row)
|
||||||
{
|
{
|
||||||
if (file_exists(_PS_ROOT_DIR_.'img/p/'.$row['id_product'].'-'.$row['id_image'].'.jpg'))
|
if (file_exists(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$row['id_product'].'-'.$row['id_image'].'.jpg'))
|
||||||
foreach ($replace_types as $old_type => $new_type)
|
foreach ($replace_types['products'] as $old_type => $new_type)
|
||||||
if ($option)
|
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
|
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');
|
rename(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$row['id_product'].'-'.$row['id_image'].'-'.$old_type.'.jpg',
|
||||||
$folder = Image::getImgFolderStatic($row['id_image']);
|
_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'img'.DIRECTORY_SEPARATOR.'p'.DIRECTORY_SEPARATOR.$row['id_product'].'-'.$row['id_image'].'-'.$new_type.'.jpg');
|
||||||
if (file_exists(_PS_ROOT_DIR_.'img/p/'.$folder.$row['id_image'].'.jpg'))
|
$folder = implode(DIRECTORY_SEPARATOR, str_split((string)$row['id_image'])).DIRECTORY_SEPARATOR;
|
||||||
foreach ($replace_types as $old_type => $new_type)
|
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)
|
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
|
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