Skip to content

Commit 1a77b70

Browse files
authored
Merge pull request #5439 from magento-architects/revert-5305-ECP-98
Reverted issues: - ECP-261 Offload Catalog Image Resizing from Magento - ECP-262 Offload Catalog Image Watermarking from Magento - ECP-263 Deprecate Rotation Support in Magento
2 parents a95a465 + ede8569 commit 1a77b70

File tree

73 files changed

+2598
-2038
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2598
-2038
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Gallery/Content.php

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,16 @@
1313
*/
1414
namespace Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery;
1515

16-
use Magento\Backend\Block\DataProviders\ImageUploadConfig as ImageUploadConfigDataProvider;
16+
use Magento\Framework\App\ObjectManager;
1717
use Magento\Backend\Block\Media\Uploader;
18+
use Magento\Framework\View\Element\AbstractBlock;
1819
use Magento\Framework\App\Filesystem\DirectoryList;
19-
use Magento\Framework\App\ObjectManager;
2020
use Magento\Framework\Exception\FileSystemException;
21-
use Magento\Framework\Storage\FileNotFoundException;
22-
use Magento\Framework\Storage\StorageProvider;
23-
use Magento\Framework\View\Element\AbstractBlock;
21+
use Magento\Backend\Block\DataProviders\ImageUploadConfig as ImageUploadConfigDataProvider;
2422
use Magento\MediaStorage\Helper\File\Storage\Database;
2523

