Skip to content

Commit

Permalink
MAGETWO-52000: [Github][PR]impossible to see what is wrong with cron …
Browse files Browse the repository at this point in the history
…- unhelpful error message #3189

- fixing upgrade
  • Loading branch information
mazhalai committed May 19, 2016
1 parent 0ee021a commit 28b1eb3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib/internal/Magento/Framework/Code/GeneratedFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
*/
namespace Magento\Framework\Code;

use Magento\Framework\Config\Data\ConfigData;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Config\File\ConfigFilePool;
use Magento\Framework\Filesystem\Directory\WriteFactory;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\Framework\App\DeploymentConfig\Writer\PhpFormatter;

/**
* Regenerates generated code and DI configuration
Expand Down Expand Up @@ -49,6 +52,43 @@ public function __construct(DirectoryList $directoryList, WriteFactory $writeFac
public function regenerate()
{
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));
$diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI));

Expand All @@ -58,6 +98,11 @@ public function regenerate()
if ($this->write->isDirectory($diPath)) {
$this->write->delete($diPath);
}
if ($this->write->isDirectory($cachePath)) {
$this->write->delete($cachePath);
}
//add to queue

$this->write->delete(self::REGENERATE_FLAG);
}
}
Expand Down
22 changes: 22 additions & 0 deletions setup/src/Magento/Setup/Model/Cron/JobUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Setup\Model\Cron;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Setup\Console\Command\AbstractSetupCommand;
use Magento\Setup\Model\ObjectManagerProvider;
use Symfony\Component\Console\Input\ArrayInput;
Expand Down Expand Up @@ -70,6 +72,26 @@ public function execute()
);
$this->params['command'] = 'setup:upgrade';
$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) {
$this->status->toggleUpdateError(true);
throw new \RuntimeException(sprintf('Could not complete %s successfully: %s', $this, $e->getMessage()));
Expand Down

0 comments on commit 28b1eb3

Please sign in to comment.