Skip to content

Commit 0320617

Browse files
committed
MAGETWO-91164: Optimize images resizing
1 parent 6c227a5 commit 0320617

File tree

2 files changed

+53
-11
lines changed

2 files changed

+53
-11
lines changed

app/code/Magento/Catalog/Console/Command/ImagesResizeCommand.php

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
*/
66
namespace Magento\Catalog\Console\Command;
77

8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Catalog\Model\Product\Image\CacheFactory;
10+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
811
use Magento\Catalog\Model\ResourceModel\Product\Image as ProductImage;
912
use Magento\Framework\App\Area;
13+
use Magento\Framework\App\ObjectManager;
1014
use Magento\Framework\App\State;
1115
use Magento\Catalog\Helper\Image as ImageHelper;
1216
use Magento\Framework\Console\Cli;
@@ -27,7 +31,25 @@ class ImagesResizeCommand extends Command
2731
/**
2832
* @var State
2933
*/
30-
private $appState;
34+
protected $appState;
35+
36+
/**
37+
* @deprecated
38+
* @var CollectionFactory
39+
*/
40+
protected $productCollectionFactory;
41+
42+
/**
43+
* @deprecated
44+
* @var ProductRepositoryInterface
45+
*/
46+
protected $productRepository;
47+
48+
/**
49+
* @deprecated
50+
* @var CacheFactory
51+
*/
52+
protected $imageCacheFactory;
3153

3254
/**
3355
* @var ProductImage
@@ -51,23 +73,33 @@ class ImagesResizeCommand extends Command
5173

5274
/**
5375
* @param State $appState
76+
* @param CollectionFactory $productCollectionFactory
77+
* @param ProductRepositoryInterface $productRepository
78+
* @param CacheFactory $imageCacheFactory
5479
* @param ProductImage $productImage
5580
* @param ViewConfig $viewConfig
5681
* @param ThemeCollection $themeCollection
5782
* @param ProductImageFactory $productImageFactory
5883
*/
5984
public function __construct(
6085
State $appState,
61-
ProductImage $productImage,
62-
ViewConfig $viewConfig,
63-
ThemeCollection $themeCollection,
64-
ProductImageFactory $productImageFactory
86+
CollectionFactory $productCollectionFactory,
87+
ProductRepositoryInterface $productRepository,
88+
CacheFactory $imageCacheFactory,
89+
ProductImage $productImage = null,
90+
ViewConfig $viewConfig = null,
91+
ThemeCollection $themeCollection = null,
92+
ProductImageFactory $productImageFactory = null
6593
) {
6694
$this->appState = $appState;
67-
$this->productImage = $productImage;
68-
$this->viewConfig = $viewConfig;
69-
$this->themeCollection = $themeCollection;
70-
$this->productImageFactory = $productImageFactory;
95+
$this->productCollectionFactory = $productCollectionFactory;
96+
$this->productRepository = $productRepository;
97+
$this->imageCacheFactory = $imageCacheFactory;
98+
$this->productImage = $productImage ?: ObjectManager::getInstance()->get(ProductImage::class);
99+
$this->viewConfig = $viewConfig ?: ObjectManager::getInstance()->get(ViewConfig::class);
100+
$this->themeCollection = $themeCollection ?: ObjectManager::getInstance()->get(ThemeCollection::class);
101+
$this->productImageFactory = $productImageFactory
102+
?: ObjectManager::getInstance()->get(ProductImageFactory::class);
71103
parent::__construct();
72104
}
73105

dev/tests/integration/testsuite/Magento/Catalog/Console/Command/ImagesResizeCommandTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,23 @@ public function setUp()
2727

2828
/**
2929
* @magentoDataFixture Magento/Catalog/_files/product_with_image.php
30-
* @magentoDbIsolation disabled
3130
*/
32-
public function testExecute()
31+
public function testRisizeSuccessfully()
3332
{
3433
$returnStatus = $this->tester->execute([]);
3534
$returnData = $this->tester->getDisplay();
3635
self::assertContains('Product images resized successfully', $returnData);
3736
self::assertEquals(0, $returnStatus);
3837
}
38+
39+
/**
40+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
41+
*/
42+
public function testNoProductImages()
43+
{
44+
$returnStatus = $this->tester->execute([]);
45+
$returnData = $this->tester->getDisplay();
46+
self::assertContains('No product images to resize', $returnData);
47+
self::assertEquals(0, $returnStatus);
48+
}
3949
}

0 commit comments

Comments
 (0)