Skip to content

Instantly share code, notes, and snippets.

@hannesl
Last active October 19, 2015 14:58
Show Gist options
  • Save hannesl/cdad9610a47091b0c8a6 to your computer and use it in GitHub Desktop.
Save hannesl/cdad9610a47091b0c8a6 to your computer and use it in GitHub Desktop.
Bolt: Workaround for issue with missing templates
{
"name": "stoco/config_cache_fix",
"description": "Fixes a cache issue which results in missing templates.",
"type": "bolt-extension",
"require": {
"bolt/bolt": ">=2.0.0,<3.0.0"
},
"license": "MIT",
"authors": [
{
"name": "Hannes Lilljequist",
"email": "hannes@sthlmconnection.se"
}
],
"autoload": {
"files": [
"init.php"
],
"psr-4": {
"Bolt\\Extension\\Stoco\\ConfigCacheFix\\": ""
}
}
}
<?php
// See https://github.com/bolt/bolt/issues/4290
namespace Bolt\Extension\Stoco\ConfigCacheFix;
use Bolt\Application;
use Bolt\BaseExtension;
use Symfony\Component\HttpFoundation\Request;
class Extension extends BaseExtension
{
public function __construct(Application $app) {
parent::__construct($app);
}
public function initialize() {
$app = $this->app;
$app->before(function (Request $request) use ($app) {
// Check the theme config. It it is empty, save a semaphore file, delete
// the config cache and reload.
$themeconfig = $app['config']->get('theme');
$semaphore = $app['paths']['cache'] . '/config-cache-fix-applied';
if (empty($themeconfig) && !file_exists($semaphore)) {
$this->app['logger.system']->info('Theme config is missing. Deleting the config cache file and reloading.', ['event' => 'config_cache_fix']);
@unlink($app['paths']['cache'] . '/config_cache.php');
@touch($semaphore);
return $app->redirect($_SERVER['REQUEST_URI'], 302);
}
elseif (!empty($themeconfig) && file_exists($semaphore)) {
@unlink($semaphore);
$this->app['logger.system']->info('The config cache fix has been sucessfully applied.', ['event' => 'config_cache_fix']);
}
});
}
public function getName() {
return "ConfigCacheFix";
}
}
<?php
namespace Bolt\Extension\Stoco\ConfigCacheFix;
$app['extensions']->register(new Extension($app));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment