Skip to content

Commit

Permalink
remove temporary images
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-bigbridge committed Feb 12, 2021
1 parent a87c6f5 commit cfbd349
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion Model/Resource/ProductStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 16 additions & 3 deletions Model/Resource/Storage/ImageStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down Expand Up @@ -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());
}
}

/**
Expand Down

0 comments on commit cfbd349

Please sign in to comment.