/**
* Attempt to load cached configuration files.
*
* @throws LowlevelException
*
* @return bool
*/
protected function loadCache()
{
$dir = $this->app['resources']->getPath('config');
/* Get the timestamps for the config files. `config_local.yml` and `extensions.yml` default to '0', because if
they aren't present, it shouldn't trigger an update for the cache, while the others should.
*/
$timestamps = [file_exists($dir . '/config.yml') ? filemtime($dir . '/config.yml') : 10000000000, file_exists($dir . '/taxonomy.yml') ? filemtime($dir . '/taxonomy.yml') : 10000000000, file_exists($dir . '/contenttypes.yml') ? filemtime($dir . '/contenttypes.yml') : 10000000000, file_exists($dir . '/menu.yml') ? filemtime($dir . '/menu.yml') : 10000000000, file_exists($dir . '/routing.yml') ? filemtime($dir . '/routing.yml') : 10000000000, file_exists($dir . '/permissions.yml') ? filemtime($dir . '/permissions.yml') : 10000000000, file_exists($dir . '/extensions.yml') ? filemtime($dir . '/extensions.yml') : 0, file_exists($dir . '/config_local.yml') ? filemtime($dir . '/config_local.yml') : 0];
$configCache = $this->app['resources']->getPath('cache/config-cache.json');
$this->cachetimestamp = file_exists($configCache) ? filemtime($configCache) : 0;
if ($this->cachetimestamp > max($timestamps)) {
$finder = new Finder();
$finder->files()->in($this->app['resources']->getPath('cache'))->name('config-cache.json')->depth('== 0');
/** @var SplFileInfo $file */
foreach ($finder as $file) {
try {
$this->data = json_decode($file->getContents(), true);
} catch (\RuntimeException $e) {
$part = Translator::__('Try logging in with your ftp-client and make the file readable. ' . 'Else try to go <a>back</a> to the last page.');
$message = '<p>' . Translator::__('general.phrase.file-not-readable-following-colon') . '</p>' . '<pre>' . htmlspecialchars($configCache) . '</pre>' . '<p>' . str_replace('<a>', '<a href="javascript:history.go(-1)">', $part) . '</p>';
throw new LowlevelException(Translator::__('page.file-management.message.file-not-readable' . $message));
}
}
// Check if we loaded actual data.
if (count($this->data) < 4 || empty($this->data['general'])) {
return false;
}
// Check to make sure the version is still the same. If not, effectively invalidate the
// cached config to force a reload.
if (!isset($this->data['version']) || Bolt\Version::compare($this->data['version'], '!=')) {
// The logger and the flashbags aren't available yet, so we set a flag to notify the user later.
$this->notify_update = true;
return false;
}
// Trigger the config loaded event on the resource manager
$this->app['resources']->initializeConfig($this->data);
// Yup, all seems to be right.
return true;
}
return false;
}