2624
/**
2725
* Block for gallery content.
28-
*
29-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3026
*/
3127
class Content extends \Magento\Backend\Block\Widget
3228
{
@@ -59,21 +55,11 @@ class Content extends \Magento\Backend\Block\Widget
5955
* @var Database
6056
*/
6157
private $fileStorageDatabase;
62-
/**
63-
* @var StorageProvider
64-
*/
65-
private $storageProvider;
66-
67-
/**
68-
* @var \Magento\Framework\Filesystem\Directory\ReadInterface
69-
*/
70-
private $mediaDirectory;
7158

7259
/**
7360
* @param \Magento\Backend\Block\Template\Context $context
7461
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
7562
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
76-
* @param StorageProvider $storageProvider
7763
* @param array $data
7864
* @param ImageUploadConfigDataProvider $imageUploadConfigDataProvider
7965
* @param Database $fileStorageDatabase
@@ -82,20 +68,17 @@ public function __construct(
8268
\Magento\Backend\Block\Template\Context $context,
8369
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
8470
\Magento\Catalog\Model\Product\Media\Config $mediaConfig,
85-
StorageProvider $storageProvider,
8671
array $data = [],
8772
ImageUploadConfigDataProvider $imageUploadConfigDataProvider = null,
8873
Database $fileStorageDatabase = null
8974
) {
9075
$this->_jsonEncoder = $jsonEncoder;
9176
$this->_mediaConfig = $mediaConfig;
9277
parent::__construct($context, $data);
93-
$this->mediaDirectory = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
9478
$this->imageUploadConfigDataProvider = $imageUploadConfigDataProvider
9579
?: ObjectManager::getInstance()->get(ImageUploadConfigDataProvider::class);
9680
$this->fileStorageDatabase = $fileStorageDatabase
9781
?: ObjectManager::getInstance()->get(Database::class);
98-
$this->storageProvider = $storageProvider;
9982
}
10083

10184
/**
@@ -174,49 +157,10 @@ public function getAddImagesButton()
174157
);
175158
}
176159

177-
/**
178-
* Sync images to database
179-
*
180-
* @param string $fileName
181-
*/
182-
private function syncImageToDatabase(string $fileName): void
183-
{
184-
if ($this->fileStorageDatabase->checkDbUsage() &&
185-
!$this->mediaDirectory->isFile($this->_mediaConfig->getMediaPath($fileName))
186-
) {
187-
$this->fileStorageDatabase->saveFileToFilesystem(
188-
$this->_mediaConfig->getMediaPath($fileName)
189-
);
190-
}
191-
}
192-
193-
/**
194-
* Returns file metadata as an associative array
195-
*
196-
* @param string $fileName
197-
* @return array
198-
* @throws FileNotFoundException
199-
*/
200-
private function getFileMetadata(string $fileName): array
201-
{
202-
$metadata = [];
203-
try {
204-
$info = $this->storageProvider->get('media')
205-
->getMetadata($this->_mediaConfig->getMediaPath($fileName));
206-
$metadata['size'] = $info['size'];
207-
} catch (FileSystemException $e) {
208-
$metadata['url'] = $this->getImageHelper()->getDefaultPlaceholderUrl('small_image');
209-
$metadata['size'] = 0;
210-
$this->_logger->warning($e);
211-
}
212-
return $metadata;
213-
}
214-
215160
/**
216161
* Returns image json
217162
*
218163
* @return string
219-
* @throws FileNotFoundException
220164
*/
221165
public function getImagesJson()
222166
{
@@ -226,14 +170,24 @@ public function getImagesJson()
226170
is_array($value['images']) &&
227171
count($value['images'])
228172
) {
173+
$mediaDir = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA);
229174
$images = $this->sortImagesByPosition($value['images']);
230175
foreach ($images as &$image) {
231176
$image['url'] = $this->_mediaConfig->getMediaUrl($image['file']);
232-
$this->syncImageToDatabase($image['file']);
233-
if (isset($image['image_metadata']) && is_array($image['image_metadata'])) {
234-
$image = array_replace_recursive($image, $image['image_metadata']);
235-
} else {
236-
$image = array_replace_recursive($image, $this->getFileMetadata($image['file']));
177+
if ($this->fileStorageDatabase->checkDbUsage() &&
178+
!$mediaDir->isFile($this->_mediaConfig->getMediaPath($image['file']))
179+
) {
180+
$this->fileStorageDatabase->saveFileToFilesystem(
181+
$this->_mediaConfig->getMediaPath($image['file'])
182+
);
183+
}
184+
try {
185+
$fileHandler = $mediaDir->stat($this->_mediaConfig->getMediaPath($image['file']));
186+
$image['size'] = $fileHandler['size'];
187+
} catch (FileSystemException $e) {
188+
$image['url'] = $this->getImageHelper()->getDefaultPlaceholderUrl('small_image');
189+
$image['size'] = 0;
190+
$this->_logger->warning($e);
237191
}
238192
}
239193
return $this->_jsonEncoder->encode($images);

app/code/Magento/Catalog/Block/Product/Gallery.php

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111
*/
1212
namespace Magento\Catalog\Block\Product;
1313

14-
use Magento\Framework\Storage\FileNotFoundException;
1514
use Magento\Catalog\Model\Product;
16-
use Magento\Catalog\Model\Product\Media\Config;
17-
use Magento\Framework\App\ObjectManager;
15+
use Magento\Framework\App\Filesystem\DirectoryList;
1816
use Magento\Framework\Data\Collection;
19-
use Magento\Framework\Registry;
20-
use Magento\Framework\Storage\StorageProvider;
2117

2218
/**
2319
* Product gallery block
@@ -30,37 +26,22 @@ class Gallery extends \Magento\Framework\View\Element\Template
3026
/**
3127
* Core registry
3228
*
33-
* @var Registry
29+
* @var \Magento\Framework\Registry
3430
*/
3531
protected $_coreRegistry = null;
3632

37-
/**
38-
* @var StorageProvider
39-
*/
40-
private $storageProvider;
41-
/**
42-
* @var Config
43-
*/
44-
private $mediaConfig;
45-
4633
/**
4734
* @param \Magento\Framework\View\Element\Template\Context $context
48-
* @param Registry $registry
35+
* @param \Magento\Framework\Registry $registry
4936
* @param array $data
50-
* @param StorageProvider $storageProvider
51-
* @param Config $mediaConfig
5237
*/
5338
public function __construct(
5439
\Magento\Framework\View\Element\Template\Context $context,
55-
Registry $registry,
56-
array $data = [],
57-
StorageProvider $storageProvider = null,
58-
Config $mediaConfig = null
40+
\Magento\Framework\Registry $registry,
41+
array $data = []
5942
) {
6043
$this->_coreRegistry = $registry;
6144
parent::__construct($context, $data);
62-
$this->storageProvider = $storageProvider ?? ObjectManager::getInstance()->get(StorageProvider::class);
63-
$this->mediaConfig = $mediaConfig ?? ObjectManager::getInstance()->get(Config::class);
6445
}
6546

6647
/**
@@ -140,24 +121,16 @@ public function getImageFile()
140121
*/
141122
public function getImageWidth()
142123
{
143-
$file = $this->getCurrentImage()->getFile();
144-
if (!$file) {
145-
return false;
146-
}
147-
$productMediaFile = $this->mediaConfig->getMediaPath($file);
148-
149-
$mediaStorage = $this->storageProvider->get('media');
150-
if ($mediaStorage->has($productMediaFile)) {
151-
try {
152-
$meta = $mediaStorage->getMetadata($productMediaFile);
153-
$size = $meta['size'];
154-
if ($size > 600) {
124+
$file = $this->getCurrentImage()->getPath();
125+
126+
if ($this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)->isFile($file)) {
127+
$size = getimagesize($file);
128+
if (isset($size[0])) {
129+
if ($size[0] > 600) {
155130
return 600;
156131
} else {
157-
return (int) $size;
132+
return (int) $size[0];
158133
}
159-
} catch (FileNotFoundException $e) {
160-
return false;
161134
}
162135
}
163136

app/code/Magento/Catalog/Block/Rss/Category.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use Magento\Framework\Exception\NoSuchEntityException;
1111

1212
/**
13-
* Category feed block
13+
* Class Category
14+
*
15+
* @package Magento\Catalog\Block\Rss
1416
*
1517
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1618
*/

app/code/Magento/Catalog/Block/Rss/Product/NewProducts.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
use Magento\Framework\App\Rss\DataProviderInterface;
99

1010
/**
11-
* New products feed block
11+
* Class NewProducts
12+
* @package Magento\Catalog\Block\Rss\Product
1213
*/
1314
class NewProducts extends \Magento\Framework\View\Element\AbstractBlock implements DataProviderInterface
1415
{
@@ -54,8 +55,6 @@ public function __construct(
5455
}
5556

5657
/**
57-
* Init
58-
*
5958
* @return void
6059
*/
6160
protected function _construct()
@@ -65,15 +64,15 @@ protected function _construct()
6564
}
6665

6766
/**
68-
* @inheritdoc
67+
* {@inheritdoc}
6968
*/
7069
public function isAllowed()
7170
{
7271
return $this->_scopeConfig->isSetFlag('rss/catalog/new', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
7372
}
7473

7574
/**
76-
* @inheritdoc
75+
* {@inheritdoc}
7776
*/
7877
public function getRssData()
7978
{
@@ -98,13 +97,10 @@ public function getRssData()
9897
$item->setAllowedInRss(true);
9998
$item->setAllowedPriceInRss(true);
10099

101-
$this->_eventManager->dispatch(
102-
'rss_catalog_new_xml_callback',
103-
[
104-
'row' => $item->getData(),
105-
'product' => $item
106-
]
107-
);
100+
$this->_eventManager->dispatch('rss_catalog_new_xml_callback', [
101+
'row' => $item->getData(),
102+
'product' => $item
103+
]);
108104

109105
if (!$item->getAllowedInRss()) {
110106
continue;
@@ -136,8 +132,6 @@ public function getRssData()
136132
}
137133

138134
/**
139-
* Get store id
140-
*
141135
* @return int
142136
*/
143137
protected function getStoreId()
@@ -183,16 +177,14 @@ protected function renderPriceHtml(\Magento\Catalog\Model\Product $product)
183177
}
184178

185179
/**
186-
* @inheritdoc
180+
* {@inheritdoc}
187181
*/
188182
public function getCacheLifetime()
189183
{
190184
return 600;
191185
}
192186

193187
/**
194-
* Get feeds
195-
*
196188
* @return array
197189
*/
198190
public function getFeeds()
@@ -207,7 +199,7 @@ public function getFeeds()
207199
}
208200

209201
/**
210-
* @inheritdoc
202+
* {@inheritdoc}
211203
*/
212204
public function isAuthRequired()
213205
{

0 commit comments

Comments
 (0)