Skip to content

Commit 3371fbc

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-53474-Caches-Arent-Enabled' into PR_Branch
2 parents 8e1f666 + c840f1a commit 3371fbc

File tree

5 files changed

+59
-53
lines changed

5 files changed

+59
-53
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ public function __construct(DirectoryList $directoryList, WriteFactory $writeFac
5252
public function regenerate()
5353
{
5454
if ($this->write->isExist(self::REGENERATE_FLAG)) {
55+
//TODO: to be removed in scope of MAGETWO-53476
5556
//clean cache
5657
$deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG);
5758
$configPool = new ConfigFilePool();
5859
$envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
5960
if ($this->write->isExist($this->write->getRelativePath($envPath))) {
6061
$this->saveCacheStatus($envPath);
6162
}
63+
//TODO: Till here
6264
$cachePath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::CACHE));
6365
$generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
6466
$diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI));

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
*/
66
namespace Magento\Setup\Console\Command;
77

8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Backend\Console\Command\AbstractCacheManageCommand;
810
use Magento\Framework\ObjectManagerInterface;
911
use Magento\Framework\Setup\ConsoleLogger;
1012
use Magento\Setup\Model\InstallerFactory;
1113
use Magento\Setup\Model\ObjectManagerProvider;
14+
use Symfony\Component\Console\Input\ArrayInput;
1215
use Symfony\Component\Console\Input\InputInterface;
1316
use Symfony\Component\Console\Input\InputOption;
1417
use Symfony\Component\Console\Output\OutputInterface;
@@ -94,5 +97,40 @@ protected function execute(InputInterface $input, OutputInterface $output)
9497
if (!$keepGenerated) {
9598
$output->writeln('<info>Please re-run Magento compile command</info>');
9699
}
100+
101+
return $this->enableCaches($objectManager, $output);
102+
}
103+
104+
/**
105+
* Enables cache if cachestates exists
106+
* TODO: to be removed in scope of MAGETWO-53476
107+
*
108+
* @param \Magento\Framework\ObjectManagerInterface $objectManager
109+
* @param \Symfony\Component\Console\Output\OutputInterface $output
110+
* @return int
111+
*/
112+
private function enableCaches($objectManager, $output)
113+
{
114+
$writeFactory = $objectManager->get('Magento\Framework\Filesystem\Directory\WriteFactory');
115+
$write = $writeFactory->create(BP);
116+
/** @var \Magento\Framework\App\Filesystem\DirectoryList $dirList */
117+
$dirList = $objectManager->get('Magento\Framework\App\Filesystem\DirectoryList');
118+
119+
$pathToCacheStatus = $write->getRelativePath($dirList->getPath(DirectoryList::VAR_DIR) . '/.cachestates.json');
120+
121+
if ($write->isExist($pathToCacheStatus)) {
122+
$params = array_keys(json_decode($write->readFile($pathToCacheStatus), true));
123+
$command = $this->getApplication()->find('cache:enable');
124+
125+
$arguments = ['command' => 'cache:enable', AbstractCacheManageCommand::INPUT_KEY_TYPES => $params ];
126+
$returnCode = $command->run(new ArrayInput($arguments), $output);
127+
128+
$write->delete($pathToCacheStatus);
129+
if (isset($returnCode) && $returnCode > 0) {
130+
$output->writeln('<error> Error occured during upgrade</error>');
131+
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
132+
}
133+
}
134+
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
97135
}
98136
}

setup/src/Magento/Setup/Model/Cron/JobUpgrade.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\Setup\Model\Cron;
77

