Skip to content

Commit a2519ca

Browse files
authored
Merge pull request #8713 from magento-gl/247beta3_jan
[Bluetooth] Community Pull Requests delivery 247beta3
2 parents 7e0fc6b + 99f3426 commit a2519ca

File tree

44 files changed

+1477
-387
lines changed

Some content is hidden

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

44 files changed

+1477
-387
lines changed

app/code/Magento/AdminAnalytics/Controller/Adminhtml/Config/EnableAdminUsage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private function markUserNotified(): ResultInterface
8989
public function execute()
9090
{
9191
$this->enableAdminUsage();
92-
$this->markUserNotified();
92+
return $this->markUserNotified();
9393
}
9494

9595
/**
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\AdminAnalytics\Test\Unit\Controller\Adminhtml\Config;
10+
11+
use Magento\AdminAnalytics\Controller\Adminhtml\Config\EnableAdminUsage;
12+
use Magento\AdminAnalytics\Model\ResourceModel\Viewer\Logger as NotificationLogger;
13+
use Magento\Config\Model\Config;
14+
use Magento\Config\Model\Config\Factory as ConfigFactory;
15+
use Magento\Framework\App\ProductMetadataInterface;
16+
use Magento\Framework\Controller\Result\Json as JsonResult;
17+
use Magento\Framework\Controller\ResultFactory;
18+
use Magento\Framework\Controller\ResultInterface;
19+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
20+
use PHPUnit\Framework\MockObject\MockObject;
21+
22+
/**
23+
* @covers \Magento\AdminAnalytics\Controller\Adminhtml\Config\EnableAdminUsage
24+
*/
25+
class EnableAdminUsageTest extends \PHPUnit\Framework\TestCase
26+
{
27+
private const STUB_PRODUCT_VERSION = 'Product Version';
28+
29+
/** @var EnableAdminUsage */
30+
private $controller;
31+
32+
/** @var MockObject|Config */
33+
private $configMock;
34+
35+
/** @var MockObject|ProductMetadataInterface */
36+
private $productMetadataMock;
37+
38+
/** @var MockObject|NotificationLogger */
39+
private $notificationLoggerMock;
40+
41+
/** @var MockObject|ResultFactory */
42+
private $resultFactoryMock;
43+
44+
/** @var JsonResult|MockObject */
45+
private $resultMock;
46+
47+
protected function setUp(): void
48+
{
49+
$objectManager = new ObjectManager($this);
50+
51+
$this->configMock = $this->getMockBuilder(Config::class)
52+
->disableOriginalConstructor()
53+
->onlyMethods(['setDataByPath', 'save'])
54+
->getMock();
55+
56+
$configFactory = $this->getMockBuilder(ConfigFactory::class)
57+
->disableOriginalConstructor()
58+
->onlyMethods(['create'])
59+
->getMock();
60+
61+
$configFactory->method('create')
62+
->willReturn($this->configMock);
63+
64+
$this->productMetadataMock = $this->getMockBuilder(ProductMetadataInterface::class)
65+
->onlyMethods(['getVersion'])
66+
->getMockForAbstractClass();
67+
68+
$this->productMetadataMock->method('getVersion')
69+
->willReturn(self::STUB_PRODUCT_VERSION);
70+
71+
$this->notificationLoggerMock = $this->getMockBuilder(NotificationLogger::class)
72+
->disableOriginalConstructor()
73+
->onlyMethods(['log'])
74+
->getMock();
75+
76+
$this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)
77+
->disableOriginalConstructor()
78+
->onlyMethods(['create'])
79+
->getMock();
80+
81+
$this->resultMock = $this->getMockBuilder(JsonResult::class)
82+
->disableOriginalConstructor()
83+
->onlyMethods(['setData'])
84+
->getMock();
85+
86+
$this->resultFactoryMock->method('create')
87+
->with(ResultFactory::TYPE_JSON)
88+
->willReturn($this->resultMock);
89+
90+
$this->controller = $objectManager->getObject(EnableAdminUsage::class, [
91+
'configFactory' => $configFactory,
92+
'productMetadata' => $this->productMetadataMock,
93+
'notificationLogger' => $this->notificationLoggerMock,
94+
'resultFactory' => $this->resultFactoryMock
95+
]);
96+
}
97+
98+
/**
99+
* If Controller returns `null`, no data is passed to the browser
100+
*/
101+
public function testResponseAfterAdminUsageChange()
102+
{
103+
// Given
104+
$this->resultMock->method('setData')->willReturnSelf();
105+
106+
// When
107+
$response = $this->controller->execute();
108+
109+
// Then
110+
$this->assertInstanceOf(ResultInterface::class, $response);
111+
}
112+
113+
public function testResponseWhenExceptionThrown()
114+
{
115+
$this->markTestSkipped('magento/magento2#31393 Lack of exception handling');
116+
117+
$this->configMock->method('setDataByPath')
118+
->willThrowException(
119+
new \Exception('System Exception')
120+
);
121+
122+
// When
123+
$response = $this->controller->execute();
124+
125+
// Then
126+
$this->assertInstanceOf(ResultInterface::class, $response);
127+
}
128+
}

