Skip to content

Commit b5b66fe

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.3-develop
Accepted Community Pull Requests: - #23118: #23053 : sendfriend verifies product visibility instead of status (by @Wirson) - #21605: [2.3] Database Media Storage - Admin Product Edit Page handles recreates images correctly when pub/media/catalog is cleared. (by @gwharton) - #23007: [Fixed] Reset feature does not clear the date (by @niravkrish) - #21876: $product->getUrlInStore() does not allow to override the scope in backend context (by @Nazar65) - #20848: Partial docs fixes in Newsletter module (by @SikailoISM) Fixed GitHub Issues: - #23053: Sendfriend works for products with visibility not visible individually (reported by @TomashKhamlai) has been fixed in #23118 by @Wirson in 2.3-develop branch Related commits: 1. 265e0d4 2. 74373a0 - #21546: [2.3] Database Media Storage - New Product Images fail to be processed correctly (reported by @gwharton) has been fixed in #21605 by @gwharton in 2.3-develop branch Related commits: 1. 5f6e24f - #21604: Database Media Storage - Admin Product Edit page does not handle product images correctly in database storage mode (reported by @gwharton) has been fixed in #21605 by @gwharton in 2.3-develop branch Related commits: 1. 5f6e24f - #22940: Reset feature does not clear the date (reported by @renard123) has been fixed in #23007 by @niravkrish in 2.3-develop branch Related commits: 1. c9f98fc 2. 40cc415 - #4247: getProductUrl does not allow to override the scope in backend context (reported by @fetzi) has been fixed in #21876 by @Nazar65 in 2.3-develop branch Related commits: 1. c50975a
2 parents b094f4c + 54b6de9 commit b5b66fe

File tree

12 files changed

+213
-27
lines changed

12 files changed

+213
-27
lines changed

app/code/Magento/Backend/Model/Url.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Class \Magento\Backend\Model\UrlInterface
1414
*
1515
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1617
* @api
1718
* @since 100.0.2
1819
*/
@@ -366,6 +367,19 @@ protected function _getMenu()
366367
return $this->_menu;
367368
}
368369

