mirror of
https://github.com/getgrav/grav.git
synced 2026-03-04 11:31:43 +01:00
Improve Flex storage
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
# v1.6.0-beta.7
|
||||
## mm/dd/2018
|
||||
|
||||
1. [](#improved)
|
||||
* Improve Flex storage
|
||||
|
||||
# v1.6.0-beta.6
|
||||
## 11/12/2018
|
||||
|
||||
|
||||
@@ -222,7 +222,6 @@ class FlexDirectory implements FlexAuthorizeInterface
|
||||
}
|
||||
|
||||
$object->save();
|
||||
//$rows = $storage->updateRows([$newKey => $object->triggerEvent('onSave')->prepareStorage()]);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -235,13 +234,6 @@ class FlexDirectory implements FlexAuthorizeInterface
|
||||
// Caching failed, but we can ignore that for now.
|
||||
}
|
||||
|
||||
/** @var FlexObject $class */
|
||||
//$class = $this->getObjectClass();
|
||||
//
|
||||
//$row = $object;
|
||||
//$index = $class::createIndex([key($rows) => time()]);
|
||||
//$object = $this->createObject($row, key($index), false);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface
|
||||
*/
|
||||
public function getStorageKey()
|
||||
{
|
||||
return $this->_storageKey;
|
||||
return $this->_storageKey ?? $this->__toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -115,7 +115,7 @@ abstract class AbstractFilesystemStorage implements FlexStorageInterface
|
||||
*/
|
||||
protected function generateKey() : string
|
||||
{
|
||||
return Base32::encode(Utils::generateRandomString(10));
|
||||
return substr(hash('sha256', random_bytes(32)), 0, 32);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,7 +64,7 @@ class FolderStorage extends AbstractFilesystemStorage
|
||||
*/
|
||||
public function hasKey(string $key) : bool
|
||||
{
|
||||
return $key && file_exists($this->getPathFromKey($key));
|
||||
return $key && !strpos($key, '@@') && file_exists($this->getPathFromKey($key));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,9 +93,13 @@ class FolderStorage extends AbstractFilesystemStorage
|
||||
foreach ($rows as $key => $row) {
|
||||
if (null === $row || (!\is_object($row) && !\is_array($row))) {
|
||||
// Only load rows which haven't been loaded before.
|
||||
$path = $this->getPathFromKey($key);
|
||||
$file = $this->getFile($path);
|
||||
$list[$key] = $this->hasKey($key) ? $this->loadFile($file) : null;
|
||||
if (!$this->hasKey($key)) {
|
||||
$list[$key] = null;
|
||||
} else {
|
||||
$path = $this->getPathFromKey($key);
|
||||
$file = $this->getFile($path);
|
||||
$list[$key] = $this->loadFile($file);
|
||||
}
|
||||
if (null !== $fetched) {
|
||||
$fetched[$key] = $list[$key];
|
||||
}
|
||||
@@ -115,9 +119,13 @@ class FolderStorage extends AbstractFilesystemStorage
|
||||
{
|
||||
$list = [];
|
||||
foreach ($rows as $key => $row) {
|
||||
$path = $this->getPathFromKey($key);
|
||||
$file = $this->getFile($path);
|
||||
$list[$key] = $this->hasKey($key) ? $this->saveFile($file, $row) : null;
|
||||
if (!$this->hasKey($key)) {
|
||||
$list[$key] = null;
|
||||
} else {
|
||||
$path = $this->getPathFromKey($key);
|
||||
$file = $this->getFile($path);
|
||||
$list[$key] = $this->saveFile($file, $row);
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
@@ -130,15 +138,19 @@ class FolderStorage extends AbstractFilesystemStorage
|
||||
{
|
||||
$list = [];
|
||||
foreach ($rows as $key => $row) {
|
||||
$path = $this->getPathFromKey($key);
|
||||
$file = $this->getFile($path);
|
||||
$list[$key] = $this->hasKey($key) ? $this->deleteFile($file) : null;
|
||||
if (!$this->hasKey($key)) {
|
||||
$list[$key] = null;
|
||||
} else {
|
||||
$path = $this->getPathFromKey($key);
|
||||
$file = $this->getFile($path);
|
||||
$list[$key] = $this->deleteFile($file);
|
||||
|
||||
$storage = $this->getStoragePath($key);
|
||||
$media = $this->getMediaPath($key);
|
||||
$storage = $this->getStoragePath($key);
|
||||
$media = $this->getMediaPath($key);
|
||||
|
||||
$this->deleteFolder($storage, true);
|
||||
$media && $this->deleteFolder($media, true);
|
||||
$this->deleteFolder($storage, true);
|
||||
$media && $this->deleteFolder($media, true);
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
@@ -151,6 +163,9 @@ class FolderStorage extends AbstractFilesystemStorage
|
||||
{
|
||||
$list = [];
|
||||
foreach ($rows as $key => $row) {
|
||||
if (strpos($key, '@@')) {
|
||||
$key = $this->getNewKey();
|
||||
}
|
||||
$path = $this->getPathFromKey($key);
|
||||
$file = $this->getFile($path);
|
||||
$list[$key] = $this->saveFile($file, $row);
|
||||
|
||||
@@ -68,7 +68,7 @@ class SimpleStorage extends AbstractFilesystemStorage
|
||||
*/
|
||||
public function hasKey(string $key) : bool
|
||||
{
|
||||
return isset($this->data[$key]);
|
||||
return $key && !strpos($key, '@@') && isset($this->data[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,7 +53,7 @@ trait ObjectTrait
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
return $this->_key ?: $this->getType() . '@' . spl_object_hash($this);
|
||||
return $this->_key ?: $this->getType() . '@@' . spl_object_hash($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user