mirror of
https://github.com/getgrav/grav.git
synced 2026-03-02 10:31:41 +01:00
Grav 1.7: Fixed Flex Pages unserialize issues if Flex-Objects Plugin has not been installed
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
* Fixed new `Flex Users` being stored with wrong filename, login issues [#2785](https://github.com/getgrav/grav/issues/2785)
|
||||
* Fixed `ignore_empty: true` not removing empty values in blueprint filtering
|
||||
* Fixed `{{ false|string }}` twig to return '0' instead of ''
|
||||
* Grav 1.7: Fixed `Flex Pages` unserialize issues if Flex-Objects Plugin has not been installed
|
||||
|
||||
# v1.7.0-rc.3
|
||||
## 01/02/2020
|
||||
|
||||
@@ -20,6 +20,7 @@ use Grav\Common\Flex\Pages\Traits\PageTranslateTrait;
|
||||
use Grav\Common\Page\Pages;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Framework\Filesystem\Filesystem;
|
||||
use Grav\Framework\Flex\FlexDirectory;
|
||||
use Grav\Framework\Flex\FlexObject;
|
||||
use Grav\Framework\Flex\Pages\FlexPageObject;
|
||||
use Grav\Framework\Route\Route;
|
||||
@@ -344,6 +345,23 @@ class PageObject extends FlexPageObject
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $serialized
|
||||
* @param FlexDirectory|null $directory
|
||||
*/
|
||||
protected function doUnserialize(array $serialized, FlexDirectory $directory = null): void
|
||||
{
|
||||
if (null === $directory) {
|
||||
$grav = Grav::instance();
|
||||
if (!isset($grav['flex_objects'])) {
|
||||
$pages = $grav['pages'];
|
||||
$directory = $pages->getDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
parent::doUnserialize($serialized, $directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $elements
|
||||
* @param bool $extended
|
||||
|
||||
@@ -889,29 +889,19 @@ class UserObject extends FlexObject implements UserInterface, MediaManipulationI
|
||||
|
||||
/**
|
||||
* @param array $serialized
|
||||
* @param FlexDirectory|null $directory
|
||||
*/
|
||||
protected function doUnserialize(array $serialized): void
|
||||
protected function doUnserialize(array $serialized, FlexDirectory $directory = null): void
|
||||
{
|
||||
$grav = Grav::instance();
|
||||
$flex = $grav['flex_objects'] ?? null;
|
||||
|
||||
// Use Flex plugin if possible -- fixes issues if admin has flex users admin, but it is not used in the session.
|
||||
if ($flex) {
|
||||
$directory = $flex->getDirectory($serialized['type']);
|
||||
} else {
|
||||
/** @var UserCollectionInterface|null $accounts */
|
||||
$accounts = $grav['accounts'] ?? null;
|
||||
$directory = $accounts instanceof FlexCollectionInterface ? $accounts->getFlexDirectory() : null;
|
||||
if (null === $directory) {
|
||||
$grav = Grav::instance();
|
||||
if (!isset($grav['flex_objects'])) {
|
||||
$accounts = $grav['accounts'] ?? null;
|
||||
$directory = $accounts instanceof FlexCollectionInterface ? $accounts->getFlexDirectory() : null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$directory) {
|
||||
throw new \RuntimeException('Internal error, please clear cache');
|
||||
}
|
||||
|
||||
$this->setFlexDirectory($directory);
|
||||
$this->setStorage($serialized['storage']);
|
||||
$this->setKey($serialized['key']);
|
||||
$this->setElements($serialized['elements']);
|
||||
parent::doUnserialize($serialized, $directory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -108,6 +108,14 @@ class Pages
|
||||
$this->grav = $grav;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FlexDirectory|null
|
||||
*/
|
||||
public function getDirectory(): ?FlexDirectory
|
||||
{
|
||||
return $this->directory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used in admin to disable frontend pages from being initialized.
|
||||
*/
|
||||
|
||||
@@ -849,8 +849,9 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
|
||||
|
||||
/**
|
||||
* @param array $serialized
|
||||
* @param FlexDirectory|null $directory
|
||||
*/
|
||||
protected function doUnserialize(array $serialized): void
|
||||
protected function doUnserialize(array $serialized, FlexDirectory $directory = null): void
|
||||
{
|
||||
$type = $serialized['type'] ?? 'unknown';
|
||||
|
||||
@@ -858,13 +859,16 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
|
||||
throw new \InvalidArgumentException("Cannot unserialize '{$type}': Bad data");
|
||||
}
|
||||
|
||||
$grav = Grav::instance();
|
||||
/** @var Flex|null $flex */
|
||||
$flex = $grav['flex_objects'] ?? null;
|
||||
$directory = $flex ? $flex->getDirectory($type) : null;
|
||||
if (!$directory) {
|
||||
throw new \InvalidArgumentException("Cannot unserialize '{$type}': Not found");
|
||||
if (null === $directory) {
|
||||
$grav = Grav::instance();
|
||||
/** @var Flex|null $flex */
|
||||
$flex = $grav['flex_objects'] ?? null;
|
||||
$directory = $flex ? $flex->getDirectory($type) : null;
|
||||
if (!$directory) {
|
||||
throw new \InvalidArgumentException("Cannot unserialize '{$type}': Not found");
|
||||
}
|
||||
}
|
||||
|
||||
$this->setFlexDirectory($directory);
|
||||
$this->setStorage($serialized['storage']);
|
||||
$this->setKey($serialized['key']);
|
||||
|
||||
Reference in New Issue
Block a user