Skip to content

Commit 7003dff

Browse files
authored
Merge pull request #481 from magento-jackalopes/MAGETWO-58017-github-error-creating-configurable-products
Fixed issue: - MAGETWO-58017 [GITHUB] Error creating configurable products in 2.1.1 #6424
2 parents 2d8fb52 + 75e550e commit 7003dff

File tree

3 files changed

+172
-38
lines changed

3 files changed

+172
-38
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<template>
1212
<minify_html>0</minify_html>
1313
</template>
14+
<static>
15+
<sign>1</sign>
16+
</static>
1417
</dev>
1518
<system>
1619
<media_storage_configuration>

lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/VersionTest.php

Lines changed: 121 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66
namespace Magento\Framework\App\Test\Unit\View\Deployment;
77

8-
use \Magento\Framework\App\View\Deployment\Version;
8+
use Magento\Framework\App\View\Deployment\Version;
9+
use Magento\Framework\Exception\FileSystemException;
910

1011
/**
1112
* Class VersionTest
@@ -18,29 +19,39 @@ class VersionTest extends \PHPUnit_Framework_TestCase
1819
private $object;
1920

2021
/**
21-
* @var \PHPUnit_Framework_MockObject_MockObject
22+
* @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
2223
*/
23-
private $appState;
24+
private $appStateMock;
2425

2526
/**
26-
* @var \PHPUnit_Framework_MockObject_MockObject
27+
* @var \Magento\Framework\App\View\Deployment\Version\StorageInterface|\PHPUnit_Framework_MockObject_MockObject
2728
*/
28-
private $versionStorage;
29+
private $versionStorageMock;
30+
31+
/**
32+
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $loggerMock;
2935

3036
protected function setUp()
3137
{
32-
$this->appState = $this->getMock(\Magento\Framework\App\State::class, [], [], '', false);
33-
$this->versionStorage = $this->getMock(\Magento\Framework\App\View\Deployment\Version\StorageInterface::class);
34-
$this->object = new Version($this->appState, $this->versionStorage);
38+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
39+
$this->appStateMock = $this->getMock(\Magento\Framework\App\State::class, [], [], '', false);
40+
$this->versionStorageMock = $this->getMock(
41+
\Magento\Framework\App\View\Deployment\Version\StorageInterface::class
42+
);
43+
$this->loggerMock = $this->getMock(\Psr\Log\LoggerInterface::class);
44+
$this->object = new Version($this->appStateMock, $this->versionStorageMock);
45+
$objectManager->setBackwardCompatibleProperty($this->object, 'logger', $this->loggerMock);
3546
}
3647

3748
public function testGetValueDeveloperMode()
3849
{
39-
$this->appState
50+
$this->appStateMock
4051
->expects($this->once())
4152
->method('getMode')
4253
->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
43-
$this->versionStorage->expects($this->never())->method($this->anything());
54+
$this->versionStorageMock->expects($this->never())->method($this->anything());
4455
$this->assertInternalType('integer', $this->object->getValue());
4556
$this->object->getValue(); // Ensure computation occurs only once and result is cached in memory
4657
}
@@ -51,12 +62,12 @@ public function testGetValueDeveloperMode()
5162
*/
5263
public function testGetValueFromStorage($appMode)
5364
{
54-
$this->appState
65+
$this->appStateMock
5566
->expects($this->once())
5667
->method('getMode')
5768
->will($this->returnValue($appMode));
58-
$this->versionStorage->expects($this->once())->method('load')->will($this->returnValue('123'));
59-
$this->versionStorage->expects($this->never())->method('save');
69+
$this->versionStorageMock->expects($this->once())->method('load')->will($this->returnValue('123'));
70+
$this->versionStorageMock->expects($this->never())->method('save');
6071
$this->assertEquals('123', $this->object->getValue());
6172
$this->object->getValue(); // Ensure caching in memory
6273
}
@@ -70,20 +81,106 @@ public function getValueFromStorageDataProvider()
7081
];
7182
}
7283

