From d9dbe5520d4e7cf41e778e2d8b340b89cf7d0b2c Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 29 Aug 2019 15:04:45 +0300 Subject: [PATCH] Added version support to Flex index file --- system/src/Grav/Framework/Flex/FlexIndex.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Framework/Flex/FlexIndex.php b/system/src/Grav/Framework/Flex/FlexIndex.php index 9d3e020b3..2eae0cbdf 100644 --- a/system/src/Grav/Framework/Flex/FlexIndex.php +++ b/system/src/Grav/Framework/Flex/FlexIndex.php @@ -28,6 +28,8 @@ use Psr\SimpleCache\InvalidArgumentException; class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexIndexInterface { + const VERSION = 1; + /** @var FlexDirectory */ private $_flexDirectory; @@ -680,7 +682,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde static::onChanges($index, $added, $updated, $removed); - $indexFile->save(['timestamp' => time(), 'count' => \count($index), 'index' => $index]); + $indexFile->save(['version' => static::VERSION, 'timestamp' => time(), 'count' => \count($index), 'index' => $index]); $indexFile->unlock(); return $index; @@ -697,13 +699,17 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde $data = []; try { $data = (array)$indexFile->content(); + $version = $data['version'] ?? null; + if ($version !== static::VERSION) { + $data = []; + } } catch (\Exception $e) { $e = new \RuntimeException(sprintf('Index failed to load: %s', $e->getMessage()), $e->getCode(), $e); static::onException($e); } - return $data ?: ['timestamp' => 0, 'count' => 0, 'index' => []]; + return $data ?: ['version' => static::VERSION, 'timestamp' => 0, 'count' => 0, 'index' => []]; } protected static function loadEntriesFromIndex(FlexStorageInterface $storage)