Skip to content

Commit

Permalink
Fixes an issue where CP Clear Cache could conflict with other plugins…
Browse files Browse the repository at this point in the history
…. Bump to 1.0.4
  • Loading branch information
mmikkel committed Mar 27, 2019
1 parent 2aa94f8 commit 7113342
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.4 - 2019-03-27
### Fixed
- Fixes an issue where CP Clear Cache could conflict with other plugins

## 1.0.3 - 2018-11-23
### Improved
– Improves plugin tagline (thanks Brandon!)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mmikkel/cp-clearcache",
"description": "Less clickin’ to get clearin’",
"type": "craft-plugin",
"version": "1.0.3",
"version": "1.0.4",
"keywords": [
"craft",
"cms",
Expand Down
28 changes: 11 additions & 17 deletions src/CpClearCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use craft\base\UtilityInterface;
use craft\events\RegisterCpNavItemsEvent;
use craft\services\Plugins;
use craft\web\Application;
use craft\web\assets\utilities\UtilitiesAsset;
use craft\web\twig\variables\Cp;
use craft\web\View;
Expand Down Expand Up @@ -62,18 +63,11 @@ public function init()
parent::init();
self::$plugin = $this;

if (!Craft::$app->getRequest()->getIsCpRequest() || Craft::$app->getRequest()->getIsConsoleRequest()) {
if (Craft::$app->getRequest()->getIsConsoleRequest() || !Craft::$app->getUser()->getIdentity() || !Craft::$app->getRequest()->getIsCpRequest()) {
return;
}

// Handler: EVENT_AFTER_LOAD_PLUGINS
Event::on(
Plugins::class,
Plugins::EVENT_AFTER_LOAD_PLUGINS,
function () {
$this->doIt();
}
);
Craft::$app->on(Application::EVENT_INIT, [$this, 'doIt']);

}

Expand All @@ -94,20 +88,20 @@ protected function doIt()
Craft::setAlias('@mmikkel/cpclearcache', __DIR__);

// Register asset bundle
$data = [
'html' => $clearCachesUtility::contentHtml(),
];

Event::on(
View::class,
View::EVENT_BEFORE_RENDER_TEMPLATE,
function () use ($data) {
View::EVENT_BEGIN_BODY,
function () use ($clearCachesUtility) {
try {
$html = $clearCachesUtility::contentHtml();
if (!$html) {
return;
}
$view = Craft::$app->getView();
$view->registerAssetBundle(UtilitiesAsset::class);
$view->registerAssetBundle(CpClearCacheBundle::class);
$view->registerJs('if (Craft.CpClearCachePlugin) { Craft.CpClearCachePlugin.init(' . json_encode($data) . '); };');
} catch (InvalidConfigException $e) {
$view->registerJs('if (Craft.CpClearCachePlugin) { Craft.CpClearCachePlugin.init(' . json_encode(['html' => $html]) . '); };', View::POS_READY);
} catch (\Throwable $e) {
Craft::error(
'Error registering AssetBundle - ' . $e->getMessage(),
__METHOD__
Expand Down

0 comments on commit 7113342

Please sign in to comment.