From c87f6c05217f325005f24dfe0c1b23d4a098964f Mon Sep 17 00:00:00 2001 From: Ian Williams Date: Wed, 12 Apr 2017 13:32:06 -0400 Subject: [PATCH] Added public webhook. --- HtmlcachePlugin.php | 12 ++++++++++++ controllers/Htmlcache_WebhookController.php | 12 ++++++++++++ services/Htmlcache_HtmlcacheService.php | 5 ++++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 controllers/Htmlcache_WebhookController.php diff --git a/HtmlcachePlugin.php b/HtmlcachePlugin.php index 2914cad..dc30ae7 100644 --- a/HtmlcachePlugin.php +++ b/HtmlcachePlugin.php @@ -237,4 +237,16 @@ public function registerCachePaths() craft()->htmlcache_htmlcache->clearCacheFiles() => Craft::t('Htmlcache cached pages') ); } + + /** + * Adds routes to allow external webhook to clear cache + * + * @return array + */ + public function registerSiteRoutes() + { + return array( + 'htmlcache/clearCache' => array('action' => 'htmlcache/webhook/clearCache'), + ); + } } diff --git a/controllers/Htmlcache_WebhookController.php b/controllers/Htmlcache_WebhookController.php new file mode 100644 index 0000000..4b20b8d --- /dev/null +++ b/controllers/Htmlcache_WebhookController.php @@ -0,0 +1,12 @@ +htmlcache_htmlcache->clearCacheFiles(); + } +} \ No newline at end of file diff --git a/services/Htmlcache_HtmlcacheService.php b/services/Htmlcache_HtmlcacheService.php index ad34407..aa64579 100644 --- a/services/Htmlcache_HtmlcacheService.php +++ b/services/Htmlcache_HtmlcacheService.php @@ -48,7 +48,10 @@ public function canCreateCacheFile() if (craft()->request->isCpRequest()) { return false; } - + // Skip if it's a webhook to clear cache + if (craft()->request->path == 'htmlcache/clearCache') { + return false; + } // Skip if it's an action Request if (craft()->request->isActionRequest()) { return false;