Skip to content

Commit 5af617e

Browse files
committed
Merge branch '2.2-develop' of github.com:magento/magento2ce into MAGETWO-68787
2 parents 55a776a + 6ba5991 commit 5af617e

File tree

9 files changed

+427
-17
lines changed

9 files changed

+427
-17
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/widget/viewed/sidebar.phtml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
'listing' => [
1818
'displayMode' => 'grid'
1919
],
20-
'column' => [
21-
'image' => [
22-
'imageCode' => 'recently_viewed_products_images_names_widget'
23-
]
20+
'image' => [
21+
'imageCode' => 'recently_viewed_products_images_names_widget'
2422
]
2523
]
2624
);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\App\Mode;
7+
8+
/**
9+
* This class is responsible for providing configuration while switching application mode
10+
*/
11+
class ConfigProvider
12+
{
13+
/**
14+
* Configuration for combinations of $currentMode and $targetMode
15+
* For example:
16+
* [
17+
* 'developer' => [
18+
* 'production' => [
19+
* {{setting_path}} => {{setting_value}}
20+
* ]
21+
* ]
22+
* ]
23+
*
24+
* @var array
25+
*/
26+
private $config;
27+
28+
/**
29+
* @param array $config
30+
*/
31+
public function __construct(array $config = [])
32+
{
33+
$this->config = $config;
34+
}
35+
36+
/**
37+
* Provide configuration while switching from $currentMode to $targetMode
38+
* This method used in \Magento\Deploy\Model\Mode::setStoreMode
39+
*
40+
* For example: while switching from developer mode to production mode
41+
* need to turn off 'dev/debug/debug_logging' setting in this case method
42+
* will return array
43+
* [
44+
* {{setting_path}} => {{setting_value}}
45+
* ]
46+
*
47+
* @param string $currentMode
48+
* @param string $targetMode
49+
* @return array
50+
*/
51+
public function getConfigs($currentMode, $targetMode)
52+
{
53+
if (isset($this->config[$currentMode][$targetMode])) {
54+
return $this->config[$currentMode][$targetMode];
55+
}
56+
return [];
57+
}
58+
}

app/code/Magento/Deploy/Model/Mode.php

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Deploy\Model;
88

9+
use Magento\Deploy\App\Mode\ConfigProvider;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
911
use Magento\Framework\App\DeploymentConfig\Reader;
1012
use Magento\Framework\App\DeploymentConfig\Writer;
1113
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -14,7 +16,10 @@
1416
use Magento\Framework\Config\File\ConfigFilePool;
1517
use Symfony\Component\Console\Input\InputInterface;
1618
use Symfony\Component\Console\Output\OutputInterface;
19+
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
20+
use Magento\Config\Console\Command\EmulatedAdminhtmlAreaProcessor;
1721
use Magento\Framework\Exception\LocalizedException;
22+
use Magento\Framework\App\ObjectManager;
1823

1924
/**
2025
* A class to manage Magento modes
@@ -44,33 +49,70 @@ class Mode
4449
*/
4550
private $reader;
4651

52+
/**
53+
* @var MaintenanceMode
54+
*/
55+
private $maintenanceMode;
56+
4757
/**
4858
* @var Filesystem
4959
*/
5060
private $filesystem;
5161

62+
/**
63+
* @var ConfigProvider
64+
*/
65+
private $configProvider;
66+
67+
/**
68+
* The factory for processor facade.
69+
*
70+
* @var ProcessorFacadeFactory
71+
*/
72+
private $processorFacadeFactory;
73+
74+
/**
75+
* Emulator adminhtml area for CLI command.
76+
*
77+
* @var EmulatedAdminhtmlAreaProcessor
78+
*/
79+
private $emulatedAreaProcessor;
80+
5281
/**
5382
* @param InputInterface $input
5483
* @param OutputInterface $output
5584
* @param Writer $writer
5685
* @param Reader $reader
5786
* @param MaintenanceMode $maintenanceMode
5887
* @param Filesystem $filesystem
88+
* @param ConfigProvider $configProvider
89+
* @param ProcessorFacadeFactory $processorFacadeFactory
90+
* @param EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor
5991
*/
6092
public function __construct(
6193
InputInterface $input,
6294
OutputInterface $output,
6395
Writer $writer,
6496
Reader $reader,
6597
MaintenanceMode $maintenanceMode,
66-
Filesystem $filesystem
98+
Filesystem $filesystem,
99+
ConfigProvider $configProvider = null,
100+
ProcessorFacadeFactory $processorFacadeFactory = null,
101+
EmulatedAdminhtmlAreaProcessor $emulatedAreaProcessor = null
67102
) {
68103
$this->input = $input;
69104
$this->output = $output;
70105
$this->writer = $writer;
71106
$this->reader = $reader;
72107
$this->maintenanceMode = $maintenanceMode;
73108
$this->filesystem = $filesystem;
109+
110+
$this->configProvider =
111+
$configProvider ?: ObjectManager::getInstance()->get(ConfigProvider::class);
112+
$this->processorFacadeFactory =
113+
$processorFacadeFactory ?: ObjectManager::getInstance()->get(ProcessorFacadeFactory::class);
114+
$this->emulatedAreaProcessor =
115+
$emulatedAreaProcessor ?: ObjectManager::getInstance()->get(EmulatedAdminhtmlAreaProcessor::class);
74116
}
75117