370+
/**
371+
* Set scope entity
372+
*
373+
* @param mixed $scopeId
374+
* @return \Magento\Framework\UrlInterface
375+
*/
376+
public function setScope($scopeId)
377+
{
378+
parent::setScope($scopeId);
379+
$this->_scope = $this->_scopeResolver->getScope($scopeId);
380+
return $this;
381+
}
382+
369383
/**
370384
* Set custom auth session
371385
*
@@ -402,13 +416,13 @@ public function getAreaFrontName()
402416
}
403417

404418
/**
405-
* Retrieve action path.
406-
* Add backend area front name as a prefix to action path
419+
* Retrieve action path, add backend area front name as a prefix to action path
407420
*
408421
* @return string
409422
*/
410423
protected function _getActionPath()
411424
{
425+
412426
$path = parent::_getActionPath();
413427
if ($path) {
414428
if ($this->getAreaFrontName()) {
@@ -448,8 +462,7 @@ protected function _getConfigCacheId($path)
448462
}
449463

450464
/**
451-
* Get config data by path
452-
* Use only global config values for backend
465+
* Get config data by path, use only global config values for backend
453466
*
454467
* @param string $path
455468
* @return null|string

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Framework\App\Filesystem\DirectoryList;
2020
use Magento\Framework\Exception\FileSystemException;
2121
use Magento\Backend\Block\DataProviders\ImageUploadConfig as ImageUploadConfigDataProvider;
22+
use Magento\MediaStorage\Helper\File\Storage\Database;
2223

2324
/**
2425
* Block for gallery content.
@@ -50,25 +51,34 @@ class Content extends \Magento\Backend\Block\Widget
5051
*/
5152
private $imageUploadConfigDataProvider;
5253

54+
/**
55+
* @var Database
56+
*/
57+
private $fileStorageDatabase;
58+
5359
/**
5460
* @param \Magento\Backend\Block\Template\Context $context
5561
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
5662
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
5763
* @param array $data
5864
* @param ImageUploadConfigDataProvider $imageUploadConfigDataProvider
65+
* @param Database $fileStorageDatabase
5966
*/
6067
public function __construct(
6168
\Magento\Backend\Block\Template\Context $context,
6269
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
6370
\Magento\Catalog\Model\Product\Media\Config $mediaConfig,
6471
array $data = [],
65-
ImageUploadConfigDataProvider $imageUploadConfigDataProvider = null
72+
ImageUploadConfigDataProvider $imageUploadConfigDataProvider = null,
73+
Database $fileStorageDatabase = null
6674
) {
6775
$this->_jsonEncoder = $jsonEncoder;
6876
$this->_mediaConfig = $mediaConfig;
6977
parent::__construct($context, $data);
7078
$this->imageUploadConfigDataProvider = $imageUploadConfigDataProvider
7179
?: ObjectManager::getInstance()->get(ImageUploadConfigDataProvider::class);
80+
$this->fileStorageDatabase = $fileStorageDatabase
81+
?: ObjectManager::getInstance()->get(Database::class);
7282
}
7383

7484
/**
@@ -164,6 +174,13 @@ public function getImagesJson()
164174
$images = $this->sortImagesByPosition($value['images']);
165175
foreach ($images as &$image) {
166176
$image['url'] = $this->_mediaConfig->getMediaUrl($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+
}
167184
try {
168185
$fileHandler = $mediaDir->stat($this->_mediaConfig->getMediaPath($image['file']));
169186
$image['size'] = $fileHandler['size'];
@@ -187,9 +204,12 @@ public function getImagesJson()
187204
private function sortImagesByPosition($images)
188205
{
189206
if (is_array($images)) {
190-
usort($images, function ($imageA, $imageB) {
191-
return ($imageA['position'] < $imageB['position']) ? -1 : 1;
192-
});
207+
usort(
208+
$images,
209+
function ($imageA, $imageB) {
210+
return ($imageA['position'] < $imageB['position']) ? -1 : 1;
211+
}
212+
);
193213
}
194214
return $images;
195215
}

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Helper/Form/Gallery/ContentTest.php

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Model\Entity\Attribute;
1010
use Magento\Catalog\Model\Product;
1111
use Magento\Framework\Phrase;
12+
use Magento\MediaStorage\Helper\File\Storage\Database;
1213

1314
/**
1415
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -50,6 +51,11 @@ class ContentTest extends \PHPUnit\Framework\TestCase
5051
*/
5152
protected $imageHelper;
5253

54+
/**
55+
* @var \Magento\MediaStorage\Helper\File\Storage\Database|\PHPUnit_Framework_MockObject_MockObject
56+
*/
57+
protected $databaseMock;
58+
5359
/**
5460
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
5561
*/
@@ -71,13 +77,18 @@ public function setUp()
7177
->disableOriginalConstructor()
7278
->getMock();
7379

80+
$this->databaseMock = $this->getMockBuilder(Database::class)
81+
->disableOriginalConstructor()
82+
->getMock();
83+
7484
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
7585
$this->content = $this->objectManager->getObject(
7686
\Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content::class,
7787
[
7888
'mediaConfig' => $this->mediaConfigMock,
7989
'jsonEncoder' => $this->jsonEncoderMock,
80-
'filesystem' => $this->fileSystemMock
90+
'filesystem' => $this->fileSystemMock,
91+
'fileStorageDatabase' => $this->databaseMock
8192
]
8293
);
8394
}
@@ -143,6 +154,13 @@ public function testGetImagesJson()
143154
$this->readMock->expects($this->any())->method('stat')->willReturnMap($sizeMap);
144155
$this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
145156

157+
$this->readMock->expects($this->any())
158+
->method('isFile')
159+
->will($this->returnValue(true));
160+
$this->databaseMock->expects($this->any())
161+
->method('checkDbUsage')
162+
->will($this->returnValue(false));
163+
146164
$this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
147165
}
148166

@@ -210,6 +228,14 @@ public function testGetImagesJsonWithException()
210228
$this->fileSystemMock->expects($this->any())->method('getDirectoryRead')->willReturn($this->readMock);
211229
$this->mediaConfigMock->expects($this->any())->method('getMediaUrl');
212230
$this->mediaConfigMock->expects($this->any())->method('getMediaPath');
231+
232+
$this->readMock->expects($this->any())
233+
->method('isFile')
234+
->will($this->returnValue(true));
235+
$this->databaseMock->expects($this->any())
236+
->method('checkDbUsage')
237+
->will($this->returnValue(false));
238+
213239
$this->readMock->expects($this->any())->method('stat')->willReturnOnConsecutiveCalls(
214240
$this->throwException(
215241
new \Magento\Framework\Exception\FileSystemException(new Phrase('test'))
@@ -365,4 +391,52 @@ private function getMediaAttribute(string $label, string $attributeCode)
365391

366392
return $mediaAttribute;
367393
}
394+
395+
/**
396+
* Test GetImagesJson() calls MediaStorage functions to obtain image from DB prior to stat call
397+
*
398+
* @return void
399+
*/
400+
public function testGetImagesJsonMediaStorageMode()
401+
{
402+
$images = [
403+
'images' => [
404+
[
405+
'value_id' => '0',
406+
'file' => 'file_1.jpg',
407+
'media_type' => 'image',
408+
'position' => '0'
409+
]
410+
]
411+
];
412+
413+
$mediaPath = [
414+
['file_1.jpg', 'catalog/product/image_1.jpg']
415+
];
416+
417+
$this->content->setElement($this->galleryMock);
418+
419+
$this->galleryMock->expects($this->once())
420+
->method('getImages')
421+
->willReturn($images);
422+
$this->fileSystemMock->expects($this->once())
423+
->method('getDirectoryRead')
424+
->willReturn($this->readMock);
425+
$this->mediaConfigMock->expects($this->any())
426+
->method('getMediaPath')
427+
->willReturnMap($mediaPath);
428+
429+
$this->readMock->expects($this->any())
430+
->method('isFile')
431+
->will($this->returnValue(false));
432+
$this->databaseMock->expects($this->any())
433+
->method('checkDbUsage')
434+
->will($this->returnValue(true));
435+
436+
$this->databaseMock->expects($this->once())
437+
->method('saveFileToFilesystem')
438+
->with('catalog/product/image_1.jpg');
439+
440+
$this->content->getImagesJson();
441+
}
368442
}