app/code/Magento/Backend/etc/config.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
99
<default>
10+
<admin>
11+
<dashboard>
12+
<enable_charts>0</enable_charts>
13+
</dashboard>
14+
</admin>
1015
<dev>
1116
<template>
1217
<minify_html>0</minify_html>
@@ -22,9 +27,6 @@
2227
<forgot_email_template>system_emails_forgot_email_template</forgot_email_template>
2328
<forgot_email_identity>general</forgot_email_identity>
2429
</emails>
25-
<dashboard>
26-
<enable_charts>1</enable_charts>
27-
</dashboard>
2830
<upload_configuration>
2931
<enable_resize>1</enable_resize>
3032
<max_width>1920</max_width>

app/code/Magento/CacheInvalidate/Model/PurgeCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class PurgeCache
3737
/**
3838
* Batch size of the purge request.
3939
*
40-
* Based on default Varnish 4 http_req_hdr_len size minus a 512 bytes margin for method,
40+
* Based on default Varnish 6 http_req_hdr_len size minus a 512 bytes margin for method,
4141
* header name, line feeds etc.
4242
*
43-
* @see https://varnish-cache.org/docs/4.1/reference/varnishd.html
43+
* @see https://varnish-cache.org/docs/6.0/reference/varnishd.html
4444
*
4545
* @var int
4646
*/

app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\CatalogRule\Model\Indexer;
88

9+
use Exception;
910
use Magento\Catalog\Model\Product;
1011
use Magento\Catalog\Model\ProductFactory;
1112
use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
@@ -28,6 +29,7 @@
2829
use Magento\Store\Model\ScopeInterface;
2930
use Magento\Store\Model\StoreManagerInterface;
3031
use Psr\Log\LoggerInterface;
32+
use Zend_Db_Statement_Exception;
3133

3234
/**
3335
* Catalog rule index builder
@@ -181,6 +183,16 @@ class IndexBuilder
181183
*/
182184
private $productCollectionFactory;
183185

