@@ -1086,9 +1086,10 @@ public function deleteShortlinkById(int $redirectId)
10861086
10871087 /**
10881088 * @param array $redirectConfig
1089- * @return bool whether the redirect was saved or not
1089+ * @param bool $checkForRedirectLoop
1090+ * @return bool
10901091 */
1091- public function saveRedirect (array $ redirectConfig ): bool
1092+ public function saveRedirect (array $ redirectConfig, bool $ checkForRedirectLoop = true ): bool
10921093 {
10931094 // Handle URL encoded URLs by decoding them before saving them
10941095 if (isset ($ redirectConfig ['redirectMatchType ' ]) && $ redirectConfig ['redirectMatchType ' ] === 'exactmatch ' ) {
@@ -1201,28 +1202,30 @@ public function saveRedirect(array $redirectConfig): bool
12011202 return false ;
12021203 }
12031204 }
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__
1205+ if ($ checkForRedirectLoop ) {
1206+ // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl
1207+ $ testRedirectConfig = $ this ->getRedirectByRedirectSrcUrl (
1208+ $ redirectConfig ['redirectDestUrl ' ],
1209+ $ redirectConfig ['siteId ' ]
12171210 );
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__ );
1211+ if ($ testRedirectConfig !== null ) {
1212+ Craft::debug (
1213+ Craft::t (
1214+ 'retour ' ,
1215+ 'Deleting redirect to prevent a loop: {redirect} ' ,
1216+ ['redirect ' => print_r ($ testRedirectConfig , true )]
1217+ ),
1218+ __METHOD__
1219+ );
1220+ // Delete the redirect that has a redirectSrcUrl the same as this record's redirectDestUrl
1221+ try {
1222+ $ db ->createCommand ()->delete (
1223+ '{{%retour_static_redirects}} ' ,
1224+ ['id ' => $ testRedirectConfig ['id ' ]]
1225+ )->execute ();
1226+ } catch (Exception $ e ) {
1227+ Craft::error ($ e ->getMessage (), __METHOD__ );
1228+ }
12261229 }
12271230 }
12281231 // Trigger a 'afterSaveRedirect' event
0 commit comments