Skip to content

Commit 3591ce8

Browse files
committed
MAGETWO-54205: After Disable/Enable Magento modules via CLI all cache types become disabled
1 parent 339609d commit 3591ce8

File tree

3 files changed

+52
-61
lines changed

3 files changed

+52
-61
lines changed

lib/internal/Magento/Framework/Code/GeneratedFiles.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public function cleanGeneratedFiles()
5757
$configPool = new ConfigFilePool();
5858
$envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
5959
if ($this->write->isExist($this->write->getRelativePath($envPath))) {
60-
$this->saveCacheConfiguration($envPath);
61-
$this->disableAllCacheTypes($envPath);
60+
$this->saveCacheConfiguration();
61+
$this->disableAllCacheTypes();
6262
}
6363
//TODO: Till here
6464

@@ -81,7 +81,7 @@ public function cleanGeneratedFiles()
8181
$this->write->delete($cachePath);
8282
}
8383
$this->write->delete(self::REGENERATE_FLAG);
84-
$this->reEnableCacheTypes($envPath);
84+
$this->reEnableCacheTypes();
8585
}
8686
}
8787

@@ -97,13 +97,13 @@ public function requestRegeneration()
9797
}
9898

9999
/**
100-
* Read Cache configuration from env.php and write to a json file.
100+
* Reads Cache configuration from env.php and write to a json file.
101101
*
102-
* @param string $envPath
103102
* @return void
104103
*/
105-
private function saveCacheConfiguration($envPath)
104+
public function saveCacheConfiguration()
106105
{
106+
$envPath = $this->GetEnvPath();
107107
$envData = include $envPath;
108108

109109
if (isset($envData['cache_types'])) {
@@ -121,13 +121,27 @@ private function saveCacheConfiguration($envPath)
121121
}
122122

123123
/**
124-
* Disable all cache types by updating env.php.
124+
* Returns path to env.php file
125+
*
126+
* @return string
127+
* @throws \Exception
128+
*/
129+
private function GetEnvPath()
130+
{
131+
$deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG);
132+
$configPool = new ConfigFilePool();
133+
$envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
134+
return $envPath;
135+
}
136+
137+
/**
138+
* Disables all cache types by updating env.php.
125139
*
126-
* @param string $envPath
127140
* @return void
128141
*/
129-
private function disableAllCacheTypes($envPath)
142+
private function disableAllCacheTypes()
130143
{
144+
$envPath = $this->GetEnvPath();
131145
$envData = include $envPath;
132146

133147
if (isset($envData['cache_types'])) {
@@ -155,7 +169,7 @@ private function disableAllCacheTypes($envPath)
155169
*
156170
* @return void
157171
*/
158-
private function reEnableCacheTypes($envPath)
172+
private function reEnableCacheTypes()
159173
{
160174
$pathToCacheStatus = $this->write->getRelativePath(
161175
$this->directoryList->getPath(DirectoryList::VAR_DIR) . '/.cachestates.json'
@@ -164,6 +178,7 @@ private function reEnableCacheTypes($envPath)
164178
if ($this->write->isExist($pathToCacheStatus)) {
165179
$enabledCacheTypes = array_keys(json_decode($this->write->readFile($pathToCacheStatus), true));
166180

181+
$envPath = $this->GetEnvPath();
167182
$envData = include $envPath;
168183
foreach ($enabledCacheTypes as $cacheType) {
169184
$envData['cache_types'][$cacheType] = 1;
@@ -178,7 +193,6 @@ private function reEnableCacheTypes($envPath)
178193
$this->write->getAbsolutePath($envPath)
179194
);
180195
}
181-
$this->write->delete($pathToCacheStatus);
182196
}
183197
}
184198
}

setup/src/Magento/Setup/Console/Command/UpgradeCommand.php

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
*/
66
namespace Magento\Setup\Console\Command;
77

8-
use Magento\Framework\App\Filesystem\DirectoryList;
9-
use Magento\Backend\Console\Command\AbstractCacheManageCommand;
10-
use Magento\Framework\ObjectManagerInterface;
118
use Magento\Framework\Setup\ConsoleLogger;
129
use Magento\Setup\Model\InstallerFactory;
1310
use Magento\Setup\Model\ObjectManagerProvider;
1411
use Symfony\Component\Console\Input\ArrayInput;
1512
use Symfony\Component\Console\Input\InputInterface;
1613
use Symfony\Component\Console\Input\InputOption;
1714
use Symfony\Component\Console\Output\OutputInterface;
15+
use Magento\Framework\Code\GeneratedFiles;
1816

1917
/**
2018
* Command for updating installed application after the code base has changed
@@ -34,11 +32,14 @@ class UpgradeCommand extends AbstractSetupCommand
3432
private $installerFactory;
3533

3634
/**
37-
* Object Manager
38-
*
39-
* @var ObjectManagerProvider
35+
* @var \Magento\Framework\ObjectManagerInterface
4036
*/
41-
private $objectManagerProvider;
37+
private $objectManager;
38+
39+
/**
40+
* @var GeneratedFiles
41+
*/
42+
private $generatedFiles;
4243

4344
/**
4445
* Constructor
@@ -49,7 +50,8 @@ class UpgradeCommand extends AbstractSetupCommand
4950
public function __construct(InstallerFactory $installerFactory, ObjectManagerProvider $objectManagerProvider)
5051
{
5152
$this->installerFactory = $installerFactory;
52-
$this->objectManagerProvider = $objectManagerProvider;
53+
/** @var \Magento\Framework\ObjectManagerInterface objectManager */
54+
$this->objectManager = $objectManagerProvider->get();
5355
parent::__construct();
5456
}
5557

