mirror of
https://github.com/getgrav/grav.git
synced 2026-03-06 12:31:53 +01:00
Improve new flex object saving and storage
This commit is contained in:
@@ -422,7 +422,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->getFlexDirectory()->getStorage()->replaceRows([$this->getStorageKey() => $this->prepareStorage()]);
|
||||
$result = $this->getFlexDirectory()->getStorage()->replaceRows([$this->getStorageKey() => $this->prepareStorage()]);
|
||||
|
||||
try {
|
||||
$this->getFlexDirectory()->clearCache();
|
||||
@@ -437,6 +437,12 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
|
||||
// Caching failed, but we can ignore that for now.
|
||||
}
|
||||
|
||||
$value = reset($result);
|
||||
$storageKey = key($result);
|
||||
if ($value && $storageKey) {
|
||||
$this->setStorageKey($storageKey);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class FileStorage extends FolderStorage
|
||||
*/
|
||||
public function __construct(array $options)
|
||||
{
|
||||
$this->dataPattern = '%1s/%2s';
|
||||
$this->dataPattern = '{FOLDER}/{KEY}';
|
||||
|
||||
if (!isset($options['formatter']) && isset($options['pattern'])) {
|
||||
$options['formatter'] = $this->detectDataFormatter($options['pattern']);
|
||||
|
||||
@@ -26,7 +26,9 @@ class FolderStorage extends AbstractFilesystemStorage
|
||||
/** @var string */
|
||||
protected $dataFolder;
|
||||
/** @var string */
|
||||
protected $dataPattern = '%1s/%2s/item';
|
||||
protected $dataPattern = '{FOLDER}/{KEY}/item';
|
||||
/** @var bool */
|
||||
protected $indexed;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -198,7 +200,7 @@ class FolderStorage extends AbstractFilesystemStorage
|
||||
if (null === $key) {
|
||||
$path = $this->dataFolder;
|
||||
} else {
|
||||
$path = sprintf($this->dataPattern, $this->dataFolder, $key);
|
||||
$path = sprintf($this->dataPattern, $this->dataFolder, $key, substr($key, 0, 2));
|
||||
}
|
||||
|
||||
return $path;
|
||||
@@ -220,7 +222,7 @@ class FolderStorage extends AbstractFilesystemStorage
|
||||
*/
|
||||
public function getPathFromKey(string $key) : string
|
||||
{
|
||||
return sprintf($this->dataPattern, $this->dataFolder, $key);
|
||||
return sprintf($this->dataPattern, $this->dataFolder, $key, substr($key, 0, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,8 +381,10 @@ class FolderStorage extends AbstractFilesystemStorage
|
||||
{
|
||||
$extension = $this->dataFormatter->getDefaultFileExtension();
|
||||
$pattern = !empty($options['pattern']) ? $options['pattern'] : $this->dataPattern;
|
||||
$pattern = preg_replace(['/{FOLDER}/', '/{KEY}/', '/{KEY:2}/'], ['%1$s', '%2$s', '%3$s'], $pattern);
|
||||
|
||||
$this->dataPattern = \dirname($pattern) . '/' . basename($pattern, $extension) . $extension;
|
||||
$this->dataFolder = $options['folder'];
|
||||
$this->indexed = (bool)($options['indexed'] ?? false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user