186+
/**
187+
* @var ReindexRuleProductsPrice
188+
*/
189+
private $reindexRuleProductsPrice;
190+
191+
/**
192+
* @var int
193+
*/
194+
private $productBatchSize;
195+
184196
/**
185197
* @param RuleCollectionFactory $ruleCollectionFactory
186198
* @param PriceCurrencyInterface $priceCurrency
@@ -204,6 +216,8 @@ class IndexBuilder
204216
* @param TimezoneInterface|null $localeDate
205217
* @param ProductCollectionFactory|null $productCollectionFactory
206218
* @param IndexerRegistry|null $indexerRegistry
219+
* @param ReindexRuleProductsPrice|null $reindexRuleProductsPrice
220+
* @param int $productBatchSize
207221
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
208222
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
209223
*/
@@ -229,7 +243,9 @@ public function __construct(
229243
TableSwapper $tableSwapper = null,
230244
TimezoneInterface $localeDate = null,
231245
ProductCollectionFactory $productCollectionFactory = null,
232-
IndexerRegistry $indexerRegistry = null
246+
IndexerRegistry $indexerRegistry = null,
247+
ReindexRuleProductsPrice $reindexRuleProductsPrice = null,
248+
int $productBatchSize = 1000
233249
) {
234250
$this->resource = $resource;
235251
$this->connection = $resource->getConnection();
@@ -242,6 +258,7 @@ public function __construct(
242258
$this->dateTime = $dateTime;
243259
$this->productFactory = $productFactory;
244260
$this->batchCount = $batchCount;
261+
$this->productBatchSize = $productBatchSize;
245262

246263
$this->productPriceCalculator = $productPriceCalculator ?? ObjectManager::getInstance()->get(
247264
ProductPriceCalculator::class
@@ -275,6 +292,8 @@ public function __construct(
275292
ObjectManager::getInstance()->get(IndexerRegistry::class);
276293
$this->productCollectionFactory = $productCollectionFactory ??
277294
ObjectManager::getInstance()->get(ProductCollectionFactory::class);
295+
$this->reindexRuleProductsPrice = $reindexRuleProductsPrice ??
296+
ObjectManager::getInstance()->get(ReindexRuleProductsPrice::class);
278297
}
279298

280299
/**
@@ -296,7 +315,7 @@ public function reindexById($id)
296315
}
297316

298317
$this->reindexRuleGroupWebsite->execute();
299-
} catch (\Exception $e) {
318+
} catch (Exception $e) {
300319
$this->critical($e);
301320
throw new LocalizedException(
302321
__('Catalog rule indexing failed. See details in exception log.')
@@ -315,7 +334,7 @@ public function reindexByIds(array $ids)
315334
{
316335
try {
317336
$this->doReindexByIds($ids);
318-
} catch (\Exception $e) {
337+
} catch (Exception $e) {
319338
$this->critical($e);
320339
throw new LocalizedException(
321340
__("Catalog rule indexing failed. See details in exception log.")
@@ -328,6 +347,8 @@ public function reindexByIds(array $ids)
328347
*
329348
* @param array $ids
330349
* @return void
350+
* @throws LocalizedException
351+
* @throws Zend_Db_Statement_Exception
331352
*/
332353
protected function doReindexByIds($ids)
333354
{
@@ -340,9 +361,10 @@ protected function doReindexByIds($ids)
340361
$this->reindexRuleProduct->execute($rule, $this->batchCount);
341362
}
342363

343-
foreach ($ids as $productId) {
344-
$this->cleanProductPriceIndex([$productId]);
345-
$this->reindexRuleProductPrice->execute($this->batchCount, $productId);
364+
// batch products together, using configurable batch size parameter
365+
foreach (array_chunk($ids, $this->productBatchSize) as $productIds) {
366+
$this->cleanProductPriceIndex($productIds);
367+
$this->reindexRuleProductsPrice->execute($this->batchCount, $productIds);
346368
}
347369

348370
//the case was not handled via indexer dependency decorator or via mview configuration
@@ -367,7 +389,7 @@ public function reindexFull()
367389
{
368390
try {
369391
$this->doReindexFull();
370-
} catch (\Exception $e) {
392+
} catch (Exception $e) {
371393
$this->critical($e);
372394
throw new LocalizedException(
373395
__("Catalog rule indexing failed. See details in exception log.")
@@ -441,6 +463,7 @@ protected function cleanByIds($productIds)
441463
* @param int $productEntityId
442464
* @param array $websiteIds
443465
* @return void
466+
* @throws Exception
444467
*/
445468
private function assignProductToRule(Rule $rule, int $productEntityId, array $websiteIds): void
446469
{
@@ -502,7 +525,7 @@ private function assignProductToRule(Rule $rule, int $productEntityId, array $we
502525
* @param Rule $rule
503526
* @param Product $product
504527
* @return $this
505-
* @throws \Exception
528+
* @throws Exception
506529
* @deprecated 101.1.5
507530
* @see ReindexRuleProduct::execute
508531
* @SuppressWarnings(PHPMD.NPathComplexity)
@@ -525,6 +548,7 @@ protected function applyRule(Rule $rule, $product)
525548
* @param RuleCollection $ruleCollection
526549
* @param Product $product
527550
* @return void
551+
* @throws LocalizedException
528552
*/
529553
private function applyRules(RuleCollection $ruleCollection, Product $product): void
530554
{
@@ -590,7 +614,7 @@ protected function updateRuleProductData(Rule $rule)
590614
* Apply all rules
591615
*
592616
* @param Product|null $product
593-
* @throws \Exception
617+
* @throws Exception
594618
* @return $this
595619
* @deprecated 101.0.0
596620
* @see ReindexRuleProductPrice::execute
@@ -661,7 +685,7 @@ protected function getRuleProductsStmt($websiteId, Product $product = null)
661685
*
662686
* @param array $arrData
663687
* @return $this
664-
* @throws \Exception
688+
* @throws Exception
665689
* @deprecated 101.0.0
666690
* @see RuleProductPricesPersistor::execute
667691
*/
@@ -708,7 +732,7 @@ protected function getProduct($productId)
708732
/**
709733
* Log critical exception
710734
*
711-
* @param \Exception $e
735+
* @param Exception $e
712736
* @return void
713737
*/
714738
protected function critical($e)

0 commit comments

Comments
 (0)