Skip to content

Commit ad96d04

Browse files
committed
MAGETWO-52000: [Github][PR]impossible to see what is wrong with cron - unhelpful error message #3189
- static test failures
1 parent 13d772e commit ad96d04

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

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

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,7 @@ public function regenerate()
5757
$configPool = new ConfigFilePool();
5858
$envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
5959
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-
}
60+
$this->saveCacheStatus($envPath);
9061
}
9162
$cachePath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::CACHE));
9263
$generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
@@ -107,6 +78,44 @@ public function regenerate()
10778
}
10879
}
10980

81+
/**
82+
* Read Cache types from env.php and write to a json file.
83+
*
84+
* @param $envPath
85+
*/
86+
private function saveCacheStatus($envPath)
87+
{
88+
$cacheData = include $envPath;
89+
90+
if (isset($cacheData['cache_types'])) {
91+
$enabledCacheTypes = $cacheData['cache_types'];
92+
$enabledCacheTypes = array_filter($enabledCacheTypes, function ($value) {
93+
return $value;
94+
});
95+
if (!empty($enabledCacheTypes)) {
96+
$this->write->writeFile($this->write->getRelativePath(
97+
$this->directoryList->getPath(DirectoryList::VAR_DIR)
98+
) . '/.cachestates.json',
99+
json_encode($enabledCacheTypes)
100+
);
101+
$cacheTypes = array_keys($cacheData['cache_types']);
102+
103+
foreach ($cacheTypes as $cacheType) {
104+
$cacheData['cache_types'][$cacheType] = 0;
105+
}
106+
107+
$formatter = new PhpFormatter();
108+
$contents = $formatter->format($cacheData);
109+
110+
$this->write->writeFile($this->write->getRelativePath($envPath), $contents);
111+
if (function_exists('opcache_invalidate')) {
112+
opcache_invalidate(
113+
$this->write->getAbsolutePath($envPath)
114+
);
115+
}
116+
}
117+
}
118+
}
110119
/**
111120
* Create flag for regeneration of code and di
112121
*

setup/src/Magento/Setup/Test/Unit/Model/Cron/JobUpgradeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testExecute()
3636

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

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

0 commit comments

Comments
 (0)