73-
public function testGetValueDefaultModeSaving()
74-
{
84+
/**
85+
* $param bool $isUnexpectedValueExceptionThrown
86+
* $param bool $isFileSystemExceptionThrown
87+
* @dataProvider getValueDefaultModeDataProvider
88+
*/
89+
public function testGetValueDefaultMode(
90+
$isUnexpectedValueExceptionThrown,
91+
$isFileSystemExceptionThrown = null
92+
) {
7593
$versionType = 'integer';
76-
$this->appState
94+
$this->appStateMock
7795
->expects($this->once())
7896
->method('getMode')
79-
->will($this->returnValue(\Magento\Framework\App\State::MODE_DEFAULT));
80-
$storageException = new \UnexpectedValueException('Does not exist in the storage');
81-
$this->versionStorage
82-
->expects($this->once())
83-
->method('load')
84-
->will($this->throwException($storageException));
85-
$this->versionStorage->expects($this->once())->method('save')->with($this->isType($versionType));
97+
->willReturn(\Magento\Framework\App\State::MODE_DEFAULT);
98+
if ($isUnexpectedValueExceptionThrown) {
99+
$storageException = new \UnexpectedValueException('Does not exist in the storage');
100+
$this->versionStorageMock
101+
->expects($this->once())
102+
->method('load')
103+
->will($this->throwException($storageException));
104+
$this->versionStorageMock->expects($this->once())
105+
->method('save')
106+
->with($this->isType($versionType));
107+
if ($isFileSystemExceptionThrown) {
108+
$fileSystemException = new FileSystemException(
109+
new \Magento\Framework\Phrase('Can not load static content version')
110+
);
111+
$this->versionStorageMock
112+
->expects($this->once())
113+
->method('save')
114+
->will($this->throwException($fileSystemException));
115+
$this->loggerMock->expects($this->once())
116+
->method('critical')
117+
->with('Can not save static content version.');
118+
} else {
119+
$this->loggerMock->expects($this->never())
120+
->method('critical');
121+
}
122+
} else {
123+
$this->versionStorageMock
124+
->expects($this->once())
125+
->method('load')
126+
->willReturn(1475779229);
127+
$this->loggerMock->expects($this->never())
128+
->method('critical');
129+
}
86130
$this->assertInternalType($versionType, $this->object->getValue());
87-
$this->object->getValue(); // Ensure caching in memory
131+
$this->object->getValue();
132+
}
133+
134+
/**
135+
* @return array
136+
*/
137+
public function getValueDefaultModeDataProvider()
138+
{
139+
return [
140+
[false],
141+
[true, false],
142+
[true, true]
143+
];
144+
}
145+
146+
/**
147+
* @param bool $isUnexpectedValueExceptionThrown
148+
* @dataProvider getValueProductionModeDataProvider
149+
*/
150+
public function testGetValueProductionMode(
151+
$isUnexpectedValueExceptionThrown
152+
) {
153+
$this->appStateMock
154+
->expects($this->once())
155+
->method('getMode')
156+
->willReturn(\Magento\Framework\App\State::MODE_PRODUCTION);
157+
if ($isUnexpectedValueExceptionThrown) {
158+
$storageException = new \UnexpectedValueException('Does not exist in the storage');
159+
$this->versionStorageMock
160+
->expects($this->once())
161+
->method('load')
162+
->will($this->throwException($storageException));
163+
$this->loggerMock->expects($this->once())
164+
->method('critical')
165+
->with('Can not load static content version.');
166+
} else {
167+
$this->versionStorageMock
168+
->expects($this->once())
169+
->method('load')
170+
->willReturn(1475779229);
171+
}
172+
$this->assertInternalType('integer', $this->object->getValue());
173+
$this->object->getValue();
174+
}
175+
176+
/**
177+
* @return array
178+
*/
179+
public function getValueProductionModeDataProvider()
180+
{
181+
return [
182+
[false],
183+
[true],
184+
];
88185
}
89186
}

lib/internal/Magento/Framework/App/View/Deployment/Version.php

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Framework\App\View\Deployment;
88

9+
use Psr\Log\LoggerInterface;
10+
use Magento\Framework\Exception\FileSystemException;
11+
912
/**
1013
* Deployment version of static files
1114
*/
@@ -26,6 +29,11 @@ class Version
2629
*/
2730
private $cachedValue;
2831

32+
/**
33+
* @var LoggerInterface
34+
*/
35+
private $logger;
36+
2937
/**
3038
* @param \Magento\Framework\App\State $appState
3139
* @param Version\StorageInterface $versionStorage
@@ -59,23 +67,49 @@ public function getValue()
5967
*/
6068
protected function readValue($appMode)
6169
{
62-
switch ($appMode) {
63-
case \Magento\Framework\App\State::MODE_DEFAULT:
64-
try {
65-
$result = $this->versionStorage->load();
66-
} catch (\UnexpectedValueException $e) {
67-
$result = (new \DateTime())->getTimestamp();
68-
$this->versionStorage->save($result);
70+
if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) {
71+
$result = $this->generateVersion();
72+
} else {
73+
try {
74+
$result = $this->versionStorage->load();
75+
} catch (\UnexpectedValueException $e) {
76+
$result = $this->generateVersion();
77+
if ($appMode == \Magento\Framework\App\State::MODE_DEFAULT) {
78+
try {
79+
$this->versionStorage->save($result);
80+
} catch (FileSystemException $e) {
81+
$this->getLogger()->critical('Can not save static content version.');
82+
}
83+
} else {
84+
$this->getLogger()->critical('Can not load static content version.');
6985
}
70-
break;
86+
}
87+
}
88+
return $result;
89+
}
7190

72-
case \Magento\Framework\App\State::MODE_DEVELOPER:
73-
$result = (new \DateTime())->getTimestamp();
74-
break;
91+
/**
92+
* Generate version of static content
93+
*
94+
* @return int
95+
*/
96+
private function generateVersion()
97+
{
98+
return time();
99+
}
75100

76-
default:
77-
$result = $this->versionStorage->load();
101+
/**
102+
* Get logger
103+
*
104+
* @return LoggerInterface
105+
* @deprecated
106+
*/
107+
private function getLogger()
108+
{
109+
if ($this->logger == null) {
110+
$this->logger = \Magento\Framework\App\ObjectManager::getInstance()
111+
->get(LoggerInterface::class);
78112
}
79-
return $result;
113+
return $this->logger;
80114
}
81115
}

0 commit comments

Comments
 (0)