mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-17 11:59:05 +00:00
Clean up some classes, extend API validation.
This commit is contained in:
@@ -26,6 +26,7 @@ namespace FireflyIII\Factory;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class TransactionJournalMetaFactory
|
||||
@@ -34,27 +35,27 @@ class TransactionJournalMetaFactory
|
||||
{
|
||||
public function updateOrCreate(array $data): ?TransactionJournalMeta
|
||||
{
|
||||
// app('log')->debug('In updateOrCreate()');
|
||||
// Log::debug('In updateOrCreate()');
|
||||
$value = $data['data'];
|
||||
|
||||
/** @var null|TransactionJournalMeta $entry */
|
||||
$entry = $data['journal']->transactionJournalMeta()->where('name', $data['name'])->first();
|
||||
if (null === $value && null !== $entry) {
|
||||
// app('log')->debug('Value is empty, delete meta value.');
|
||||
// Log::debug('Value is empty, delete meta value.');
|
||||
$entry->delete();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($data['data'] instanceof Carbon) {
|
||||
app('log')->debug('Is a carbon object.');
|
||||
Log::debug('Is a carbon object.');
|
||||
$value = $data['data']->toW3cString();
|
||||
}
|
||||
if ('' === (string) $value) {
|
||||
// app('log')->debug('Is an empty string.');
|
||||
// Log::debug('Is an empty string.');
|
||||
// don't store blank strings.
|
||||
if (null !== $entry) {
|
||||
app('log')->debug('Will not store empty strings, delete meta value');
|
||||
Log::debug('Will not store empty strings, delete meta value');
|
||||
$entry->delete();
|
||||
}
|
||||
|
||||
@@ -62,13 +63,13 @@ class TransactionJournalMetaFactory
|
||||
}
|
||||
|
||||
if (null === $entry) {
|
||||
// app('log')->debug('Will create new object.');
|
||||
app('log')->debug(sprintf('Going to create new meta-data entry to store "%s".', $data['name']));
|
||||
// Log::debug('Will create new object.');
|
||||
Log::debug(sprintf('Going to create new meta-data entry to store "%s".', $data['name']));
|
||||
$entry = new TransactionJournalMeta();
|
||||
$entry->transactionJournal()->associate($data['journal']);
|
||||
$entry->name = $data['name'];
|
||||
}
|
||||
app('log')->debug('Will update value and return.');
|
||||
Log::debug('Will update value and return.');
|
||||
$entry->data = $value;
|
||||
$entry->save();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user