Merge branch 'develop' of github.com:getgrav/grav into feature/media

 Conflicts:
	CHANGELOG.md
This commit is contained in:
Matias Griese
2022-03-29 21:35:34 +03:00
2 changed files with 14 additions and 4 deletions

View File

@@ -6,6 +6,12 @@
2. [](#improved)
* By default, add media to only pages which have been initialized in pages loop
# v1.7.33
## mm/dd/2022
1. [](#bugfix)
* Fixed missing changes in yaml & markdown files if saved multiple times during the same second because of a caching issue
# v1.7.32
## 03/28/2022

View File

@@ -32,9 +32,10 @@ trait CompiledFile
public function content($var = null)
{
try {
$filename = $this->filename;
// If nothing has been loaded, attempt to get pre-compiled version of the file first.
if ($var === null && $this->raw === null && $this->content === null) {
$key = md5($this->filename);
$key = md5($filename);
$file = PhpFile::instance(CACHE_DIR . "compiled/files/{$key}{$this->extension}.php");
$modified = $this->modified();
@@ -48,13 +49,15 @@ trait CompiledFile
$class = get_class($this);
$size = filesize($filename);
$cache = $file->exists() ? $file->content() : null;
// Load real file if cache isn't up to date (or is invalid).
if (!isset($cache['@class'])
|| $cache['@class'] !== $class
|| $cache['modified'] !== $modified
|| $cache['filename'] !== $this->filename
|| ($cache['size'] ?? null) !== $size
|| $cache['filename'] !== $filename
) {
// Attempt to lock the file for writing.
try {
@@ -67,8 +70,9 @@ trait CompiledFile
$data = (array)$this->decode($this->raw());
$cache = [
'@class' => $class,
'filename' => $this->filename,
'filename' => $filename,
'modified' => $modified,
'size' => $size,
'data' => $data
];
@@ -89,7 +93,7 @@ trait CompiledFile
$this->content = $cache['data'];
}
} catch (Exception $e) {
throw new RuntimeException(sprintf('Failed to read %s: %s', Utils::basename($this->filename), $e->getMessage()), 500, $e);
throw new RuntimeException(sprintf('Failed to read %s: %s', Utils::basename($filename), $e->getMessage()), 500, $e);
}
return parent::content($var);