Skip to content

Commit 662cc45

Browse files
MAGETWO-69633: Redis sess: fix path for persistent_identifier & compression_threshold #9368
2 parents a8f0888 + 2af0504 commit 662cc45

File tree

9 files changed

+169
-123
lines changed

9 files changed

+169
-123
lines changed

app/code/Magento/Config/Console/Command/ConfigSet/LockProcessor.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Config\App\Config\Type\System;
99
use Magento\Config\Model\PreparedValueFactory;
1010
use Magento\Framework\App\Config\ConfigPathResolver;
11+
use Magento\Framework\App\Config\Value;
1112
use Magento\Framework\App\DeploymentConfig;
1213
use Magento\Framework\Config\File\ConfigFilePool;
1314
use Magento\Framework\Exception\CouldNotSaveException;
@@ -79,19 +80,27 @@ public function process($path, $value, $scope, $scopeCode)
7980
$configPath = $this->configPathResolver->resolve($path, $scope, $scopeCode, System::CONFIG_TYPE);
8081
$backendModel = $this->preparedValueFactory->create($path, $value, $scope, $scopeCode);
8182

82-
/**
83-
* Temporary solution until Magento introduce unified interface
84-
* for storing system configuration into database and configuration files.
85-
*/
86-
$backendModel->validateBeforeSave();
87-
$backendModel->beforeSave();
83+
if ($backendModel instanceof Value) {
84+
/**
85+
* Temporary solution until Magento introduce unified interface
86+
* for storing system configuration into database and configuration files.
87+
*/
88+
$backendModel->validateBeforeSave();
89+
$backendModel->beforeSave();
8890

89-
$this->deploymentConfigWriter->saveConfig(
90-
[ConfigFilePool::APP_ENV => $this->arrayManager->set($configPath, [], $backendModel->getValue())],
91-
false
92-
);
91+
$value = $backendModel->getValue();
9392

94-
$backendModel->afterSave();
93+
$backendModel->afterSave();
94+
95+
/**
96+
* Because FS does not support transactions,
97+
* we'll write value just after all validations are triggered.
98+
*/
99+
$this->deploymentConfigWriter->saveConfig(
100+
[ConfigFilePool::APP_ENV => $this->arrayManager->set($configPath, [], $value)],
101+
false
102+
);
103+
}
95104
} catch (\Exception $exception) {
96105
throw new CouldNotSaveException(__('%1', $exception->getMessage()), $exception);
97106
}

app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockProcessorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ public function testCustomException()
206206
->willReturn($this->valueMock);
207207
$this->arrayManagerMock->expects($this->never())
208208
->method('set');
209-
$this->valueMock->expects($this->never())
209+
$this->valueMock->expects($this->once())
210210
->method('getValue');
211211
$this->valueMock->expects($this->once())
212-
->method('validateBeforeSave')
212+
->method('afterSave')
213213
->willThrowException(new \Exception('Invalid values'));
214214
$this->deploymentConfigWriterMock->expects($this->never())
215215
->method('saveConfig');

dev/tests/integration/testsuite/Magento/Sitemap/Model/ResourceModel/Catalog/ProductTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Test class for \Magento\Sitemap\Model\ResourceModel\Catalog\Product.
1010
* - test products collection generation for sitemap
1111
*
12-
* @magentoDataFixtureBeforeTransaction Magento/CatalogSearch/_files/full_reindex.php
12+
* @magentoDataFixtureBeforeTransaction Magento/Catalog/_files/enable_reindex_schedule.php
1313
* @magentoDataFixture Magento/Sitemap/_files/sitemap_products.php
1414
*/
1515
class ProductTest extends \PHPUnit_Framework_TestCase

lib/internal/Magento/Framework/Console/Cli.php

