Skip to content

Commit caf42c9

Browse files
committed
Merge remote-tracking branch 'mainline/2.3-develop' into DEVOPS-2632-2.3
2 parents 63cef66 + 345823b commit caf42c9

File tree

9 files changed

+310
-53
lines changed

9 files changed

+310
-53
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ protected function initializeProductData(array $productData, $createNew)
334334
unset($productData['media_gallery']);
335335
if ($createNew) {
336336
$product = $this->productFactory->create();
337-
if ($this->storeManager->hasSingleStore()) {
338-
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsiteId()]);
339-
}
337+
$this->assignProductToWebsites($product);
340338
} else {
341339
$this->removeProductFromLocalCache($productData['sku']);
342340
$product = $this->get($productData['sku']);
@@ -345,31 +343,20 @@ protected function initializeProductData(array $productData, $createNew)
345343
foreach ($productData as $key => $value) {
346344
$product->setData($key, $value);
347345
}
348-
$this->assignProductToWebsites($product, $createNew);
349346

350347
return $product;
351348
}
352349

353350
/**
354351
* @param \Magento\Catalog\Model\Product $product
355-
* @param bool $createNew
356352
* @return void
357353
*/
358-
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product, $createNew)
354+
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product)
359355
{
360-
$websiteIds = $product->getWebsiteIds();
361-
362-
if (!$this->storeManager->hasSingleStore()) {
363-
$websiteIds = array_unique(
364-
array_merge(
365-
$websiteIds,
366-
[$this->storeManager->getStore()->getWebsiteId()]
367-
)
368-
);
369-
}
370-
371-
if ($createNew && $this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
356+
if ($this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
372357
$websiteIds = array_keys($this->storeManager->getWebsites());
358+
} else {
359+
$websiteIds = [$this->storeManager->getStore()->getWebsiteId()];
373360
}
374361

375362
$product->setWebsiteIds($websiteIds);

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ public function testGetBySkuFromCacheInitializedInGetById()
553553

554554
public function testSaveExisting()
555555
{
556-
$this->storeManagerMock->expects($this->any())->method('getWebsites')->willReturn([1 => 'default']);
557556
$this->resourceModelMock->expects($this->any())->method('getIdBySku')->will($this->returnValue(100));
558557
$this->productFactoryMock->expects($this->any())
559558
->method('create')
@@ -566,7 +565,6 @@ public function testSaveExisting()
566565
->expects($this->once())
567566
->method('toNestedArray')
568567
->will($this->returnValue($this->productData));
569-
$this->productMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
570568
$this->productMock->expects($this->atLeastOnce())->method('getSku')->willReturn($this->productData['sku']);
571569

572570
$this->assertEquals($this->productMock, $this->model->save($this->productMock));
@@ -588,7 +586,6 @@ public function testSaveNew()
588586
->expects($this->once())
589587
->method('toNestedArray')
590588
->will($this->returnValue($this->productData));
591-
$this->productMock->method('getWebsiteIds')->willReturn([]);
592589
$this->productMock->method('getSku')->willReturn('simple');
593590

594591
$this->assertEquals($this->productMock, $this->model->save($this->productMock));
@@ -615,7 +612,6 @@ public function testSaveUnableToSaveException()
615612
->expects($this->once())
616613
->method('toNestedArray')
617614
->will($this->returnValue($this->productData));
618-
$this->productMock->method('getWebsiteIds')->willReturn([]);
619615
$this->productMock->method('getSku')->willReturn('simple');
620616

621617
$this->model->save($this->productMock);
@@ -642,7 +638,6 @@ public function testSaveException()
642638
->expects($this->once())
643639
->method('toNestedArray')
644640
->will($this->returnValue($this->productData));
645-
$this->productMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
646641
$this->productMock->method('getSku')->willReturn('simple');
647642

648643
$this->model->save($this->productMock);
@@ -667,7 +662,6 @@ public function testSaveInvalidProductException()
667662
->expects($this->once())
668663
->method('toNestedArray')
669664
->will($this->returnValue($this->productData));
670-
$this->productMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
671665
$this->productMock->method('getSku')->willReturn('simple');
672666

673667
$this->model->save($this->productMock);
@@ -697,9 +691,6 @@ public function testSaveThrowsTemporaryStateExceptionIfDatabaseConnectionErrorOc
697691
->expects($this->once())
698692
->method('toNestedArray')
699693
->will($this->returnValue($this->productData));
700-
$this->productMock->expects($this->once())
701-
->method('getWebsiteIds')
702-
->willReturn([]);
703694
$this->productMock->method('getSku')->willReturn('simple');
704695

705696
$this->model->save($this->productMock);
@@ -847,7 +838,6 @@ public function testSaveExistingWithOptions(array $newOptions, array $existingOp
847838
->method('toNestedArray')
848839
->will($this->returnValue($this->productData));
849840

850-
$this->initializedProductMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
851841
$this->initializedProductMock->expects($this->atLeastOnce())
852842
->method('getSku')->willReturn($this->productData['sku']);
853843
$this->productMock->expects($this->atLeastOnce())->method('getSku')->willReturn($this->productData['sku']);
@@ -1083,7 +1073,6 @@ public function testSaveWithLinks(array $newLinks, array $existingLinks, array $
10831073
$outputLinks[] = $outputLink;
10841074
}
10851075
}
1086-
$this->initializedProductMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
10871076

10881077
if (!empty($outputLinks)) {
10891078
$this->initializedProductMock->expects($this->once())
@@ -1264,7 +1253,6 @@ public function testSaveExistingWithNewMediaGalleryEntries()
12641253
'media_type' => 'media_type',
12651254
]
12661255
);
1267-
$this->initializedProductMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
12681256
$this->initializedProductMock->expects($this->atLeastOnce())
12691257
->method('getSku')->willReturn($this->productData['sku']);
12701258
$this->productMock->expects($this->atLeastOnce())->method('getSku')->willReturn($this->productData['sku']);
@@ -1305,7 +1293,6 @@ public function testSaveWithDifferentWebsites()
13051293
2 => ['second'],
13061294
3 => ['third']
13071295
]);
1308-
$this->productMock->expects($this->once())->method('getWebsiteIds')->willReturn([1,2,3]);
13091296
$this->productMock->expects($this->once())->method('setWebsiteIds')->willReturn([2,3]);
13101297
$this->productMock->method('getSku')->willReturn('simple');
13111298

