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

- static test failures
  • Loading branch information
mazhalai committed May 20, 2016
1 parent 13d772e commit ad96d04
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
69 changes: 39 additions & 30 deletions lib/internal/Magento/Framework/Code/GeneratedFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,7 @@ public function regenerate()
$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)
);
}
}
}
$this->saveCacheStatus($envPath);
}
$cachePath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::CACHE));
$generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
Expand All @@ -107,6 +78,44 @@ public function regenerate()
}
}

/**
* Read Cache types from env.php and write to a json file.
*
* @param $envPath
*/
private function saveCacheStatus($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)
);
}
}
}
}
/**
* Create flag for regeneration of code and di
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testExecute()

$writeFactory->expects($this->once())->method('create')->willReturn($write);
$directoryList = $this->getMock('\Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
$directoryList->expects($this->once())->method('getPath')->willReturn( '/some/full/path' . $pathToCacheStatus);
$directoryList->expects($this->once())->method('getPath')->willReturn('/some/full/path' . $pathToCacheStatus);

$objectManager->expects($this->any())->method('get')->will($this->returnValueMap([
['\Magento\Framework\Filesystem\Directory\WriteFactory', $writeFactory],
Expand Down

0 comments on commit ad96d04

Please sign in to comment.