Merge branch 'release/1.7.37'

This commit is contained in:
Andy Miller
2022-10-05 11:31:48 -06:00
10 changed files with 320 additions and 494 deletions

View File

@@ -1,3 +1,15 @@
# v1.7.37
## 10/05/2022
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
* Updated to latest vendor libraries
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)
* Force user index file to be updated to fix email addresses [getgrav/grav-plugin-login#229](https://github.com/getgrav/grav-plugin-login/issues/229)
# v1.7.36
## 09/08/2022
@@ -5,7 +17,7 @@
* Added `authorize-*@:` support for Flex blueprints, e.g. `authorize-disabled@: not delete` disables the field if user does not have access to delete object
* Added support for `flex-ignore@` to hide all the nested fields in the blueprint
1. [](#bugfix)
* Fixed loggin with a capitalised email address when using old users [getgrav/grav-plugin-login#229](https://github.com/getgrav/grav-plugin-login/issues/229)
* Fixed login with a capitalised email address when using old users [getgrav/grav-plugin-login#229](https://github.com/getgrav/grav-plugin-login/issues/229)
# v1.7.35
## 08/04/2022

View File

@@ -19,6 +19,7 @@
"ext-zip": "*",
"ext-dom": "*",
"ext-libxml": "*",
"ext-gd": "*",
"symfony/polyfill-mbstring": "~1.23",
"symfony/polyfill-iconv": "^1.23",
"symfony/polyfill-php74": "^1.23",

596
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -35,6 +35,7 @@ home:
pages:
type: regular # EXPERIMENTAL: Page type: regular or flex
dirs: ['page://'] # Advanced functionality, allows for multiple page paths
theme: quark # Default theme (defaults to "quark" theme)
order:
by: default # Order pages by "default", "alpha" or "date"

View File

@@ -9,7 +9,7 @@
// Some standard defines
define('GRAV', true);
define('GRAV_VERSION', '1.7.36');
define('GRAV_VERSION', '1.7.37');
define('GRAV_SCHEMA', '1.7.0_2020-11-20_1');
define('GRAV_TESTING', false);

View File

@@ -138,9 +138,12 @@ trait CompiledFile
$class = get_class($this);
$size = filesize($filename);
// Reload data from the filesystem. This ensures that we always cache the correct data (see issue #2282).
$this->raw = $this->content = null;
$data = (array)$this->decode($this->raw());
// windows doesn't play nicely with this as it can't read when locked
if (!Utils::isWindows()) {
// Reload data from the filesystem. This ensures that we always cache the correct data (see issue #2282).
$this->raw = $this->content = null;
$data = (array)$this->decode($this->raw());
}
// Decode data into compiled array.
$cache = [

View File

@@ -31,32 +31,34 @@ abstract class Folder
/**
* Recursively find the last modified time under given path.
*
* @param string $path
* @param array $paths
* @return int
*/
public static function lastModifiedFolder($path)
public static function lastModifiedFolder(array $paths): int
{
if (!file_exists($path)) {
return 0;
}
$last_modified = 0;
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
$flags = RecursiveDirectoryIterator::SKIP_DOTS;
if ($locator->isStream($path)) {
$directory = $locator->getRecursiveIterator($path, $flags);
} else {
$directory = new RecursiveDirectoryIterator($path, $flags);
}
$filter = new RecursiveFolderFilterIterator($directory);
$iterator = new RecursiveIteratorIterator($filter, RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $dir) {
$dir_modified = $dir->getMTime();
if ($dir_modified > $last_modified) {
$last_modified = $dir_modified;
foreach ($paths as $path) {
if (!file_exists($path)) {
return 0;
}
if ($locator->isStream($path)) {
$directory = $locator->getRecursiveIterator($path, $flags);
} else {
$directory = new RecursiveDirectoryIterator($path, $flags);
}
$filter = new RecursiveFolderFilterIterator($directory);
$iterator = new RecursiveIteratorIterator($filter, RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $dir) {
$dir_modified = $dir->getMTime();
if ($dir_modified > $last_modified) {
$last_modified = $dir_modified;
}
}
}
@@ -66,38 +68,40 @@ abstract class Folder
/**
* Recursively find the last modified time under given path by file.
*
* @param string $path
* @param array $paths
* @param string $extensions which files to search for specifically
* @return int
*/
public static function lastModifiedFile($path, $extensions = 'md|yaml')
public static function lastModifiedFile(array $paths, $extensions = 'md|yaml'): int
{
if (!file_exists($path)) {
return 0;
}
$last_modified = 0;
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
$flags = RecursiveDirectoryIterator::SKIP_DOTS;
if ($locator->isStream($path)) {
$directory = $locator->getRecursiveIterator($path, $flags);
} else {
$directory = new RecursiveDirectoryIterator($path, $flags);
}
$recursive = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
$iterator = new RegexIterator($recursive, '/^.+\.'.$extensions.'$/i');
/** @var RecursiveDirectoryIterator $file */
foreach ($iterator as $filepath => $file) {
try {
$file_modified = $file->getMTime();
if ($file_modified > $last_modified) {
$last_modified = $file_modified;
foreach($paths as $path) {
if (!file_exists($path)) {
return 0;
}
if ($locator->isStream($path)) {
$directory = $locator->getRecursiveIterator($path, $flags);
} else {
$directory = new RecursiveDirectoryIterator($path, $flags);
}
$recursive = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
$iterator = new RegexIterator($recursive, '/^.+\.'.$extensions.'$/i');
/** @var RecursiveDirectoryIterator $file */
foreach ($iterator as $file) {
try {
$file_modified = $file->getMTime();
if ($file_modified > $last_modified) {
$last_modified = $file_modified;
}
} catch (Exception $e) {
Grav::instance()['log']->error('Could not process file: ' . $e->getMessage());
}
} catch (Exception $e) {
Grav::instance()['log']->error('Could not process file: ' . $e->getMessage());
}
}
@@ -107,28 +111,30 @@ abstract class Folder
/**
* Recursively md5 hash all files in a path
*
* @param string $path
* @param array $paths
* @return string
*/
public static function hashAllFiles($path)
public static function hashAllFiles(array $paths): string
{
$files = [];
if (file_exists($path)) {
$flags = RecursiveDirectoryIterator::SKIP_DOTS;
foreach ($paths as $path) {
if (file_exists($path)) {
$flags = RecursiveDirectoryIterator::SKIP_DOTS;
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
if ($locator->isStream($path)) {
$directory = $locator->getRecursiveIterator($path, $flags);
} else {
$directory = new RecursiveDirectoryIterator($path, $flags);
}
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
if ($locator->isStream($path)) {
$directory = $locator->getRecursiveIterator($path, $flags);
} else {
$directory = new RecursiveDirectoryIterator($path, $flags);
}
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file) {
$files[] = $file->getPathname() . '?'. $file->getMTime();
foreach ($iterator as $file) {
$files[] = $file->getPathname() . '?'. $file->getMTime();
}
}
}

View File

@@ -30,7 +30,7 @@ use function is_string;
*/
class UserIndex extends FlexIndex implements UserCollectionInterface
{
public const VERSION = parent::VERSION . '.1';
public const VERSION = parent::VERSION . '.2';
/**
* @param FlexStorageInterface $storage
@@ -50,7 +50,7 @@ class UserIndex extends FlexIndex implements UserCollectionInterface
// return $index['index'];
//}
// Load up to date index.
// Load up-to-date index.
$entries = parent::loadEntriesFromStorage($storage);
return static::updateIndexFile($storage, $index['index'], $entries, ['force_update' => $force]);
@@ -142,9 +142,11 @@ class UserIndex extends FlexIndex implements UserCollectionInterface
} elseif ($field === 'flex_key') {
$user = $this->withKeyField('flex_key')->get($query);
} elseif ($field === 'email') {
$user = $this->withKeyField('email')->get(static::filterUsername($query, $this->getFlexDirectory()->getStorage()));
$email = mb_strtolower($query);
$user = $this->withKeyField('email')->get($email);
} elseif ($field === 'username') {
$user = $this->get(static::filterUsername($query, $this->getFlexDirectory()->getStorage()));
$username = static::filterUsername($query, $this->getFlexDirectory()->getStorage());
$user = $this->get($username);
} else {
$user = $this->__call('find', [$query, $field]);
}

View File

@@ -622,7 +622,12 @@ class Page implements PageInterface
$headers['Vary'] = 'Accept-Encoding';
}
return $headers;
// Added new Headers event
$headers_obj = (object) $headers;
Grav::instance()->fireEvent('onPageHeaders', new Event(['headers' => $headers_obj]));
return (array)$headers_obj;
}
/**

View File

@@ -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;
@@ -100,6 +102,7 @@ class Pages
/** @var string|null */
protected static $home_route;
/**
* Constructor
*
@@ -1712,10 +1715,7 @@ class Pages
/** @var Language $language */
$language = $this->grav['language'];
$pages_dir = $locator->findResource('page://');
if (!is_string($pages_dir)) {
throw new RuntimeException('Internal Error');
}
$pages_dirs = $this->getPagesPaths();
// Set active language
$this->active_lang = $language->getActive();
@@ -1731,16 +1731,17 @@ class Pages
$hash = 0;
break;
case 'folder':
$hash = Folder::lastModifiedFolder($pages_dir);
$hash = Folder::lastModifiedFolder($pages_dirs);
break;
case 'hash':
$hash = Folder::hashAllFiles($pages_dir);
$hash = Folder::hashAllFiles($pages_dirs);
break;
default:
$hash = Folder::lastModifiedFile($pages_dir);
$hash = Folder::lastModifiedFile($pages_dirs);
}
$this->pages_cache_id = md5($pages_dir . $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'];
@@ -1760,18 +1761,39 @@ class Pages
$this->grav['debugger']->addMessage('Page cache disabled, rebuilding pages..');
}
$this->resetPages($pages_dir);
$this->resetPages($pages_dirs);
}
protected function getPagesPaths(): array
{
$grav = Grav::instance();
$locator = $grav['locator'];
$paths = [];
$dirs = (array) $grav['config']->get('system.pages.dirs', ['page://']);
foreach ($dirs as $dir) {
$path = $locator->findResource($dir);
if (file_exists($path)) {
$paths[] = $path;
}
}
return $paths;
}
/**
* Accessible method to manually reset the pages cache
*
* @param string $pages_dir
* @param array $pages_dirs
*/
public function resetPages($pages_dir): void
public function resetPages(array $pages_dirs): void
{
$this->sort = [];
$this->recurse($pages_dir);
foreach ($pages_dirs as $dir) {
$this->recurse($dir);
}
$this->buildRoutes();
// cache if needed
@@ -1795,7 +1817,7 @@ class Pages
* @throws RuntimeException
* @internal
*/
protected function recurse($directory, PageInterface $parent = null)
protected function recurse(string $directory, PageInterface $parent = null)
{
$directory = rtrim($directory, DS);
$page = new Page;
@@ -2177,7 +2199,7 @@ class Pages
* @param array $list
* @return array
*/
protected function arrayShuffle($list)
protected function arrayShuffle(array $list): array
{
$keys = array_keys($list);
shuffle($keys);
@@ -2193,7 +2215,7 @@ class Pages
/**
* @return string
*/
protected function getVersion()
protected function getVersion(): string
{
return $this->directory ? 'flex' : 'regular';
}
@@ -2206,8 +2228,18 @@ class Pages
*
* @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;
}
}