Lines changed: 29 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\App\ProductMetadata;
1212
use Magento\Framework\App\State;
1313
use Magento\Framework\Composer\ComposerJsonFinder;
14-
use Magento\Framework\Exception\FileSystemException;
14+
use Magento\Framework\Console\Exception\GenerationDirectoryAccessException;
1515
use Magento\Framework\Filesystem\Driver\File;
1616
use Magento\Framework\ObjectManagerInterface;
1717
use Magento\Framework\Shell\ComplexParameter;
@@ -66,17 +66,27 @@ class Cli extends Console\Application
6666
/**
6767
* @param string $name the application name
6868
* @param string $version the application version
69+
* @SuppressWarnings(PHPMD.ExitExpression)
6970
*/
7071
public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
7172
{
72-
$configuration = require BP . '/setup/config/application.config.php';
73-
$bootstrapApplication = new Application();
74-
$application = $bootstrapApplication->bootstrap($configuration);
75-
$this->serviceManager = $application->getServiceManager();
73+
try {
74+
$configuration = require BP . '/setup/config/application.config.php';
75+
$bootstrapApplication = new Application();
76+
$application = $bootstrapApplication->bootstrap($configuration);
77+
$this->serviceManager = $application->getServiceManager();
78+
79+
$this->assertCompilerPreparation();
80+
$this->initObjectManager();
81+
$this->assertGenerationPermissions();
82+
} catch (\Exception $exception) {
83+
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
84+
$output->writeln(
85+
'<error>' . $exception->getMessage() . '</error>'
86+
);
7687

77-
$this->assertCompilerPreparation();
78-
$this->initObjectManager();
79-
$this->assertGenerationPermissions();
88+
exit(static::RETURN_FAILURE);
89+
}
8090

8191
if ($version == 'UNKNOWN') {
8292
$directoryList = new DirectoryList(BP);
@@ -91,20 +101,13 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
91101
/**
92102
* {@inheritdoc}
93103
*
94-
* @throws \Exception the exception in case of unexpected error
104+
* @throws \Exception The exception in case of unexpected error
95105
*/
96106
public function doRun(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
97107
{
98108
$exitCode = parent::doRun($input, $output);
99109

100110
if ($this->initException) {
101-
$output->writeln(
102-
"<error>We're sorry, an error occurred. Try clearing the cache and code generation directories. "
103-
. "By default, they are: " . $this->getDefaultDirectoryPath(DirectoryList::CACHE) . ", "
104-
. $this->getDefaultDirectoryPath(DirectoryList::GENERATED_METADATA) . ", "
105-
. $this->getDefaultDirectoryPath(DirectoryList::GENERATED_CODE) . ", and var/page_cache.</error>"
106-
);
107-
108111
throw $this->initException;
109112
}
110113

@@ -154,24 +157,17 @@ protected function getApplicationCommands()
154157
* Object Manager initialization.
155158
*
156159
* @return void
157-
* @SuppressWarnings(PHPMD.ExitExpression)
158160
*/
159161
private function initObjectManager()
160162
{
161-
try {
162-
$params = (new ComplexParameter(self::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER);
163-
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
164-
165-
$this->objectManager = Bootstrap::create(BP, $params)->getObjectManager();
163+
$params = (new ComplexParameter(self::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER);
164+
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
166165

167-
/** @var ObjectManagerProvider $omProvider */
168-
$omProvider = $this->serviceManager->get(ObjectManagerProvider::class);
169-
$omProvider->setObjectManager($this->objectManager);
170-
} catch (FileSystemException $exception) {
171-
$this->writeGenerationDirectoryReadError();
166+
$this->objectManager = Bootstrap::create(BP, $params)->getObjectManager();
172167

173-
exit(static::RETURN_FAILURE);
174-
}
168+
/** @var ObjectManagerProvider $omProvider */
169+
$omProvider = $this->serviceManager->get(ObjectManagerProvider::class);
170+
$omProvider->setObjectManager($this->objectManager);
175171
}
176172

177173
/**
@@ -182,7 +178,7 @@ private function initObjectManager()
182178
* developer - application will be terminated
183179
*
184180
* @return void
185-
* @SuppressWarnings(PHPMD.ExitExpression)
181+
* @throws GenerationDirectoryAccessException If generation directory is read-only in developer mode
186182
*/
187183
private function assertGenerationPermissions()
188184
{
@@ -197,17 +193,15 @@ private function assertGenerationPermissions()
197193
if ($state->getMode() !== State::MODE_PRODUCTION
198194
&& !$generationDirectoryAccess->check()
199195
) {
200-
$this->writeGenerationDirectoryReadError();
201-
202-
exit(static::RETURN_FAILURE);
196+
throw new GenerationDirectoryAccessException();
203197
}
204198
}
205199

206200
/**
207201
* Checks whether compiler is being prepared.
208202
*
209203
* @return void
210-
* @SuppressWarnings(PHPMD.ExitExpression)
204+
* @throws GenerationDirectoryAccessException If generation directory is read-only
211205
*/
212206
private function assertCompilerPreparation()
213207
{
@@ -222,33 +216,10 @@ private function assertCompilerPreparation()
222216
new File()
223217
);
224218

225-
try {
226-
$compilerPreparation->handleCompilerEnvironment();
227-
} catch (FileSystemException $e) {
228-
$this->writeGenerationDirectoryReadError();
229-
230-
exit(static::RETURN_FAILURE);
231-
}
219+
$compilerPreparation->handleCompilerEnvironment();
232220
}
233221
}
234222

235-
/**
236-
* Writes read error to console.
237-
*
238-
* @return void
239-
*/
240-
private function writeGenerationDirectoryReadError()
241-
{
242-
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
243-
$output->writeln(
244-
'<error>'
245-
. 'Command line user does not have read and write permissions on '
246-
. $this->getDefaultDirectoryPath(DirectoryList::GENERATED_CODE) . ' directory. '
247-
. 'Please address this issue before using Magento command line.'
248-
. '</error>'
249-
);
250-
}
251-
252223
/**
253224
* Retrieves vendor commands.
254225
*
@@ -270,22 +241,4 @@ protected function getVendorCommands($objectManager)
270241

271242
return $commands;
272243
}
273-
274-
/**
275-
* Get default directory path by code
276-
*
277-
* @param string $code
278-
* @return string
279-
*/
280-
private function getDefaultDirectoryPath($code)
281-
{
282-
$config = DirectoryList::getDefaultConfig();
283-
$result = '';
284-
285-
if (isset($config[$code][DirectoryList::PATH])) {
286-
$result = $config[$code][DirectoryList::PATH];
287-
}
288-
289-
return $result;
290-
}
291244
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Console\Exception;
7+
8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\Exception\FileSystemException;
10+
use Magento\Framework\Phrase;
11+
12+
/**
13+
* The default exception for missing write permissions on compilation generated folder.
14+
*/
15+
class GenerationDirectoryAccessException extends FileSystemException
16+
{
17+
/**
18+
* @inheritdoc
19+
*/
20+
public function __construct(Phrase $phrase = null, \Exception $cause = null, $code = 0)
21+
{
22+
$phrase = $phrase ?: new Phrase(
23+
'Command line user does not have read and write permissions on '
24+
. $this->getDefaultDirectoryPath(DirectoryList::GENERATED) . ' directory. '
25+
. 'Please address this issue before using Magento command line.'
26+
);
27+
28+
parent::__construct($phrase, $cause, $code);
29+
}
30+
31+
/**
32+
* Get default directory path by code
33+
*
34+
* @param string $code
35+
* @return string
36+
*/
37+
private function getDefaultDirectoryPath($code)
38+
{
39+
$config = DirectoryList::getDefaultConfig();
40+
$result = '';
41+
42+
if (isset($config[$code][DirectoryList::PATH])) {
43+
$result = $config[$code][DirectoryList::PATH];
44+
}
45+
46+
return $result;
47+
}
48+
}

lib/internal/Magento/Framework/Console/GenerationDirectoryAccess.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
use Magento\Framework\App\Bootstrap;
99
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Filesystem\Directory\WriteFactory;
1011
use Magento\Framework\Filesystem\DriverPool;
11-
use Magento\Framework\Filesystem\File\WriteFactory;
12-
use Magento\Framework\Filesystem\Directory\Write;
1312
use Zend\ServiceManager\ServiceManager;
1413
use Magento\Setup\Mvc\Bootstrap\InitParamListener;
1514

@@ -33,7 +32,7 @@ public function __construct(
3332
}
3433

3534
/**
36-
* Check generated/code read and write access
35+
* Check write permissions to generation folders
3736
*
3837
* @return bool
3938
*/
@@ -44,33 +43,32 @@ public function check()
4443
? $initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]
4544
: [];
4645
$directoryList = new DirectoryList(BP, $filesystemDirPaths);
47-
$generationDirectoryPath = $directoryList->getPath(DirectoryList::GENERATED_CODE);
4846
$driverPool = new DriverPool();
4947
$fileWriteFactory = new WriteFactory($driverPool);
50-
/** @var \Magento\Framework\Filesystem\DriverInterface $driver */
51-
$driver = $driverPool->getDriver(DriverPool::FILE);
52-
$directoryWrite = new Write($fileWriteFactory, $driver, $generationDirectoryPath);
53-
if ($directoryWrite->isExist()) {
54-
if ($directoryWrite->isDirectory()
55-
|| $directoryWrite->isReadable()
56-
) {
48+
49+
$generationDirs = [
50+
DirectoryList::GENERATED,
51+
DirectoryList::GENERATED_CODE,
52+
DirectoryList::GENERATED_METADATA
53+
];
54+
55+
foreach ($generationDirs as $generationDirectory) {
56+
$directoryPath = $directoryList->getPath($generationDirectory);
57+
$directoryWrite = $fileWriteFactory->create($directoryPath);
58+
59+
if (!$directoryWrite->isExist()) {
5760
try {
58-
$probeFilePath = $generationDirectoryPath . DIRECTORY_SEPARATOR . uniqid(mt_rand()).'tmp';
59-
$fileWriteFactory->create($probeFilePath, DriverPool::FILE, 'w');
60-
$driver->deleteFile($probeFilePath);
61+
$directoryWrite->create();
6162
} catch (\Exception $e) {
6263
return false;
6364
}
64-
} else {
65-
return false;
6665
}
67-
} else {
68-
try {
69-
$directoryWrite->create();
70-
} catch (\Exception $e) {
66+
67+
if (!$directoryWrite->isWritable()) {
7168
return false;
7269
}
7370
}
71+
7472
return true;
7573
}
7674
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Console\Test\Unit\Exception;
7+
8+
use Magento\Framework\Console\Exception\GenerationDirectoryAccessException;
9+
10+
class GenerationDirectoryAccessExceptionTest extends \PHPUnit_Framework_TestCase
11+
{
12+
public function testConstructor()
13+
{
14+
$exception = new GenerationDirectoryAccessException();
15+
16+
$this->assertContains(
17+
'Command line user does not have read and write permissions on generated directory.',
18+
$exception->getMessage()
19+
);
20+
}
21+
}

0 commit comments

Comments
 (0)