Merge pull request #699 from sjousse/patch-1

[*] MO : ShopImporter Optimize image copy in ShopImport module
This commit is contained in:
Gregory Roussac committed 2013-09-09 08:11:51 -07:00
commit 5362f4d426
1 file changed
+6 -13
+6 -13
View File
@@ -844,19 +844,15 @@ class shopimporter extends ImportModule
default: default:
case 'Product': case 'Product':
$path = _PS_PROD_IMG_DIR_; $path = _PS_PROD_IMG_DIR_;
$type = 'products';
break; break;
case 'Category': case 'Category':
$path = _PS_CAT_IMG_DIR_; $path = _PS_CAT_IMG_DIR_;
$type = 'categories';
break; break;
case 'Manufacturer': case 'Manufacturer':
$path = _PS_MANU_IMG_DIR_; $path = _PS_MANU_IMG_DIR_;
$type = 'manufacturers';
break; break;
case 'Supplier': case 'Supplier':
$path = _PS_SUPP_IMG_DIR_; $path = _PS_SUPP_IMG_DIR_;
$type = 'suppliers';
break; break;
} }
$cover = 1; $cover = 1;
@@ -865,11 +861,8 @@ class shopimporter extends ImportModule
foreach($item['images'] as $key => $image) foreach($item['images'] as $key => $image)
{ {
$tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'import'); $tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'import');
if (@copy(str_replace(' ', '%20', $image), $tmpfile)) if (@copy(str_replace(' ', '%20', $image), $tmpfile))
{ {
$imagesTypes = ImageType::getImagesTypes($type);
ImageManager::resize($tmpfile, $path.(int)$matchId[$item[$identifier]].'.jpg');
if ($className == 'Product') if ($className == 'Product')
{ {
$image = new Image(); $image = new Image();
@@ -884,13 +877,13 @@ class shopimporter extends ImportModule
$legend[Configuration::get('PS_LANG_DEFAULT')] = Tools::link_rewrite($val); $legend[Configuration::get('PS_LANG_DEFAULT')] = Tools::link_rewrite($val);
$image->legend = $legend; $image->legend = $legend;
$image->add(); $image->add();
ImageManager::resize($tmpfile, $path.(int)$matchId[$item[$identifier]].'-'.(int)$image->id.'.jpg'); $path = $image->getPathForCreation();
foreach ($imagesTypes AS $k => $imageType) ImageManager::resize($tmpfile, $path.'.jpg');
ImageManager::resize($tmpfile, $path.(int)$matchId[$item[$identifier]].'-'.(int)$image->id.'-'.stripslashes($imageType['name']).'.jpg', $imageType['width'], $imageType['height']);
} }
else else
foreach ($imagesTypes as $imageType) {
ImageManager::resize($tmpfile, $path.(int)$matchId[$item[$identifier]].'-'.stripslashes($imageType['name']).'.jpg', $imageType['width'], $imageType['height']); ImageManager::resize($tmpfile, $path.(int)$matchId[$item[$identifier]].'.jpg');
}
} }
else else
@unlink($tmpfile); @unlink($tmpfile);