Skip to content

Commit

Permalink
Merge pull request #124 from luca-rath/bugfix/invalidate-navigation-c…
Browse files Browse the repository at this point in the history
…ache

Fix invalidation of navigation cache
  • Loading branch information
Prokyonn authored Sep 20, 2022
2 parents 7a7f69b + 7dbc0d1 commit 9f3100e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
54 changes: 28 additions & 26 deletions EventSubscriber/NavigationInvalidationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,51 +91,53 @@ public static function getSubscribedEvents()

public function collectNavigationContextBeforePublishing(PublishEvent $event): void
{
$path = $this->documentInspector->getPath($event->getDocument());
$this->collectNavigationContexts($path, $event->getLocale());
$this->collectNavigationContexts($event->getDocument(), $event->getLocale());
}

public function collectNavigationContextBeforeUnpublishing(UnpublishEvent $event): void
{
$path = $this->documentInspector->getPath($event->getDocument());
$this->collectNavigationContexts($path, $event->getLocale());
$this->collectNavigationContexts($event->getDocument(), $event->getLocale());
}

public function collectNavigationContextBeforeRemoving(RemoveEvent $event): void
{
$document = $event->getDocument();
$path = $this->documentInspector->getPath($event->getDocument());
foreach ($this->documentInspector->getLocales($document) as $locale) {
$this->collectNavigationContexts($path, $locale);
}
$this->collectNavigationContexts($event->getDocument(), null);
}

public function collectNavigationContextBeforeRemovingLocale(RemoveLocaleEvent $event): void
{
$path = $this->documentInspector->getPath($event->getDocument());
$this->collectNavigationContexts($path, $event->getLocale());
$this->collectNavigationContexts($event->getDocument(), $event->getLocale());
}

public function collectNavigationContexts(string $path, string $locale): void
private function collectNavigationContexts(object $document, ?string $eventLocale): void
{
$path = $this->documentInspector->getPath($document);
$locales = $eventLocale ? [$eventLocale] : $this->documentInspector->getLocales($document);

$defaultNode = $this->defaultSession->getNode($path);
$liveNode = $this->liveSession->getNode($path);

$propertyName = $this->propertyEncoder->localizedContentName('navContexts', $locale);
$liveNavigationContexts = [];
$defaultNavigationContexts = [];
if ($liveNode->hasProperty($propertyName)) {
$liveNavigationContexts = $liveNode->getProperty($propertyName)->getValue();
foreach ($locales as $locale) {
$propertyName = $this->propertyEncoder->localizedContentName('navContexts', $locale);
$liveNavigationContexts = [];
$defaultNavigationContexts = [];

if ($liveNode->hasProperty($propertyName)) {
$liveNavigationContexts = $liveNode->getProperty($propertyName)->getValue();
}

if ($defaultNode->hasProperty($propertyName)) {
$defaultNavigationContexts = $defaultNode->getProperty($propertyName)->getValue();
}

$this->navigationContexts = \array_unique(
\array_merge(
$this->navigationContexts,
$liveNavigationContexts,
$defaultNavigationContexts
)
);
}
if ($defaultNode->hasProperty($propertyName)) {
$defaultNavigationContexts = $defaultNode->getProperty($propertyName)->getValue();
}

$this->navigationContexts = \array_merge(
$this->navigationContexts,
$liveNavigationContexts,
$defaultNavigationContexts
);
}

public function invalidateNavigationContexts(): void
Expand Down
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade

## 0.9.0

### Make NavigationInvalidationSubscriber::collectNavigationContexts method private

## 0.6.0

### Change constructor arguments of SingleSnippetSelectionResolver
Expand Down

0 comments on commit 9f3100e

Please sign in to comment.