Skip to content

Commit d78ab09

Browse files
committed
Fix issue deleting a route when there are redirects pointing to it
1 parent 870dbb2 commit d78ab09

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

features/bootstrap/DoctrineContext.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ public function thereIsARouteWithRedirects(string $firstPath, string $redirectTo
494494

495495
$this->restContext->resources['final_route'] = $this->iriConverter->getIriFromResource($finalRoute);
496496
$this->restContext->resources['route'] = $this->iriConverter->getIriFromResource($route);
497+
$this->restContext->resources['middle_route'] = $this->iriConverter->getIriFromResource($middleRoute);
497498
$this->restContext->resources['route_page'] = $this->iriConverter->getIriFromResource($page);
498499
}
499500

features/main/route.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ Feature: Route resources
3333
When I send a "DELETE" request to the resource "route"
3434
Then the response status code should be 204
3535

36+
@loginUser
37+
Scenario: I can delete a route which has a redirect
38+
Given there is a Route "/contact" which redirects to "/contact-new"
39+
When I send a "DELETE" request to the resource "final_route"
40+
Then the response status code should be 204
41+
And the resource "final_route" should not exist
42+
And the resource "route" should not exist
43+
And the resource "middle_route" should not exist
44+
3645
Scenario: A route will output the nested redirect routes and data for the redirected page
3746
Given there is a Route "/contact" which redirects to "/contact-new"
3847
When I send a "GET" request to "/_/routes//contact"

src/EventListener/Api/RouteEventListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function onPostWrite(ViewEvent $event): void
6969
throw new InvalidArgumentException(sprintf('Could not find entity manager for %s', $className));
7070
}
7171

72-
// create a redirect fro the old route
72+
// create a redirect from the old route
7373
$previousRouteData = $request->attributes->get('previous_data');
7474
$previousPath = $previousRouteData->getPath();
7575
if ($previousPath !== $data->getPath()) {

src/Serializer/Normalizer/RouteNormalizer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public function normalize($object, $format = null, array $context = []): float|a
4040

4141
$redirectedRoutes = [$finalRoute->getId()];
4242
while ($nextRedirect = $finalRoute->getRedirect()) {
43+
// if a route has just been deleted which had other routes redirecting to it, then they will delete - but appear here as a redirect still without an ID for some reason
44+
if (!$nextRedirect->getId()) {
45+
break;
46+
}
4347
if (\in_array($nextRedirect->getId(), $redirectedRoutes, true)) {
4448
throw new CircularReferenceException(sprintf('The redirect routes result in a circular reference: %s', implode(' -> ', $redirectedRoutes)));
4549
}

0 commit comments

Comments
 (0)