Last active
October 19, 2015 14:58
-
-
Save hannesl/cdad9610a47091b0c8a6 to your computer and use it in GitHub Desktop.
Bolt: Workaround for issue with missing templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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": "[email protected]" | |
} | |
], | |
"autoload": { | |
"files": [ | |
"init.php" | |
], | |
"psr-4": { | |
"Bolt\\Extension\\Stoco\\ConfigCacheFix\\": "" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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