From f6830c6ab69af9464f56e9c5482006c82dfed046 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Thu, 15 Oct 2015 10:48:25 +1030 Subject: [PATCH] Flush the embed client assets when settings are changed --- extensions/embed/bootstrap.php | 3 +- ...FlushEmbedAssetsWhenSettingsAreChanged.php | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 extensions/embed/src/Listener/FlushEmbedAssetsWhenSettingsAreChanged.php diff --git a/extensions/embed/bootstrap.php b/extensions/embed/bootstrap.php index 481d20d97..0ecaf69bb 100644 --- a/extensions/embed/bootstrap.php +++ b/extensions/embed/bootstrap.php @@ -14,4 +14,5 @@ use Illuminate\Contracts\Events\Dispatcher; return function (Dispatcher $events) { $events->subscribe(Listener\AddEmbedRoute::class); -}; \ No newline at end of file + $events->subscribe(Listener\FlushEmbedAssetsWhenSettingsAreChanged::class); +}; diff --git a/extensions/embed/src/Listener/FlushEmbedAssetsWhenSettingsAreChanged.php b/extensions/embed/src/Listener/FlushEmbedAssetsWhenSettingsAreChanged.php new file mode 100644 index 000000000..acb06c5f8 --- /dev/null +++ b/extensions/embed/src/Listener/FlushEmbedAssetsWhenSettingsAreChanged.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Embed\Listener; + +use Flarum\Embed\DiscussionController; +use Flarum\Event\ExtensionWasDisabled; +use Flarum\Event\ExtensionWasEnabled; +use Flarum\Event\SettingWasSet; +use Illuminate\Contracts\Events\Dispatcher; + +class FlushEmbedAssetsWhenSettingsAreChanged +{ + /** + * @var DiscussionController + */ + protected $controller; + + /** + * @param DiscussionController $controller + */ + public function __construct(DiscussionController $controller) + { + $this->controller = $controller; + } + + /** + * @param Dispatcher $events + */ + public function subscribe(Dispatcher $events) + { + $events->listen(SettingWasSet::class, [$this, 'flushCss']); + $events->listen(ExtensionWasEnabled::class, [$this, 'flushAssets']); + $events->listen(ExtensionWasDisabled::class, [$this, 'flushAssets']); + } + + /** + * @param SettingWasSet $event + */ + public function flushCss(SettingWasSet $event) + { + if (preg_match('/^theme_|^custom_less$/i', $event->key)) { + $this->controller->flushCss(); + } + } + + public function flushAssets() + { + $this->controller->flushAssets(); + } +}