Will not store fields with empty strings or weird value

This commit is contained in:
James Cole 2018-04-22 08:07:33 +02:00
parent 529dd490b7
commit 49421f50ac
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 19 additions and 11 deletions

View File

@ -329,18 +329,22 @@ trait AccountServiceTrait
/** @var AccountMeta $entry */
$entry = $account->accountMeta()->where('name', $field)->first();
// if $data has field and $entry is null, create new one:
if (isset($data[$field]) && null === $entry) {
Log::debug(sprintf('Created meta-field "%s":"%s" for account #%d ("%s") ', $field, $data[$field], $account->id, $account->name));
$factory->create(['account_id' => $account->id, 'name' => $field, 'data' => $data[$field],]);
}
// must not be an empty string:
if (isset($data[$field]) && strlen((string)$data[$field]) > 0) {
// if $data has field and $entry is not null, update $entry:
// let's not bother with a service.
if (isset($data[$field]) && null !== $entry) {
$entry->data = $data[$field];
$entry->save();
Log::debug(sprintf('Updated meta-field "%s":"%s" for #%d ("%s") ', $field, $data[$field], $account->id, $account->name));
// if $data has field and $entry is null, create new one:
if (null === $entry) {
Log::debug(sprintf('Created meta-field "%s":"%s" for account #%d ("%s") ', $field, $data[$field], $account->id, $account->name));
$factory->create(['account_id' => $account->id, 'name' => $field, 'data' => $data[$field],]);
}
// if $data has field and $entry is not null, update $entry:
// let's not bother with a service.
if (null !== $entry) {
$entry->data = $data[$field];
$entry->save();
Log::debug(sprintf('Updated meta-field "%s":"%s" for #%d ("%s") ', $field, $data[$field], $account->id, $account->name));
}
}
}
}

View File

@ -51,6 +51,10 @@ class AccountUpdateService
$account->iban = $data['iban'];
$account->save();
if($data['currency_id'] === 0) {
unset($data['currency_id']);
}
// update all meta data:
$this->updateMetaData($account, $data);