diff --git a/CHANGELOG.md b/CHANGELOG.md index afe9396..0b3018e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +# 1.6.1 : Fix remove temporary images in force-download mode + +In the (default) mode where images are re-downloaded each import, the images were left in the temporary directory (even though they were not used again). This is now no longer the case. The images are removed after the import. + ## 1.6.0 : Flat type category url paths * An option, requested by Chris Astley, to create simple url_path attributes for generated categories (i.e 'corner-chairs' instead of the standard 'furniture/tables/corner-chairs'). This extends to the url_rewrite entry as well. diff --git a/Model/Resource/ProductStorage.php b/Model/Resource/ProductStorage.php index e6a63f1..e2a73d9 100644 --- a/Model/Resource/ProductStorage.php +++ b/Model/Resource/ProductStorage.php @@ -332,7 +332,8 @@ protected function saveProducts(array $validProducts, ImportConfig $config) $this->stockItemStorage->storeStockItems($validProducts); $this->linkedProductStorage->updateLinkedProducts($validProducts); $this->imageStorage->storeProductImages($validProducts, - $config->imageStrategy === ImportConfig::IMAGE_STRATEGY_SET); + $config->imageStrategy === ImportConfig::IMAGE_STRATEGY_SET, + $config->existingImageStrategy == ImportConfig::EXISTING_IMAGE_STRATEGY_FORCE_DOWNLOAD); $this->tierPriceStorage->updateTierPrices($validProducts); // url_rewrite (must be done after url_key and category_id) diff --git a/Model/Resource/Storage/ImageStorage.php b/Model/Resource/Storage/ImageStorage.php index cf7d097..ec716e9 100644 --- a/Model/Resource/Storage/ImageStorage.php +++ b/Model/Resource/Storage/ImageStorage.php @@ -185,17 +185,18 @@ protected function getDownloadableTemporaryStoragePath(DownloadableProduct $prod /** * @param Product[] $products * @param bool $removeObsoleteImages + * @param bool $removeTemporaryImages */ - public function storeProductImages(array $products, bool $removeObsoleteImages) + public function storeProductImages(array $products, bool $removeObsoleteImages, bool $removeTemporaryImages) { foreach ($products as $product) { - $this->storeImages($product, $removeObsoleteImages); + $this->storeImages($product, $removeObsoleteImages, $removeTemporaryImages); } $this->insertImageRoles($products); } - protected function storeImages(Product $product, bool $removeObsoleteImages) + protected function storeImages(Product $product, bool $removeObsoleteImages, bool $removeTemporaryImages) { // important! if no images are specified, do not remove all images if (empty($product->getImages())) { @@ -229,6 +230,18 @@ protected function storeImages(Product $product, bool $removeObsoleteImages) $this->upsertImageGalleryInformation($product->id, $storeView->getStoreViewId(), $imageGalleryInformation); } } + + // remove temporary images + if ($removeTemporaryImages) { + $this->removeTemporaryImages($product); + } + } + + protected function removeTemporaryImages(Product $product) + { + foreach ($product->getImages() as $image) { + @unlink($image->getTemporaryStoragePath()); + } } /**