From 822f609a22d0d906124436ba6f9f5690c7da7802 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 18 May 2024 06:44:18 +0200 Subject: [PATCH] Fix ibans --- app/Console/Commands/Correction/FixIbans.php | 28 +++++++++----------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/app/Console/Commands/Correction/FixIbans.php b/app/Console/Commands/Correction/FixIbans.php index 27e79a1c5b..6a12bbfc8b 100644 --- a/app/Console/Commands/Correction/FixIbans.php +++ b/app/Console/Commands/Correction/FixIbans.php @@ -37,9 +37,9 @@ class FixIbans extends Command { use ShowsFriendlyMessages; - protected $description = 'Removes spaces from IBANs'; - protected $signature = 'firefly-iii:fix-ibans'; - private int $count = 0; + protected $description = 'Removes spaces from IBANs'; + protected $signature = 'firefly-iii:fix-ibans'; + private int $count = 0; /** * Execute the console command. @@ -60,15 +60,13 @@ class FixIbans extends Command { /** @var Account $account */ foreach ($accounts as $account) { - $iban = $account->iban; - if (str_contains($iban, ' ')) { - $iban = app('steam')->filterSpaces((string)$account->iban); - if ('' !== $iban) { - $account->iban = $iban; - $account->save(); - $this->friendlyInfo(sprintf('Removed spaces from IBAN of account #%d', $account->id)); - ++$this->count; - } + $iban = (string) $account->iban; + $newIban = app('steam')->filterSpaces($iban); + if ('' !== $iban && $iban !== $newIban) { + $account->iban = $newIban; + $account->save(); + $this->friendlyInfo(sprintf('Removed spaces from IBAN of account #%d', $account->id)); + ++$this->count; } } } @@ -79,13 +77,13 @@ class FixIbans extends Command /** @var Account $account */ foreach ($accounts as $account) { - $userId = $account->user_id; + $userId = $account->user_id; $set[$userId] ??= []; - $iban = (string)$account->iban; + $iban = (string) $account->iban; if ('' === $iban) { continue; } - $type = $account->accountType->type; + $type = $account->accountType->type; if (in_array($type, [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], true)) { $type = 'liabilities'; }