Skip to content
Snippets Groups Projects
Commit 28b1eb33 authored by Maddy Chellathurai's avatar Maddy Chellathurai
Browse files

MAGETWO-52000: [Github][PR]impossible to see what is wrong with cron -...

MAGETWO-52000: [Github][PR]impossible to see what is wrong with cron - unhelpful error message #3189

- fixing upgrade
parent 0ee021ab
No related merge requests found
...@@ -5,9 +5,12 @@ ...@@ -5,9 +5,12 @@
*/ */
namespace Magento\Framework\Code; namespace Magento\Framework\Code;
use Magento\Framework\Config\Data\ConfigData;
use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Filesystem\Directory\WriteFactory; use Magento\Framework\Filesystem\Directory\WriteFactory;
use Magento\Framework\Filesystem\Directory\WriteInterface; use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\Framework\App\DeploymentConfig\Writer\PhpFormatter;
/** /**
* Regenerates generated code and DI configuration * Regenerates generated code and DI configuration
...@@ -49,6 +52,43 @@ class GeneratedFiles ...@@ -49,6 +52,43 @@ class GeneratedFiles
public function regenerate() public function regenerate()
{ {
if ($this->write->isExist(self::REGENERATE_FLAG)) { if ($this->write->isExist(self::REGENERATE_FLAG)) {
//clean cache
$deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG);
$configPool = new ConfigFilePool();
$envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
if ($this->write->isExist($this->write->getRelativePath($envPath))) {
$cacheData = include $envPath;
if (isset($cacheData['cache_types'])) {
$enabledCacheTypes = $cacheData['cache_types'];
$enabledCacheTypes = array_filter($enabledCacheTypes, function ($value) {
return $value;
}
);
if (!empty($enabledCacheTypes)) {
$this->write->writeFile($this->write->getRelativePath(
$this->directoryList->getPath(DirectoryList::VAR_DIR)) . '/.cachestates.json',
json_encode($enabledCacheTypes)
);
$cacheTypes = array_keys($cacheData['cache_types']);
foreach ($cacheTypes as $cacheType) {
$cacheData['cache_types'][$cacheType] = 0;
}
$formatter = new PhpFormatter();
$contents = $formatter->format($cacheData);
$this->write->writeFile($this->write->getRelativePath($envPath), $contents);
if (function_exists('opcache_invalidate')) {
opcache_invalidate(
$this->write->getAbsolutePath($envPath)
);
}
}
}
}
$cachePath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::CACHE));
$generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION)); $generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
$diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI)); $diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI));
...@@ -58,6 +98,11 @@ class GeneratedFiles ...@@ -58,6 +98,11 @@ class GeneratedFiles
if ($this->write->isDirectory($diPath)) { if ($this->write->isDirectory($diPath)) {
$this->write->delete($diPath); $this->write->delete($diPath);
} }
if ($this->write->isDirectory($cachePath)) {
$this->write->delete($cachePath);
}
//add to queue
$this->write->delete(self::REGENERATE_FLAG); $this->write->delete(self::REGENERATE_FLAG);
} }
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
*/ */
namespace Magento\Setup\Model\Cron; namespace Magento\Setup\Model\Cron;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Setup\Console\Command\AbstractSetupCommand; use Magento\Setup\Console\Command\AbstractSetupCommand;
use Magento\Setup\Model\ObjectManagerProvider; use Magento\Setup\Model\ObjectManagerProvider;
use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\ArrayInput;
...@@ -70,6 +72,26 @@ class JobUpgrade extends AbstractJob ...@@ -70,6 +72,26 @@ class JobUpgrade extends AbstractJob
); );
$this->params['command'] = 'setup:upgrade'; $this->params['command'] = 'setup:upgrade';
$this->command->run(new ArrayInput($this->params), $this->output); $this->command->run(new ArrayInput($this->params), $this->output);
/**
* @var \Magento\Framework\Filesystem\Directory\WriteFactory $writeFactory
*/
$writeFactory = $this->objectManager->get('\\Magento\Framework\Filesystem\Directory\WriteFactory');
$write = $writeFactory->create(BP);
$dirList = $this->objectManager->get('\Magento\Framework\App\Filesystem\DirectoryList');
$pathToCacheStatus = $write->getRelativePath(
$dirList->getPath(DirectoryList::VAR_DIR) . '/.cachestates.json'
);
if ($write->isExist($pathToCacheStatus)) {
$params = array_keys(json_decode($write->readFile($pathToCacheStatus), true));
$this->queue->addJobs(
[['name' => JobFactory::JOB_ENABLE_CACHE, 'params' => [implode(' ', $params)]]]
);
$write->delete($pathToCacheStatus);
}
} catch (\Exception $e) { } catch (\Exception $e) {
$this->status->toggleUpdateError(true); $this->status->toggleUpdateError(true);
throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage())); throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment