Skip to content

Commit

Permalink
Merge pull request #1574 from kdambekalns/bugfix/1573-resource-redirects
Browse files Browse the repository at this point in the history
BUGFIX: Create resource redirects correctly
  • Loading branch information
kdambekalns authored May 24, 2017
2 parents 0266386 + 6ca09dd commit 1141b01
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions TYPO3.Media/Classes/TYPO3/Media/Domain/Service/AssetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
* source code.
*/

use Neos\RedirectHandler\Storage\RedirectStorageInterface;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Http\Uri;
use TYPO3\Flow\Mvc\ActionRequest;
use TYPO3\Flow\Mvc\Routing\UriBuilder;
use TYPO3\Flow\Object\ObjectManagerInterface;
Expand Down Expand Up @@ -248,9 +250,9 @@ public function replaceAssetResource(AssetInterface $asset, FlowResource $resour
$uriMapping = [];
$redirectHandlerEnabled = isset($options['generateRedirects']) && (boolean)$options['generateRedirects'] === true && $this->packageManager->isPackageAvailable('Neos.RedirectHandler');
if ($redirectHandlerEnabled) {
$uriMapping[
$this->resourceManager->getPublicPersistentResourceUri($originalAssetResource)
] = $this->resourceManager->getPublicPersistentResourceUri($asset->getResource());
$originalAssetResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($originalAssetResource));
$newAssetResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($asset->getResource()));
$uriMapping[$originalAssetResourceUri->getPath()] = $newAssetResourceUri->getPath();
}

if (method_exists($asset, 'getVariants')) {
Expand All @@ -266,18 +268,18 @@ public function replaceAssetResource(AssetInterface $asset, FlowResource $resour
}

if ($redirectHandlerEnabled) {
$uriMapping[
$this->resourceManager->getPublicPersistentResourceUri($originalVariantResource)
] = $this->resourceManager->getPublicPersistentResourceUri($variant->getResource());
$originalVariantResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($originalVariantResource));
$newVariantResourceUri = new Uri($this->resourceManager->getPublicPersistentResourceUri($variant->getResource()));
$uriMapping[$originalVariantResourceUri->getPath()] = $newVariantResourceUri->getPath();
}

$this->getRepository($variant)->update($variant);
}
}

if ($redirectHandlerEnabled) {
/** @var \Neos\RedirectHandler\Storage\RedirectStorageInterface $redirectStorage */
$redirectStorage = $this->objectManager->get('Neos\\RedirectHandler\\Storage\\RedirectStorageInterface');
/** @var RedirectStorageInterface $redirectStorage */
$redirectStorage = $this->objectManager->get(RedirectStorageInterface::class);
foreach ($uriMapping as $originalUri => $newUri) {
$existingRedirect = $redirectStorage->getOneBySourceUriPathAndHost($originalUri);
if ($existingRedirect === null) {
Expand Down

0 comments on commit 1141b01

Please sign in to comment.