@@ -1377,7 +1364,6 @@ public function testSaveExistingWithMediaGalleryEntries()
13771364
$this->mediaGalleryProcessor->expects($this->once())
13781365
->method('setMediaAttribute')
13791366
->with($this->initializedProductMock, ['image', 'small_image'], 'filename1');
1380-
$this->initializedProductMock->expects($this->once())->method('getWebsiteIds')->willReturn([]);
13811367
$this->initializedProductMock->expects($this->atLeastOnce())
13821368
->method('getSku')->willReturn($this->productData['sku']);
13831369
$this->productMock->expects($this->atLeastOnce())->method('getSku')->willReturn($this->productData['sku']);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Developer\Model\Logger\Handler;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\DeploymentConfig;
12+
13+
/**
14+
* Enable/disable syslog logging based on the store config setting.
15+
*/
16+
class Syslog extends \Magento\Framework\Logger\Handler\Syslog
17+
{
18+
public const CONFIG_PATH = 'dev/syslog/syslog_logging';
19+
20+
/**
21+
* Scope config.
22+
*
23+
* @var ScopeConfigInterface
24+
*/
25+
private $scopeConfig;
26+
27+
/**
28+
* Deployment config.
29+
*
30+
* @var DeploymentConfig
31+
*/
32+
private $deploymentConfig;
33+
34+
/**
35+
* @param ScopeConfigInterface $scopeConfig Scope config
36+
* @param DeploymentConfig $deploymentConfig Deployment config
37+
* @param string $ident The string ident to be added to each message
38+
*/
39+
public function __construct(
40+
ScopeConfigInterface $scopeConfig,
41+
DeploymentConfig $deploymentConfig,
42+
string $ident
43+
) {
44+
parent::__construct($ident);
45+
46+
$this->scopeConfig = $scopeConfig;
47+
$this->deploymentConfig = $deploymentConfig;
48+
}
49+
50+
/**
51+
* @inheritdoc
52+
*/
53+
public function isHandling(array $record): bool
54+
{
55+
return parent::isHandling($record)
56+
&& $this->deploymentConfig->isAvailable()
57+
&& $this->scopeConfig->getValue(self::CONFIG_PATH);
58+
}
59+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Developer\Test\Unit\Model\Logger\Handler;
9+
10+
use Magento\Developer\Model\Logger\Handler\Syslog;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\App\DeploymentConfig;
13+
use Magento\Framework\Logger\Monolog;
14+
use PHPUnit\Framework\TestCase;
15+
use PHPUnit_Framework_MockObject_MockObject as Mock;
16+
17+
/**
18+
* @inheritdoc
19+
*/
20+
class SyslogTest extends TestCase
21+
{
22+
/**
23+
* @var Syslog
24+
*/
25+
private $model;
26+
27+
/**
28+
* @var ScopeConfigInterface|Mock
29+
*/
30+
private $scopeConfigMock;
31+
32+
/**
33+
* @var DeploymentConfig|Mock
34+
*/
35+
private $deploymentConfigMock;
36+
37+
protected function setUp()
38+
{
39+
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
40+
$this->deploymentConfigMock = $this->createMock(DeploymentConfig::class);
41+
42+
$this->model = new Syslog(
43+
$this->scopeConfigMock,
44+
$this->deploymentConfigMock,
45+
'Magento'
46+
);
47+
}
48+
49+
public function testIsHandling(): void
50+
{
51+
$record = [
52+
'level' => Monolog::DEBUG,
53+
];
54+
55+
$this->scopeConfigMock->expects($this->once())
56+
->method('getValue')
57+
->with(Syslog::CONFIG_PATH)
58+
->willReturn('1');
59+
$this->deploymentConfigMock->expects($this->once())
60+
->method('isAvailable')
61+
->willReturn(true);
62+
63+
$this->assertTrue(
64+
$this->model->isHandling($record)
65+
);
66+
}
67+
68+
public function testIsHandlingNotInstalled(): void
69+
{
70+
$record = [
71+
'level' => Monolog::DEBUG,
72+
];
73+
74+
$this->scopeConfigMock->expects($this->never())
75+
->method('getValue');
76+
$this->deploymentConfigMock->expects($this->once())
77+
->method('isAvailable')
78+
->willReturn(false);
79+
80+
$this->assertFalse(
81+
$this->model->isHandling($record)
82+
);
83+
}
84+
85+
public function testIsHandlingDisabled(): void
86+
{
87+
$record = [
88+
'level' => Monolog::DEBUG,
89+
];
90+
91+
$this->scopeConfigMock->expects($this->once())
92+
->method('getValue')
93+
->with(Syslog::CONFIG_PATH)
94+
->willReturn('0');
95+
$this->deploymentConfigMock->expects($this->once())
96+
->method('isAvailable')
97+
->willReturn(true);
98+
99+
$this->assertFalse(
100+
$this->model->isHandling($record)
101+
);
102+
}
103+
}

app/code/Magento/Developer/etc/adminhtml/system.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
3333
</field>
3434
</group>
35+
<group id="syslog" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
36+
<label>Syslog</label>
37+
<field id="syslog_logging" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
38+
<label>Log to Syslog</label>
39+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
40+
</field>
41+
</group>
3542
</section>
3643
</system>
3744
</config>

app/code/Magento/Developer/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<preference for="Magento\Framework\Logger\Handler\Debug" type="Magento\Developer\Model\Logger\Handler\Debug"/>
10+
<preference for="Magento\Framework\Logger\Handler\Syslog" type="Magento\Developer\Model\Logger\Handler\Syslog"/>
1011

1112
<type name="Magento\Framework\View\Result\Page">
1213
<arguments>

app/etc/di.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,15 @@
249249
<argument name="handlers" xsi:type="array">
250250
<item name="system" xsi:type="object">Magento\Framework\Logger\Handler\System</item>
251251
<item name="debug" xsi:type="object">Magento\Framework\Logger\Handler\Debug</item>
252+
<item name="syslog" xsi:type="object">Magento\Framework\Logger\Handler\Syslog</item>
252253
</argument>
253254
</arguments>
254255
</type>
256+
<type name="Magento\Framework\Logger\Handler\Syslog">
257+
<arguments>
258+
<argument name="ident" xsi:type="string">Magento</argument>
259+
</arguments>
260+
</type>
255261
<type name="Magento\Framework\Model\Context">
256262
<arguments>
257263
<argument name="actionValidator" xsi:type="object">Magento\Framework\Model\ActionValidator\RemoveAction\Proxy</argument>

0 commit comments

Comments
 (0)