76118
/**
@@ -145,6 +187,7 @@ public function getMode()
145187
*/
146188
protected function setStoreMode($mode)
147189
{
190+
$this->saveAppConfigs($mode);
148191
$data = [
149192
ConfigFilePool::APP_ENV => [
150193
State::PARAM_MODE => $mode
@@ -153,6 +196,29 @@ protected function setStoreMode($mode)
153196
$this->writer->saveConfig($data);
154197
}
155198

199+
/**
200+
* Save application configs while switching mode
201+
*
202+
* @param string $mode
203+
* @return void
204+
*/
205+
private function saveAppConfigs($mode)
206+
{
207+
$configs = $this->configProvider->getConfigs($this->getMode(), $mode);
208+
foreach ($configs as $path => $value) {
209+
$this->emulatedAreaProcessor->process(function () use ($path, $value) {
210+
$this->processorFacadeFactory->create()->process(
211+
$path,
212+
$value,
213+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
214+
null,
215+
true
216+
);
217+
});
218+
$this->output->writeln('Config "' . $path . ' = ' . $value . '" has been saved.');
219+
}
220+
}
221+
156222
/**
157223
* Enable maintenance mode
158224
*
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Deploy\Test\Unit\App\Mode;
7+
8+
use Magento\Deploy\App\Mode\ConfigProvider;
9+
10+
class ConfigProviderTest extends \PHPUnit\Framework\TestCase
11+
{
12+
public function testGetConfigs()
13+
{
14+
$expectedValue = [
15+
'{{setting_path}}' => '{{setting_value}}'
16+
];
17+
$configProvider = new ConfigProvider(
18+
[
19+
'developer' => [
20+
'production' => $expectedValue
21+
]
22+
]
23+
);
24+
$this->assertEquals($expectedValue, $configProvider->getConfigs('developer', 'production'));
25+
$this->assertEquals([], $configProvider->getConfigs('undefined', 'production'));
26+
}
27+
}

app/code/Magento/Deploy/Test/Unit/Model/ModeTest.php

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
*/
66
namespace Magento\Deploy\Test\Unit\Model;
77

8+
use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
9+
use Magento\Config\Console\Command\ConfigSet\ProcessorFacade;
10+
use Magento\Config\Console\Command\EmulatedAdminhtmlAreaProcessor;
11+
use Magento\Deploy\App\Mode\ConfigProvider;
812
use Magento\Deploy\Model\Filesystem;
913
use Magento\Deploy\Model\Mode;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
1015
use Magento\Framework\App\DeploymentConfig\Reader;
1116
use Magento\Framework\App\DeploymentConfig\Writer;
1217
use Magento\Framework\App\MaintenanceMode;
@@ -19,6 +24,7 @@
1924

2025
/**
2126
* @inheritdoc
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2228
*/
2329
class ModeTest extends \PHPUnit\Framework\TestCase
2430
{
@@ -57,6 +63,26 @@ class ModeTest extends \PHPUnit\Framework\TestCase
5763
*/
5864
private $filesystemMock;
5965

66+
/**
67+
* @var ConfigProvider|Mock
68+
*/
69+
private $configProvider;
70+
71+
/**
72+
* @var ProcessorFacadeFactory|Mock
73+
*/
74+
private $processorFacadeFactory;
75+
76+
/**
77+
* @var ProcessorFacade|Mock
78+
*/
79+
private $processorFacade;
80+
81+
/**
82+
* @var EmulatedAdminhtmlAreaProcessor|Mock
83+
*/
84+
private $emulatedAreaProcessor;
85+
6086
protected function setUp()
6187
{
6288
$this->inputMock = $this->getMockBuilder(InputInterface::class)
@@ -75,14 +101,30 @@ protected function setUp()
75101
$this->filesystemMock = $this->getMockBuilder(Filesystem::class)
76102
->disableOriginalConstructor()
77103
->getMock();
104+
$this->configProvider = $this->getMockBuilder(ConfigProvider::class)
105+
->disableOriginalConstructor()
106+
->getMock();
107+
$this->processorFacadeFactory = $this->getMockBuilder(ProcessorFacadeFactory::class)
108+
->disableOriginalConstructor()
109+
->setMethods(['create'])
110+
->getMockForAbstractClass();
111+
$this->processorFacade = $this->getMockBuilder(ProcessorFacade::class)
112+
->disableOriginalConstructor()
113+
->getMock();
114+
$this->emulatedAreaProcessor = $this->getMockBuilder(EmulatedAdminhtmlAreaProcessor::class)
115+
->disableOriginalConstructor()
116+
->getMock();
78117

79118
$this->model = new Mode(
80119
$this->inputMock,
81120
$this->outputMock,
82121
$this->writerMock,
83122
$this->readerMock,
84123
$this->maintenanceMock,
85-
$this->filesystemMock
124+
$this->filesystemMock,
125+
$this->configProvider,
126+
$this->processorFacadeFactory,
127+
$this->emulatedAreaProcessor
86128
);
87129
}
88130

@@ -112,6 +154,9 @@ public function testEnableProductionMode()
112154
State::PARAM_MODE => State::MODE_DEVELOPER,
113155
],
114156
];
157+
$this->configProvider->expects($this->any())
158+
->method('getConfigs')
159+
->willReturn([]);
115160
$this->writerMock->expects($this->once())
116161
->method("saveConfig")
117162
->willReturnCallback(function ($data) use (&$dataStorage) {
@@ -145,6 +190,12 @@ public function testEnableDeveloperModeOnFail()
145190
State::PARAM_MODE => State::MODE_DEVELOPER,
146191
],
147192
];
193+
$this->readerMock->expects($this->any())
194+
->method('load')
195+
->willReturn([State::PARAM_MODE => State::MODE_DEVELOPER]);
196+
$this->configProvider->expects($this->any())
197+
->method('getConfigs')
198+
->willReturn([]);
148199
$this->writerMock->expects($this->exactly(2))
149200
->method("saveConfig")
150201
->withConsecutive(
@@ -165,4 +216,41 @@ public function testEnableDeveloperModeOnFail()
165216
$this->model->enableProductionMode();
166217
$this->assertEquals(State::MODE_PRODUCTION, $mode);
167218
}
219+
220+
public function testEnableProductionModeMinimal()
221+
{
222+
$this->readerMock->expects($this->once())
223+
->method('load')
224+
->willReturn([State::PARAM_MODE => State::MODE_DEVELOPER]);
225+
$this->configProvider->expects($this->once())
226+
->method('getConfigs')
227+
->with('developer', 'production')
228+
->willReturn([
229+
'dev/debug/debug_logging' => 0
230+
]);
231+
$this->emulatedAreaProcessor->expects($this->once())
232+
->method('process')
233+
->willReturnCallback(function (\Closure $closure) {
234+
return $closure->call($this->model);
235+
});
236+
237+
$this->processorFacadeFactory->expects($this->once())
238+
->method('create')
239+
->willReturn($this->processorFacade);
240+
$this->processorFacade
241+
->expects($this->once())
242+
->method('process')
243+
->with(
244+
'dev/debug/debug_logging',
245+
0,
246+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
247+
null,
248+
true
249+
);
250+
$this->outputMock->expects($this->once())
251+
->method('writeln')
252+
->with('Config "dev/debug/debug_logging = 0" has been saved.');
253+
254+
$this->model->enableProductionModeMinimal();
255+
}
168256
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,15 @@
7070
</argument>
7171
</arguments>
7272
</type>
73+
<type name="Magento\Deploy\App\Mode\ConfigProvider">
74+
<arguments>
75+
<argument name="config" xsi:type="array">
76+
<item name="developer" xsi:type="array">
77+
<item name="production" xsi:type="array">
78+
<item name="dev/debug/debug_logging" xsi:type="string">0</item>
79+
</item>
80+
</item>
81+
</argument>
82+
</arguments>
83+
</type>
7384
</config>

app/code/Magento/Developer/Model/Logger/Handler/Debug.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public function isHandling(array $record)
6060
if ($this->deploymentConfig->isAvailable()) {
6161
return
6262
parent::isHandling($record)
63-
&& $this->state->getMode() !== State::MODE_PRODUCTION
6463
&& $this->scopeConfig->getValue('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE);
6564
}
6665

0 commit comments

Comments
 (0)