Skip to content

Commit

Permalink
Added Pages:: getSimplePagesHash() method
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Oct 5, 2022
1 parent 3e98669 commit 6fcc4ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
1. [](#new)
* Added new `onPageHeaders()` event to allow for header modification as needed
* Added a `system.pages.dirs` configuration option to allow for configurable paths, and multiple page paths
* Added new `Pages::getSimplePagesHash` which is useful for caching pages specific data
1. [](#bugfix)
* An attempt to workaround windows reading locked file issue [getgrav/grav-plugin-admin#2299](https://github.com/getgrav/grav-plugin-admin/issues/2299)

Expand Down
21 changes: 17 additions & 4 deletions system/src/Grav/Common/Page/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class Pages
/** @var string */
protected $check_method;
/** @var string */
protected $simple_pages_hash;
/** @var string */
protected $pages_cache_id;
/** @var bool */
protected $initialized = false;
Expand Down Expand Up @@ -1738,7 +1740,8 @@ protected function buildRegularPages(): void
$hash = Folder::lastModifiedFile($pages_dirs);
}

$this->pages_cache_id = md5(json_encode($pages_dirs) . $hash . $language->getActive() . $config->checksum());
$this->simple_pages_hash = json_encode($pages_dirs) . $hash . $config->checksum();
$this->pages_cache_id = md5($this->simple_pages_hash . $language->getActive());

/** @var Cache $cache */
$cache = $this->grav['cache'];
Expand Down Expand Up @@ -2196,7 +2199,7 @@ protected function buildSort($path, array $pages, $order_by = 'default', $manual
* @param array $list
* @return array
*/
protected function arrayShuffle($list)
protected function arrayShuffle(array $list): array
{
$keys = array_keys($list);
shuffle($keys);
Expand All @@ -2212,7 +2215,7 @@ protected function arrayShuffle($list)
/**
* @return string
*/
protected function getVersion()
protected function getVersion(): string
{
return $this->directory ? 'flex' : 'regular';
}
Expand All @@ -2225,8 +2228,18 @@ protected function getVersion()
*
* @return string
*/
public function getPagesCacheId()
public function getPagesCacheId(): string
{
return $this->pages_cache_id;
}

/**
* Get the simple pages hash that is not md5 encoded, and isn't specific to language
*
* @return string
*/
public function getSimplePagesHash(): string
{
return $this->simple_pages_hash;
}
}

0 comments on commit 6fcc4ec

Please sign in to comment.