@@ -79,15 +81,14 @@ protected function configure()
7981
*/
8082
protected function execute(InputInterface $input, OutputInterface $output)
8183
{
82-
/** @var \Magento\Framework\ObjectManagerInterface $objectManager */
83-
$objectManager = $this->objectManagerProvider->get();
84+
$this->getGeneratedFiles()->requestRegeneration();
8485
$areaCode = 'setup';
8586
/** @var \Magento\Framework\App\State $appState */
86-
$appState = $objectManager->get('Magento\Framework\App\State');
87+
$appState = $this->objectManager->get('Magento\Framework\App\State');
8788
$appState->setAreaCode($areaCode);
8889
/** @var \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader */
89-
$configLoader = $objectManager->get('Magento\Framework\ObjectManager\ConfigLoaderInterface');
90-
$objectManager->configure($configLoader->load($areaCode));
90+
$configLoader = $this->objectManager->get('Magento\Framework\ObjectManager\ConfigLoaderInterface');
91+
$this->objectManager->configure($configLoader->load($areaCode));
9192

9293
$keepGenerated = $input->getOption(self::INPUT_KEY_KEEP_GENERATED);
9394
$installer = $this->installerFactory->create(new ConsoleLogger($output));
@@ -98,41 +99,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
9899
$output->writeln('<info>Please re-run Magento compile command</info>');
99100
}
100101

101-
return $this->enableCaches($objectManager, $output);
102+
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
102103
}
103104

104105
/**
105-
* Enables cache if cachestates exists
106-
* TODO: to be removed in scope of MAGETWO-53476
106+
* Get deployment config
107107
*
108-
* @param \Magento\Framework\ObjectManagerInterface $objectManager
109-
* @param \Symfony\Component\Console\Output\OutputInterface $output
110-
* @return int
108+
* @return GeneratedFiles
109+
* @deprecated
111110
*/
112-
private function enableCaches($objectManager, $output)
111+
private function getGeneratedFiles()
113112
{
114-
$writeFactory = $objectManager->get('Magento\Framework\Filesystem\Directory\WriteFactory');
115-
/** @var \Magento\Framework\Filesystem\Directory\Write $write */
116-
$write = $writeFactory->create(BP);
117-
/** @var \Magento\Framework\App\Filesystem\DirectoryList $dirList */
118-
$dirList = $objectManager->get('Magento\Framework\App\Filesystem\DirectoryList');
119-
120-
$pathToCacheStatus = $write->getRelativePath($dirList->getPath(DirectoryList::VAR_DIR) . '/.cachestates.json');
121-
122-
if ($write->isExist($pathToCacheStatus)) {
123-
$params = array_keys(json_decode($write->readFile($pathToCacheStatus), true));
124-
$command = $this->getApplication()->find('cache:enable');
125-
126-
$arguments = ['command' => 'cache:enable', AbstractCacheManageCommand::INPUT_KEY_TYPES => $params ];
127-
$returnCode = $command->run(new ArrayInput($arguments), $output);
128-
129-
$write->delete($pathToCacheStatus);
130-
if (isset($returnCode) && $returnCode > 0) {
131-
$message = '<error> Error occured during upgrade. Error code: ' . $returnCode . '</error>';
132-
$output->writeln($message);
133-
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
134-
}
113+
if (!($this->generatedFiles instanceof GeneratedFiles)) {
114+
return $this->objectManager->get(GeneratedFiles::class);
135115
}
136-
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
116+
return $this->generatedFiles;
137117
}
138118
}

setup/src/Magento/Setup/Test/Unit/Console/Command/UpgradeCommandTest.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,19 @@ public function testExecute()
2727
$installer->expects($this->at(1))->method('installSchema');
2828
$installer->expects($this->at(2))->method('installDataFixtures');
2929
$installerFactory->expects($this->once())->method('create')->willReturn($installer);
30-
31-
$pathToCacheStatus = '/path/to/cachefile';
3230
$writeFactory = $this->getMock('\Magento\Framework\Filesystem\Directory\WriteFactory', [], [], '', false);
33-
$write = $this->getMock('\Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
34-
$write->expects($this->once())->method('isExist')->with('/path/to/cachefile')->willReturn(false);
35-
$write->expects($this->once())->method('getRelativePath')->willReturn($pathToCacheStatus);
36-
37-
$writeFactory->expects($this->once())->method('create')->willReturn($write);
3831
$directoryList = $this->getMock('\Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
39-
$objectManager->expects($this->exactly(4))
32+
$generatedFiles = $this->getMock('\Magento\Framework\Code\GeneratedFiles', [], [], '', false);
33+
$generatedFiles->expects($this->once())->method('requestRegeneration');
34+
35+
$objectManager->expects($this->exactly(3))
4036
->method('get')
4137
->will($this->returnValueMap([
4238
['Magento\Framework\App\State', $state],
4339
['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader],
4440
['Magento\Framework\Filesystem\Directory\WriteFactory', $writeFactory],
4541
['Magento\Framework\App\Filesystem\DirectoryList', $directoryList],
42+
['Magento\Framework\Code\GeneratedFiles', $generatedFiles]
4643
]));
4744

4845
$commandTester = new CommandTester(new UpgradeCommand($installerFactory, $objectManagerProvider));

0 commit comments

Comments
 (0)