Skip to content

Commit 28b1eb3

Browse files
committed
MAGETWO-52000: [Github][PR]impossible to see what is wrong with cron - unhelpful error message #3189
- fixing upgrade
1 parent 0ee021a commit 28b1eb3

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
*/
66
namespace Magento\Framework\Code;
77

8+
use Magento\Framework\Config\Data\ConfigData;
89
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Config\File\ConfigFilePool;
911
use Magento\Framework\Filesystem\Directory\WriteFactory;
1012
use Magento\Framework\Filesystem\Directory\WriteInterface;
13+
use Magento\Framework\App\DeploymentConfig\Writer\PhpFormatter;
1114

1215
/**
1316
* Regenerates generated code and DI configuration
@@ -49,6 +52,43 @@ public function __construct(DirectoryList $directoryList, WriteFactory $writeFac
4952
public function regenerate()
5053
{
5154
if ($this->write->isExist(self::REGENERATE_FLAG)) {
55+
//clean cache
56+
$deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG);
57+
$configPool = new ConfigFilePool();
58+
$envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
59+
if ($this->write->isExist($this->write->getRelativePath($envPath))) {
60+
$cacheData = include $envPath;
61+
62+
if (isset($cacheData['cache_types'])) {
63+
$enabledCacheTypes = $cacheData['cache_types'];
64+
$enabledCacheTypes = array_filter($enabledCacheTypes, function ($value) {
65+
return $value;
66+
}
67+
);
68+
if (!empty($enabledCacheTypes)) {
69+
$this->write->writeFile($this->write->getRelativePath(
70+
$this->directoryList->getPath(DirectoryList::VAR_DIR)) . '/.cachestates.json',
71+
json_encode($enabledCacheTypes)
72+
);
73+
$cacheTypes = array_keys($cacheData['cache_types']);
74+
75+
foreach ($cacheTypes as $cacheType) {
76+
$cacheData['cache_types'][$cacheType] = 0;
77+
}
78+
79+
$formatter = new PhpFormatter();
80+
$contents = $formatter->format($cacheData);
81+
82+
$this->write->writeFile($this->write->getRelativePath($envPath), $contents);
83+
if (function_exists('opcache_invalidate')) {
84+
opcache_invalidate(
85+
$this->write->getAbsolutePath($envPath)
86+
);
87+
}
88+
}
89+
}
90+
}
91+
$cachePath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::CACHE));
5292
$generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
5393
$diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI));
5494

@@ -58,6 +98,11 @@ public function regenerate()
5898
if ($this->write->isDirectory($diPath)) {
5999
$this->write->delete($diPath);
60100
}
101+
if ($this->write->isDirectory($cachePath)) {
102+
$this->write->delete($cachePath);
103+
}
104+
//add to queue
105+
61106
$this->write->delete(self::REGENERATE_FLAG);
62107
}
63108
}

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

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

8+
use Magento\Framework\App\Filesystem\DirectoryList;
9+
use Magento\Framework\Filesystem;
810
use Magento\Setup\Console\Command\AbstractSetupCommand;
911
use Magento\Setup\Model\ObjectManagerProvider;
1012
use Symfony\Component\Console\Input\ArrayInput;
@@ -70,6 +72,26 @@ public function execute()
7072
);
7173
$this->params['command'] = 'setup:upgrade';
7274
$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+
7395
} catch (\Exception $e) {
7496
$this->status->toggleUpdateError(true);
7597
throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));

0 commit comments

Comments
 (0)