Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Make sure IBAN's have their spaces removed.
James Cole87ced8565775
diff --git a/app/Console/Commands/Correction/CorrectDatabase.php b/app/Console/Commands/Correction/CorrectDatabase.phpindex 6c378372f8..02059baadf 100644--- a/app/Console/Commands/Correction/CorrectDatabase.php+++ b/app/Console/Commands/Correction/CorrectDatabase.php@@ -69,6 +69,7 @@ class CorrectDatabase extends Command'firefly-iii:delete-empty-journals','firefly-iii:delete-empty-groups','firefly-iii:fix-account-types',+ 'firefly-iii:fix-ibans','firefly-iii:fix-account-order','firefly-iii:rename-meta-fields','firefly-iii:fix-ob-currencies',diff --git a/app/Console/Commands/Correction/FixIbans.php b/app/Console/Commands/Correction/FixIbans.phpnew file mode 100644index 0000000000..5da57a16f6--- /dev/null+++ b/app/Console/Commands/Correction/FixIbans.php@@ -0,0 +1,50 @@+<?php++namespace FireflyIII\Console\Commands\Correction;++use FireflyIII\Models\Account;+use Illuminate\Console\Command;++/**+ * Class FixIbans+ */+class FixIbans extends Command+{+ /**+ * The console command description.+ *+ * @var string+ */+ protected $description = 'Removes spaces from IBANs';+ /**+ * The name and signature of the console command.+ *+ * @var string+ */+ protected $signature = 'firefly-iii:fix-ibans';++ /**+ * Execute the console command.+ *+ * @return int+ */+ public function handle(): int+ {+ $accounts = Account::whereNotNull('iban')->get();+ /** @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->line(sprintf('Removed spaces from IBAN of account #%d', $account->id));+ }+ }+ }++ return 0;+ }+}diff --git a/app/Console/Commands/Upgrade/UpgradeDatabase.php b/app/Console/Commands/Upgrade/UpgradeDatabase.phpindex 48d7c9f1aa..d0fee361ef 100644--- a/app/Console/Commands/Upgrade/UpgradeDatabase.php+++ b/app/Console/Commands/Upgrade/UpgradeDatabase.php@@ -98,6 +98,7 @@ class UpgradeDatabase extends Command'firefly-iii:unify-group-accounts','firefly-iii:fix-transaction-types','firefly-iii:fix-frontpage-accounts',+ 'firefly-iii:fix-ibans',// two report commands'firefly-iii:report-empty-objects',diff --git a/app/Http/Controllers/System/InstallController.php b/app/Http/Controllers/System/InstallController.phpindex 5c19c32cac..9a91f7c2f3 100644--- a/app/Http/Controllers/System/InstallController.php+++ b/app/Http/Controllers/System/InstallController.php@@ -109,6 +109,7 @@ class InstallController extends Controller'firefly-iii:unify-group-accounts' => [],'firefly-iii:fix-transaction-types' => [],'firefly-iii:fix-frontpage-accounts' => [],+ 'firefly-iii:fix-ibans' => [],// final command to set latest version in DB'firefly-iii:set-latest-version' => ['--james-is-cool' => true],diff --git a/app/Services/Internal/Support/AccountServiceTrait.php b/app/Services/Internal/Support/AccountServiceTrait.phpindex 2ea1715b4f..e760f29d5e 100644--- a/app/Services/Internal/Support/AccountServiceTrait.php+++ b/app/Services/Internal/Support/AccountServiceTrait.php@@ -69,7 +69,8 @@ trait AccountServiceTraitreturn null;}- return $iban;++ return app('steam')->filterSpaces($iban);}/**diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.phpindex 16e9d7f2ec..51add15fba 100644--- a/app/Services/Internal/Update/AccountUpdateService.php+++ b/app/Services/Internal/Update/AccountUpdateService.php@@ -135,7 +135,7 @@ class AccountUpdateService$account->active = $data['active'];}if (array_key_exists('iban', $data)) {- $account->iban = $data['iban'];+ $account->iban = app('steam')->filterSpaces((string)$data['iban']);}// set liability, but account must already be a liability.diff --git a/app/Support/Steam.php b/app/Support/Steam.phpindex c6ad2e51ac..b6d57bf340 100644--- a/app/Support/Steam.php+++ b/app/Support/Steam.php@@ -540,4 +540,62 @@ class Steamreturn $amount;}+ /**+ * @param string $string+ *+ * @return string+ */+ public function filterSpaces(string $string): string+ {+ $search = [+ "\u{0001}", // start of heading+ "\u{0002}", // start of text+ "\u{0003}", // end of text+ "\u{0004}", // end of transmission+ "\u{0005}", // enquiry+ "\u{0006}", // ACK+ "\u{0007}", // BEL+ "\u{0008}", // backspace+ "\u{000E}", // shift out+ "\u{000F}", // shift in+ "\u{0010}", // data link escape+ "\u{0011}", // DC1+ "\u{0012}", // DC2+ "\u{0013}", // DC3+ "\u{0014}", // DC4+ "\u{0015}", // NAK+ "\u{0016}", // SYN+ "\u{0017}", // ETB+ "\u{0018}", // CAN+ "\u{0019}", // EM+ "\u{001A}", // SUB+ "\u{001B}", // escape+ "\u{001C}", // file separator+ "\u{001D}", // group separator+ "\u{001E}", // record separator+ "\u{001F}", // unit separator+ "\u{007F}", // DEL+ "\u{00A0}", // non-breaking space+ "\u{1680}", // ogham space mark+ "\u{180E}", // mongolian vowel separator+ "\u{2000}", // en quad+ "\u{2001}", // em quad+ "\u{2002}", // en space+ "\u{2003}", // em space+ "\u{2004}", // three-per-em space+ "\u{2005}", // four-per-em space+ "\u{2006}", // six-per-em space+ "\u{2007}", // figure space+ "\u{2008}", // punctuation space+ "\u{2009}", // thin space+ "\u{200A}", // hair space+ "\u{200B}", // zero width space+ "\u{202F}", // narrow no-break space+ "\u{3000}", // ideographic space+ "\u{FEFF}", // zero width no -break space+ "\x20", // plain old normal space+ ];++ return str_replace($search, '', $string);+ }}diff --git a/composer.json b/composer.jsonindex 0102b413d5..67e4f91d77 100644--- a/composer.json+++ b/composer.json@@ -193,6 +193,7 @@"@php artisan firefly-iii:unify-group-accounts","@php artisan firefly-iii:fix-transaction-types","@php artisan firefly-iii:fix-frontpage-accounts",+ "@php artisan firefly-iii:fix-ibans","@php artisan firefly-iii:report-empty-objects","@php artisan firefly-iii:report-sum","@php artisan firefly-iii:restore-oauth-keys",