From 07f9c3482cfc6efe5f8ad7d1c25fa8aac2ada162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mu=CC=88ller?= Date: Thu, 4 Jan 2024 15:18:37 +0100 Subject: [PATCH] TASK: Adjust to media changes for asset replacement follow up Moves handling of asset redirects after resource replacement to the redirect package. See: https://github.com/neos/neos-development-collection/issues/4815 https://github.com/neos/neos-development-collection/pull/4816 --- Classes/AssetRedirectAfterReplacement.php | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Classes/AssetRedirectAfterReplacement.php diff --git a/Classes/AssetRedirectAfterReplacement.php b/Classes/AssetRedirectAfterReplacement.php new file mode 100644 index 0000000..37d6c59 --- /dev/null +++ b/Classes/AssetRedirectAfterReplacement.php @@ -0,0 +1,34 @@ +resourceManager->getPublicPersistentResourceUri($assetResourceReplaced->previousResource); + $newResourceUriString = $this->resourceManager->getPublicPersistentResourceUri($assetResourceReplaced->newResource); + + if (!is_string($originalResourceUriString) || !is_string($newResourceUriString)) { + return; + } + + $existingRedirect = $this->redirectStorage->getOneBySourceUriPathAndHost($originalResourceUriString); + if ($existingRedirect === null && $originalResourceUriString !== $newResourceUriString) { + $this->redirectStorage->addRedirect(new Uri($originalResourceUriString), new Uri($newResourceUriString), 301); + } + } +}