Fix incorrect rule selection when deleting rules with same long URL

This commit is contained in:
Alejandro Celaya 2024-03-03 12:59:58 +01:00
parent 8751d6c315
commit 63c533fa62
2 changed files with 5 additions and 3 deletions

View File

@ -168,7 +168,9 @@ class RedirectRuleHandler implements RedirectRuleHandlerInterface
{ {
$choices = []; $choices = [];
foreach ($currentRules as $index => $rule) { 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)); $resp = $io->choice($message, array_flip($choices));

View File

@ -174,7 +174,7 @@ class RedirectRuleHandlerTest extends TestCase
$callIndex++; $callIndex++;
if ($message === 'What rule do you want to delete?') { 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 // First we select remove action to trigger code branch, then save to finish execution
@ -219,7 +219,7 @@ class RedirectRuleHandlerTest extends TestCase
$callIndex++; $callIndex++;
if ($message === 'What rule do you want to re-arrange?') { 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 // First we select remove action to trigger code branch, then save to finish execution