Fix issue in storing comments cache when cache is enabled #33

This commit is contained in:
Flavio Copes 2016-08-12 13:27:50 +02:00
parent c1fe1a6a32
commit e4e1c79d1a
2 changed files with 11 additions and 7 deletions

View File

@ -3,6 +3,8 @@
1. [](#improved) 1. [](#improved)
* Added Romanian translation * Added Romanian translation
1. [](#bugfix)
* Fix issue in storing comments cache when cache is enabled [#33](https://github.com/getgrav/grav-plugin-comments/issues/33)
# v1.2.1 # v1.2.1
## 07/19/2016 ## 07/19/2016

View File

@ -18,7 +18,7 @@ class CommentsPlugin extends Plugin
protected $route = 'comments'; protected $route = 'comments';
protected $enable = false; protected $enable = false;
protected $comments_cache_id; protected $comments_cache_id;
/** /**
* @return array * @return array
*/ */
@ -92,7 +92,7 @@ class CommentsPlugin extends Plugin
public function initializeFrontend() public function initializeFrontend()
{ {
$this->calculateEnable(); $this->calculateEnable();
if ($this->enable) { if ($this->enable) {
$this->enable([ $this->enable([
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
@ -101,12 +101,14 @@ class CommentsPlugin extends Plugin
'onTwigSiteVariables' => ['onTwigSiteVariables', 0] 'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
]); ]);
} }
$cache = $this->grav['cache']; $cache = $this->grav['cache'];
$uri = $this->grav['uri'];
//init cache id //init cache id
$this->comments_cache_id = md5('comments-data' . $cache->getKey()); $this->comments_cache_id = md5('comments-data' . $cache->getKey() . '-' . $uri->url());
} }
/** /**
* Admin side initialization * Admin side initialization
*/ */
@ -136,7 +138,7 @@ class CommentsPlugin extends Plugin
$this->grav['twig']->comments = $comments; $this->grav['twig']->comments = $comments;
$this->grav['twig']->pages = $this->fetchPages(); $this->grav['twig']->pages = $this->fetchPages();
} }
/** /**
*/ */
public function onPluginsInitialized() public function onPluginsInitialized()
@ -325,7 +327,7 @@ class CommentsPlugin extends Plugin
if ($comments = $cache->fetch($this->comments_cache_id)) { if ($comments = $cache->fetch($this->comments_cache_id)) {
return $comments; return $comments;
} }
$lang = $this->grav['language']->getLanguage(); $lang = $this->grav['language']->getLanguage();
$filename = $lang ? '/' . $lang : ''; $filename = $lang ? '/' . $lang : '';
$filename .= $this->grav['uri']->path() . '.yaml'; $filename .= $this->grav['uri']->path() . '.yaml';