Skip to content

Commit cb1cf83

Browse files
committed
Revert "refactor: When saving a redirect, Retour no longer deletes redirects that have the redirectDestUrl of the redirect being saved as their redirectSrcUrl ([#303](#303))"
This reverts commit 794cbf6.
1 parent 2a09809 commit cb1cf83

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/services/Redirects.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,30 @@ public function saveRedirect(array $redirectConfig): bool
12011201
return false;
12021202
}
12031203
}
1204+
// To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl
1205+
$testRedirectConfig = $this->getRedirectByRedirectSrcUrl(
1206+
$redirectConfig['redirectDestUrl'],
1207+
$redirectConfig['siteId']
1208+
);
1209+
if ($testRedirectConfig !== null) {
1210+
Craft::debug(
1211+
Craft::t(
1212+
'retour',
1213+
'Deleting redirect to prevent a loop: {redirect}',
1214+
['redirect' => print_r($testRedirectConfig, true)]
1215+
),
1216+
__METHOD__
1217+
);
1218+
// Delete the redirect that has a redirectSrcUrl the same as this record's redirectDestUrl
1219+
try {
1220+
$db->createCommand()->delete(
1221+
'{{%retour_static_redirects}}',
1222+
['id' => $testRedirectConfig['id']]
1223+
)->execute();
1224+
} catch (Exception $e) {
1225+
Craft::error($e->getMessage(), __METHOD__);
1226+
}
1227+
}
12041228
// Trigger a 'afterSaveRedirect' event
12051229
$this->trigger(self::EVENT_AFTER_SAVE_REDIRECT, $event);
12061230

0 commit comments

Comments
 (0)