app/code/Magento/Newsletter/Block/Adminhtml/Problem.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(
4141
}
4242

4343
/**
44-
* @return void
44+
* @inheritDoc
4545
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
4646
*/
4747
protected function _construct()
@@ -83,7 +83,7 @@ protected function _prepareLayout()
8383
/**
8484
* Get the html element for unsubscribe button
8585
*
86-
* @return $string
86+
* @return string
8787
*/
8888
public function getUnsubscribeButtonHtml()
8989
{
@@ -93,7 +93,7 @@ public function getUnsubscribeButtonHtml()
9393
/**
9494
* Get the html element for delete button
9595
*
96-
* @return $string
96+
* @return string
9797
*/
9898
public function getDeleteButtonHtml()
9999
{

app/code/Magento/Newsletter/Controller/Adminhtml/Subscriber/MassDelete.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@
66
*/
77
namespace Magento\Newsletter\Controller\Adminhtml\Subscriber;
88

9-
use Magento\Newsletter\Controller\Adminhtml\Subscriber;
109
use Magento\Backend\App\Action\Context;
10+
use Magento\Framework\App\Action\HttpPostActionInterface;
11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\App\Response\Http\FileFactory;
13+
use Magento\Newsletter\Controller\Adminhtml\Subscriber;
1214
use Magento\Newsletter\Model\SubscriberFactory;
13-
use Magento\Framework\App\ObjectManager;
1415

15-
class MassDelete extends Subscriber
16+
/**
17+
* Subscriber mass delete controller.
18+
*/
19+
class MassDelete extends Subscriber implements HttpPostActionInterface
1620
{
1721
/**
1822
* @var SubscriberFactory
1923
*/
2024
private $subscriberFactory;
21-
25+
2226
/**
2327
* @param Context $context
2428
* @param FileFactory $fileFactory
29+
* @param SubscriberFactory|null $subscriberFactory
2530
*/
2631
public function __construct(
2732
Context $context,
@@ -31,7 +36,7 @@ public function __construct(
3136
$this->subscriberFactory = $subscriberFactory ?: ObjectManager::getInstance()->get(SubscriberFactory::class);
3237
parent::__construct($context, $fileFactory);
3338
}
34-
39+
3540
/**
3641
* Delete one or more subscribers action
3742
*

app/code/Magento/Newsletter/Controller/Manage/Save.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Newsletter\Controller\Manage;
89

910
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
10-
use Magento\Customer\Model\Customer;
11+
use Magento\Customer\Api\Data\CustomerInterface;
1112
use Magento\Framework\App\Action\HttpGetActionInterface;
1213
use Magento\Framework\App\Action\HttpPostActionInterface;
1314
use Magento\Newsletter\Model\Subscriber;
@@ -65,7 +66,7 @@ public function __construct(
6566
/**
6667
* Save newsletter subscription preference action
6768
*
68-
* @return void|null
69+
* @return \Magento\Framework\App\ResponseInterface
6970
*/
7071
public function execute()
7172
{
@@ -110,16 +111,16 @@ public function execute()
110111
$this->messageManager->addError(__('Something went wrong while saving your subscription.'));
111112
}
112113
}
113-
$this->_redirect('customer/account/');
114+
return $this->_redirect('customer/account/');
114115
}
115116

116117
/**
117118
* Set ignore_validation_flag to skip unnecessary address and customer validation
118119
*
119-
* @param Customer $customer
120+
* @param CustomerInterface $customer
120121
* @return void
121122
*/
122-
private function setIgnoreValidationFlag($customer)
123+
private function setIgnoreValidationFlag(CustomerInterface $customer): void
123124
{
124125
$customer->setData('ignore_validation_flag', true);
125126
}

app/code/Magento/Newsletter/Controller/Subscriber/Confirm.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7+
declare(strict_types=1);
78

89
namespace Magento\Newsletter\Controller\Subscriber;
910

0 commit comments

Comments
 (0)