mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-01 02:21:45 +00:00
Clean up some classes, extend API validation.
This commit is contained in:
@@ -31,6 +31,7 @@ use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
|
||||
use FireflyIII\Services\Internal\Support\BillServiceTrait;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class BillFactory
|
||||
@@ -47,7 +48,7 @@ class BillFactory
|
||||
*/
|
||||
public function create(array $data): ?Bill
|
||||
{
|
||||
app('log')->debug(sprintf('Now in %s', __METHOD__), $data);
|
||||
Log::debug(sprintf('Now in %s', __METHOD__), $data);
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
$currency = $factory->find((int) ($data['currency_id'] ?? null), (string) ($data['currency_code'] ?? null))
|
||||
?? app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
|
||||
@@ -82,8 +83,8 @@ class BillFactory
|
||||
]
|
||||
);
|
||||
} catch (QueryException $e) {
|
||||
app('log')->error($e->getMessage());
|
||||
app('log')->error($e->getTraceAsString());
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
throw new FireflyException('400000: Could not store bill.', 0, $e);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
/**
|
||||
* Class CategoryFactory
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ class CategoryFactory
|
||||
$categoryId = (int) $categoryId;
|
||||
$categoryName = (string) $categoryName;
|
||||
|
||||
app('log')->debug(sprintf('Going to find category with ID %d and name "%s"', $categoryId, $categoryName));
|
||||
Log::debug(sprintf('Going to find category with ID %d and name "%s"', $categoryId, $categoryName));
|
||||
|
||||
if ('' === $categoryName && 0 === $categoryId) {
|
||||
return null;
|
||||
@@ -72,8 +72,8 @@ class CategoryFactory
|
||||
]
|
||||
);
|
||||
} catch (QueryException $e) {
|
||||
app('log')->error($e->getMessage());
|
||||
app('log')->error($e->getTraceAsString());
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
throw new FireflyException('400003: Could not store new category.', 0, $e);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use function Safe\json_encode;
|
||||
|
||||
/**
|
||||
* Class PiggyBankFactory
|
||||
*/
|
||||
@@ -92,7 +91,7 @@ class PiggyBankFactory
|
||||
/** @var PiggyBank $piggyBank */
|
||||
$piggyBank = PiggyBank::createQuietly($piggyBankData);
|
||||
} catch (QueryException $e) {
|
||||
app('log')->error(sprintf('Could not store piggy bank: %s', $e->getMessage()), $piggyBankData);
|
||||
Log::error(sprintf('Could not store piggy bank: %s', $e->getMessage()), $piggyBankData);
|
||||
|
||||
throw new FireflyException('400005: Could not store new piggy bank.', 0, $e);
|
||||
}
|
||||
@@ -211,7 +210,7 @@ class PiggyBankFactory
|
||||
$current = 1;
|
||||
foreach ($set as $piggyBank) {
|
||||
if ($piggyBank->order !== $current) {
|
||||
app('log')->debug(sprintf('Piggy bank #%d ("%s") was at place %d but should be on %d', $piggyBank->id, $piggyBank->name, $piggyBank->order, $current));
|
||||
Log::debug(sprintf('Piggy bank #%d ("%s") was at place %d but should be on %d', $piggyBank->id, $piggyBank->name, $piggyBank->order, $current));
|
||||
$piggyBank->order = $current;
|
||||
$piggyBank->save();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ use FireflyIII\Models\Location;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class TagFactory
|
||||
@@ -40,12 +41,12 @@ class TagFactory
|
||||
public function findOrCreate(string $tag): ?Tag
|
||||
{
|
||||
$tag = trim($tag);
|
||||
app('log')->debug(sprintf('Now in TagFactory::findOrCreate("%s")', $tag));
|
||||
Log::debug(sprintf('Now in TagFactory::findOrCreate("%s")', $tag));
|
||||
|
||||
/** @var null|Tag $dbTag */
|
||||
$dbTag = $this->user->tags()->where('tag', $tag)->first();
|
||||
if (null !== $dbTag) {
|
||||
app('log')->debug(sprintf('Tag exists (#%d), return it.', $dbTag->id));
|
||||
Log::debug(sprintf('Tag exists (#%d), return it.', $dbTag->id));
|
||||
|
||||
return $dbTag;
|
||||
}
|
||||
@@ -60,11 +61,11 @@ class TagFactory
|
||||
]
|
||||
);
|
||||
if (!$newTag instanceof Tag) {
|
||||
app('log')->error(sprintf('TagFactory::findOrCreate("%s") but tag is unexpectedly NULL!', $tag));
|
||||
Log::error(sprintf('TagFactory::findOrCreate("%s") but tag is unexpectedly NULL!', $tag));
|
||||
|
||||
return null;
|
||||
}
|
||||
app('log')->debug(sprintf('Created new tag #%d ("%s")', $newTag->id, $newTag->tag));
|
||||
Log::debug(sprintf('Created new tag #%d ("%s")', $newTag->id, $newTag->tag));
|
||||
|
||||
return $newTag;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ use FireflyIII\Rules\UniqueIban;
|
||||
use FireflyIII\Services\Internal\Update\AccountUpdateService;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class TransactionFactory
|
||||
@@ -96,9 +97,9 @@ class TransactionFactory
|
||||
/** @var null|Transaction $result */
|
||||
$result = Transaction::create($data);
|
||||
} catch (QueryException $e) {
|
||||
app('log')->error(sprintf('Could not create transaction: %s', $e->getMessage()), $data);
|
||||
app('log')->error($e->getMessage());
|
||||
app('log')->error($e->getTraceAsString());
|
||||
Log::error(sprintf('Could not create transaction: %s', $e->getMessage()), $data);
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
|
||||
throw new FireflyException(sprintf('Query exception when creating transaction: %s', $e->getMessage()), 0, $e);
|
||||
}
|
||||
@@ -106,7 +107,7 @@ class TransactionFactory
|
||||
throw new FireflyException('Transaction is NULL.');
|
||||
}
|
||||
|
||||
app('log')->debug(
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'Created transaction #%d (%s %s, account %s), part of journal #%d',
|
||||
$result->id,
|
||||
@@ -138,17 +139,17 @@ class TransactionFactory
|
||||
private function updateAccountInformation(): void
|
||||
{
|
||||
if (!array_key_exists('iban', $this->accountInformation)) {
|
||||
app('log')->debug('No IBAN information in array, will not update.');
|
||||
Log::debug('No IBAN information in array, will not update.');
|
||||
|
||||
return;
|
||||
}
|
||||
if ('' !== (string) $this->account->iban) {
|
||||
app('log')->debug('Account already has IBAN information, will not update.');
|
||||
Log::debug('Account already has IBAN information, will not update.');
|
||||
|
||||
return;
|
||||
}
|
||||
if ($this->account->iban === $this->accountInformation['iban']) {
|
||||
app('log')->debug('Account already has this IBAN, will not update.');
|
||||
Log::debug('Account already has this IBAN, will not update.');
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -157,12 +158,12 @@ class TransactionFactory
|
||||
'iban' => ['required', new UniqueIban($this->account, $this->account->accountType->type)],
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
app('log')->debug('Invalid or non-unique IBAN, will not update.');
|
||||
Log::debug('Invalid or non-unique IBAN, will not update.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
app('log')->debug('Will update account with IBAN information.');
|
||||
Log::debug('Will update account with IBAN information.');
|
||||
$service = app(AccountUpdateService::class);
|
||||
$service->update($this->account, ['iban' => $this->accountInformation['iban']]);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Class TransactionGroupFactory
|
||||
@@ -55,7 +56,7 @@ class TransactionGroupFactory
|
||||
*/
|
||||
public function create(array $data): TransactionGroup
|
||||
{
|
||||
app('log')->debug('Now in TransactionGroupFactory::create()');
|
||||
Log::debug('Now in TransactionGroupFactory::create()');
|
||||
$this->journalFactory->setUser($data['user']);
|
||||
$this->journalFactory->setUserGroup($data['user_group']);
|
||||
$this->journalFactory->setErrorOnHash($data['error_if_duplicate_hash'] ?? false);
|
||||
@@ -63,7 +64,7 @@ class TransactionGroupFactory
|
||||
try {
|
||||
$collection = $this->journalFactory->create($data);
|
||||
} catch (DuplicateTransactionException $e) {
|
||||
app('log')->warning('GroupFactory::create() caught journalFactory::create() with a duplicate!');
|
||||
Log::warning('GroupFactory::create() caught journalFactory::create() with a duplicate!');
|
||||
|
||||
throw new DuplicateTransactionException($e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
@@ -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