Skip to content

Commit 503643c

Browse files
committed
MAGETWO-53474: [Github] Caches Aren't Enabled by Default on RC1 with Composer when Upgrading via CLI
- Moving logic to re-enable cache to setup:upgrade
1 parent a5fa3af commit 503643c

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
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: 26 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,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
9497
if (!$keepGenerated) {
9598
$output->writeln('<info>Please re-run Magento compile command</info>');
9699
}
100+
101+
//TODO: to be removed in scope of MAGETWO-53476
102+
$writeFactory = $objectManager->get('\Magento\Framework\Filesystem\Directory\WriteFactory');
103+
$write = $writeFactory->create(BP);
104+
/** @var \Magento\Framework\App\Filesystem\DirectoryList $dirList */
105+
$dirList = $objectManager->get('\Magento\Framework\App\Filesystem\DirectoryList');
106+
107+
$pathToCacheStatus = $write->getRelativePath($dirList->getPath(DirectoryList::VAR_DIR) . '/.cachestates.json');
108+
109+
if ($write->isExist($pathToCacheStatus)) {
110+
$params = array_keys(json_decode($write->readFile($pathToCacheStatus), true));
111+
$command = $this->getApplication()->find('cache:enable');
112+
113+
$arguments = ['command' => 'cache:enable', AbstractCacheManageCommand::INPUT_KEY_TYPES => $params ];
114+
$returnCode = $command->run(new ArrayInput($arguments), $output);
115+
116+
$write->delete($pathToCacheStatus);
117+
if (isset($returnCode) && $returnCode > 0) {
118+
$output->writeln('<error> Error occured during upgrade</error>');
119+
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
120+
}
121+
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
122+
}
97123
}
98124
}

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()));

0 commit comments

Comments
 (0)