Skip to content

Commit 47f6e95

Browse files
authored
Merge pull request #19 from Flowpack/task/neos-7-8-compatibility
TASK: Stay compatible with Neos 7 + 8
2 parents 22a5260 + a170dba commit 47f6e95

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

Classes/NodeRendering/Infrastructure/RedisContentCacheReader.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
use Flowpack\DecoupledContentStore\NodeRendering\Dto\DocumentNodeCacheValues;
77
use Flowpack\DecoupledContentStore\NodeRendering\Dto\RenderedDocumentFromContentCache;
88
use Neos\Cache\Backend\AbstractBackend;
9+
use Neos\Cache\Backend\RedisBackend;
910
use Neos\Cache\Frontend\StringFrontend;
1011
use Neos\Flow\Annotations as Flow;
11-
use Flowpack\DecoupledContentStore\Core\Infrastructure\RedisClientManager;
12+
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
13+
use Neos\Flow\Package\PackageManager;
1214
use Neos\Fusion\Core\Cache\ContentCache;
13-
use Neos\Cache\Backend\RedisBackend;
1415

1516
/**
1617
* @Flow\Scope("singleton")
@@ -20,15 +21,15 @@ class RedisContentCacheReader
2021

2122
/**
2223
* @Flow\Inject
23-
* @var RedisClientManager
24+
* @var StringFrontend
2425
*/
25-
protected $redisClient;
26+
protected $contentCache;
2627

2728
/**
2829
* @Flow\Inject
29-
* @var StringFrontend
30+
* @var ObjectManagerInterface
3031
*/
31-
protected $contentCache;
32+
protected $objectManager;
3233

3334
/**
3435
* @Flow\InjectConfiguration(path="cache.applicationIdentifier", package="Neos.Flow")
@@ -47,14 +48,22 @@ public function tryToExtractRenderingForEnumeratedNodeFromContentCache(DocumentN
4748
*/
4849
$identifierPrefix = md5($this->applicationIdentifier) . ':';
4950

50-
$redis = null;
51+
$packageManager = $this->objectManager->get(PackageManager::class);
52+
$flowPackage = $packageManager->getPackage('Neos.Flow');
53+
preg_match('/^(\d+\.\d+)/', $flowPackage->getInstalledVersion(), $versionMatches);
54+
$flowMajorVersion = (int)($versionMatches[1] ?? '0');
55+
5156
$backend = $this->contentCache->getBackend();
52-
if ($backend instanceof RedisBackend) {
57+
if ($flowMajorVersion >= 8 && $backend instanceof RedisBackend) {
5358
$reflProp = new \ReflectionProperty(RedisBackend::class, 'redis');
5459
$reflProp->setAccessible(true);
5560
$redis = $reflProp->getValue($backend);
61+
} elseif (get_class($backend) === 'Sandstorm\OptimizedRedisCacheBackend\OptimizedRedisCacheBackend') {
62+
$reflProp = new \ReflectionProperty(\Sandstorm\OptimizedRedisCacheBackend\OptimizedRedisCacheBackend::class, 'redis');
63+
$reflProp->setAccessible(true);
64+
$redis = $reflProp->getValue($backend);
5665
} else {
57-
throw new \RuntimeException('TODO: Cache backend must be OptimizedRedisCacheBackend.');
66+
throw new \RuntimeException('The cache backend for "Neos_Fusion_Content" must be an OptimizedRedisCacheBackend, but is ' . get_class($backend), 1622570000);
5867
}
5968
$serializedCacheValues = $redis->get($documentNodeCacheKey->fullyQualifiedRedisKeyName($identifierPrefix));
6069
if ($serializedCacheValues === false) {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ as the basis for orchestrating and executing a content release.
4747
## Requirements
4848

4949
- Redis
50-
- Sandstorm.OptimizedCacheBackend recommended
50+
- Sandstorm.OptimizedCacheBackend is required when this package is used with Neos 7.3 (Neos 8 already has an optimized Redis backend)
5151
- Prunner
5252

5353
Start up prunner via the following command:

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
"type": "neos-package",
44
"name": "flowpack/decoupledcontentstore",
55
"require": {
6-
"php": "^8.0",
7-
"neos/neos": "^8.0",
6+
"php": "^7.4 || ^8.0",
7+
"neos/neos": "^7.3 || ^8.0",
88
"albertofem/rsync-lib": "~1.0",
99
"flowpack/prunner": "*"
1010
},
11+
"suggest": {
12+
"sandstorm/optimizedrediscachebackend": "This package is only needed when this package is being used with Neos 7.3"
13+
},
1114
"autoload": {
1215
"psr-4": {
1316
"Flowpack\\DecoupledContentStore\\": "Classes/"

0 commit comments

Comments
 (0)