From 63c533fa62359beacd9a5e469d9592fd7c3d7429 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 3 Mar 2024 12:59:58 +0100 Subject: [PATCH] Fix incorrect rule selection when deleting rules with same long URL --- module/CLI/src/RedirectRule/RedirectRuleHandler.php | 4 +++- module/CLI/test/RedirectRule/RedirectRuleHandlerTest.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/module/CLI/src/RedirectRule/RedirectRuleHandler.php b/module/CLI/src/RedirectRule/RedirectRuleHandler.php index 7470d3b5..068cdc74 100644 --- a/module/CLI/src/RedirectRule/RedirectRuleHandler.php +++ b/module/CLI/src/RedirectRule/RedirectRuleHandler.php @@ -168,7 +168,9 @@ class RedirectRuleHandler implements RedirectRuleHandlerInterface { $choices = []; foreach ($currentRules as $index => $rule) { - $choices[$rule->longUrl] = $index + 1; + $priority = $index + 1; + $key = sprintf('%s - %s', $priority, $rule->longUrl); + $choices[$key] = $priority; } $resp = $io->choice($message, array_flip($choices)); diff --git a/module/CLI/test/RedirectRule/RedirectRuleHandlerTest.php b/module/CLI/test/RedirectRule/RedirectRuleHandlerTest.php index df448a8d..0c0b7d12 100644 --- a/module/CLI/test/RedirectRule/RedirectRuleHandlerTest.php +++ b/module/CLI/test/RedirectRule/RedirectRuleHandlerTest.php @@ -174,7 +174,7 @@ class RedirectRuleHandlerTest extends TestCase $callIndex++; if ($message === 'What rule do you want to delete?') { - return 'https://example.com/two'; // Second rule to be removed + return '2 - https://example.com/two'; // Second rule to be removed } // First we select remove action to trigger code branch, then save to finish execution @@ -219,7 +219,7 @@ class RedirectRuleHandlerTest extends TestCase $callIndex++; if ($message === 'What rule do you want to re-arrange?') { - return 'https://example.com/two'; // Second rule to be re-arrange + return '2 - https://example.com/two'; // Second rule to be re-arrange } // First we select remove action to trigger code branch, then save to finish execution