diff --git a/app/Console/Commands/Correction/CorrectsIbans.php b/app/Console/Commands/Correction/CorrectsIbans.php index d3f1705612..8502350322 100644 --- a/app/Console/Commands/Correction/CorrectsIbans.php +++ b/app/Console/Commands/Correction/CorrectsIbans.php @@ -43,7 +43,7 @@ class CorrectsIbans extends Command */ public function handle(): int { - $accounts = Account::whereNotNull('iban')->get(); + $accounts = Account::with('accountMeta')->get(); $this->filterIbans($accounts); $this->countAndCorrectIbans($accounts); @@ -62,6 +62,18 @@ class CorrectsIbans extends Command $this->friendlyInfo(sprintf('Removed spaces from IBAN of account #%d', $account->id)); ++$this->count; } + // same for account number: + $accountNumber = $account->accountMeta->where('name', 'account_number')->first(); + if(null !== $accountNumber) { + $number = (string) $accountNumber->value; + $newNumber = app('steam')->filterSpaces($number); + if ('' !== $number && $number !== $newNumber) { + $accountNumber->value = $newNumber; + $accountNumber->save(); + $this->friendlyInfo(sprintf('Removed spaces from account number of account #%d', $account->id)); + ++$this->count; + } + } } } diff --git a/app/Factory/AccountMetaFactory.php b/app/Factory/AccountMetaFactory.php index cad3bdddb6..6193dc4147 100644 --- a/app/Factory/AccountMetaFactory.php +++ b/app/Factory/AccountMetaFactory.php @@ -26,6 +26,7 @@ namespace FireflyIII\Factory; use FireflyIII\Models\Account; use FireflyIII\Models\AccountMeta; +use FireflyIII\Support\Facades\Steam; /** * Class AccountMetaFactory @@ -41,11 +42,16 @@ class AccountMetaFactory $entry = $account->accountMeta()->where('name', $field)->first(); // must not be an empty string: if ('' !== $value) { + if('account_number' === $field) { + $value = Steam::filterSpaces($value); + $value = trim(str_replace([' ',"\t", "\n", "\r"], '', $value)); + } // if $data has field and $entry is null, create new one: if (null === $entry) { return $this->create(['account_id' => $account->id, 'name' => $field, 'data' => $value]); } + // if $data has field and $entry is not null, update $entry: $entry->data = $value; $entry->save();