8-
use Magento\Framework\App\Filesystem\DirectoryList;
9-
use Magento\Framework\Filesystem;
108
use Magento\Setup\Console\Command\AbstractSetupCommand;
119
use Magento\Setup\Model\ObjectManagerProvider;
1210
use Symfony\Component\Console\Input\ArrayInput;
@@ -72,26 +70,6 @@ public function execute()
7270
);
7371
$this->params['command'] = 'setup:upgrade';
7472
$this->command->run(new ArrayInput($this->params), $this->output);
75-
76-
/**
77-
* @var \Magento\Framework\Filesystem\Directory\WriteFactory $writeFactory
78-
*/
79-
$writeFactory = $this->objectManager->get('\Magento\Framework\Filesystem\Directory\WriteFactory');
80-
$write = $writeFactory->create(BP);
81-
$dirList = $this->objectManager->get('\Magento\Framework\App\Filesystem\DirectoryList');
82-
$pathToCacheStatus = $write->getRelativePath(
83-
$dirList->getPath(DirectoryList::VAR_DIR) . '/.cachestates.json'
84-
);
85-
86-
if ($write->isExist($pathToCacheStatus)) {
87-
$params = array_keys(json_decode($write->readFile($pathToCacheStatus), true));
88-
89-
$this->queue->addJobs(
90-
[['name' => JobFactory::JOB_ENABLE_CACHE, 'params' => [implode(' ', $params)]]]
91-
);
92-
$write->delete($pathToCacheStatus);
93-
}
94-
9573
} catch (\Exception $e) {
9674
$this->status->toggleUpdateError(true);
9775
throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,31 @@ public function testExecute()
2020
$state = $this->getMock('Magento\Framework\App\State', [], [], '', false);
2121
$state->expects($this->once())->method('setAreaCode')->with('setup');
2222
$objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
23-
$objectManager->expects($this->exactly(2))
24-
->method('get')
25-
->will($this->returnValueMap([
26-
['Magento\Framework\App\State', $state],
27-
['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader],
28-
]));
2923
$objectManager->expects($this->once())->method('configure');
3024
$state->expects($this->once())->method('setAreaCode')->with('setup');
3125
$installer = $this->getMock('Magento\Setup\Model\Installer', [], [], '', false);
3226
$installer->expects($this->at(0))->method('updateModulesSequence');
3327
$installer->expects($this->at(1))->method('installSchema');
3428
$installer->expects($this->at(2))->method('installDataFixtures');
3529
$installerFactory->expects($this->once())->method('create')->willReturn($installer);
30+
31+
$pathToCacheStatus = '/path/to/cachefile';
32+
$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);
38+
$directoryList = $this->getMock('\Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
39+
$objectManager->expects($this->exactly(4))
40+
->method('get')
41+
->will($this->returnValueMap([
42+
['Magento\Framework\App\State', $state],
43+
['Magento\Framework\ObjectManager\ConfigLoaderInterface', $configLoader],
44+
['Magento\Framework\Filesystem\Directory\WriteFactory', $writeFactory],
45+
['Magento\Framework\App\Filesystem\DirectoryList', $directoryList],
46+
]));
47+
3648
$commandTester = new CommandTester(new UpgradeCommand($installerFactory, $objectManagerProvider));
3749
$commandTester->execute([]);
3850
}

setup/src/Magento/Setup/Test/Unit/Model/Cron/JobUpgradeTest.php

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class JobUpgradeTest extends \PHPUnit_Framework_TestCase
1212
public function testExecute()
1313
{
1414
$queue = $this->getMock('Magento\Setup\Model\Cron\Queue', [], [], '', false);
15-
$queue->expects($this->exactly(3))->method('addJobs');
15+
$queue->expects($this->exactly(2))->method('addJobs');
1616
$command = $this->getMock('Magento\Setup\Console\Command\UpgradeCommand', [], [], '', false);
1717
$command->expects($this->once())->method('run');
1818
$status = $this->getMock('Magento\Setup\Model\Cron\Status', [], [], '', false);
@@ -21,30 +21,6 @@ public function testExecute()
2121
$objectManagerProvider = $this->getMock('Magento\Setup\Model\ObjectManagerProvider', ['get'], [], '', false);
2222
$objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
2323

24-
$cleanupFiles = $this->getMock('\Magento\Framework\App\State\CleanupFiles', [], [], '', false);
25-
$cache = $this->getMock('\Magento\Framework\App\Cache', [], [], '', false);
26-
27-
$pathToCacheStatus = '/path/to/cachefile';
28-
$writeFactory = $this->getMock('\Magento\Framework\Filesystem\Directory\WriteFactory', [], [], '', false);
29-
$write = $this->getMock('\Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
30-
$write->expects($this->once())->method('isExist')->with('/path/to/cachefile')->willReturn(true);
31-
$write->expects($this->once())->method('readFile')->with('/path/to/cachefile')->willReturn(
32-
'{"cacheOne":1,"cacheTwo":1,"cacheThree":1}'
33-
);
34-
$write->expects($this->once())->method('delete')->with('/path/to/cachefile')->willReturn(true);
35-
$write->expects($this->once())->method('getRelativePath')->willReturn($pathToCacheStatus);
36-
37-
$writeFactory->expects($this->once())->method('create')->willReturn($write);
38-
$directoryList = $this->getMock('\Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
39-
$directoryList->expects($this->once())->method('getPath')->willReturn('/some/full/path' . $pathToCacheStatus);
40-
41-
$objectManager->expects($this->any())->method('get')->will($this->returnValueMap([
42-
['\Magento\Framework\Filesystem\Directory\WriteFactory', $writeFactory],
43-
['\Magento\Framework\App\Filesystem\DirectoryList', $directoryList],
44-
['\Magento\Framework\App\State\CleanupFiles', $cleanupFiles],
45-
['\Magento\Framework\App\Cache', $cache],
46-
]));
47-
4824
$jobUpgrade = new JobUpgrade(
4925
$command,
5026
$objectManagerProvider,

0 commit comments

Comments
 (0)