mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Remove spaces from account numbers.
This commit is contained in:
@@ -43,7 +43,7 @@ class CorrectsIbans extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$accounts = Account::whereNotNull('iban')->get();
|
$accounts = Account::with('accountMeta')->get();
|
||||||
$this->filterIbans($accounts);
|
$this->filterIbans($accounts);
|
||||||
$this->countAndCorrectIbans($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->friendlyInfo(sprintf('Removed spaces from IBAN of account #%d', $account->id));
|
||||||
++$this->count;
|
++$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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -26,6 +26,7 @@ namespace FireflyIII\Factory;
|
|||||||
|
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountMeta;
|
use FireflyIII\Models\AccountMeta;
|
||||||
|
use FireflyIII\Support\Facades\Steam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountMetaFactory
|
* Class AccountMetaFactory
|
||||||
@@ -41,11 +42,16 @@ class AccountMetaFactory
|
|||||||
$entry = $account->accountMeta()->where('name', $field)->first();
|
$entry = $account->accountMeta()->where('name', $field)->first();
|
||||||
// must not be an empty string:
|
// must not be an empty string:
|
||||||
if ('' !== $value) {
|
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 $data has field and $entry is null, create new one:
|
||||||
if (null === $entry) {
|
if (null === $entry) {
|
||||||
return $this->create(['account_id' => $account->id, 'name' => $field, 'data' => $value]);
|
return $this->create(['account_id' => $account->id, 'name' => $field, 'data' => $value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if $data has field and $entry is not null, update $entry:
|
// if $data has field and $entry is not null, update $entry:
|
||||||
$entry->data = $value;
|
$entry->data = $value;
|
||||||
$entry->save();
|
$entry->save();
|
||||||
|
Reference in New Issue
Block a user