Remove static references

This commit is contained in:
James Cole
2023-10-29 06:33:43 +01:00
parent 075d459b7c
commit 4f2159b54d
205 changed files with 1287 additions and 1287 deletions

View File

@@ -74,14 +74,14 @@ class AddTag implements ActionInterface
if (0 === $count) {
// add to journal:
DB::table('tag_transaction_journal')->insert(['tag_id' => $tag->id, 'transaction_journal_id' => $journal['transaction_journal_id']]);
Log::debug(sprintf('RuleAction AddTag. Added tag #%d ("%s") to journal %d.', $tag->id, $tag->tag, $journal['transaction_journal_id']));
app('log')->debug(sprintf('RuleAction AddTag. Added tag #%d ("%s") to journal %d.', $tag->id, $tag->tag, $journal['transaction_journal_id']));
$object = TransactionJournal::find($journal['transaction_journal_id']);
// event for audit log entry
event(new TriggeredAuditLog($this->action->rule, $object, 'add_tag', null, $tag->tag));
return true;
}
Log::debug(
app('log')->debug(
sprintf('RuleAction AddTag fired but tag %d ("%s") was already added to journal %d.', $tag->id, $tag->tag, $journal['transaction_journal_id'])
);
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.tag_already_added', ['tag' => $this->action->action_value])));

View File

@@ -60,7 +60,7 @@ class AppendNotes implements ActionInterface
$dbNote->noteable_type = TransactionJournal::class;
$dbNote->text = '';
}
Log::debug(sprintf('RuleAction AppendNotes appended "%s" to "%s".', $this->action->action_value, $dbNote->text));
app('log')->debug(sprintf('RuleAction AppendNotes appended "%s" to "%s".', $this->action->action_value, $dbNote->text));
$before = $dbNote->text;
$text = sprintf('%s%s', $dbNote->text, $this->action->action_value);
$dbNote->text = $text;

View File

@@ -56,7 +56,7 @@ class AppendNotesToDescription implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
Log::debug('Now in AppendNotesToDescription');
app('log')->debug('Now in AppendNotesToDescription');
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
if (null === $object) {
@@ -66,7 +66,7 @@ class AppendNotesToDescription implements ActionInterface
}
$note = $object->notes()->first();
if (null === $note) {
Log::debug('Journal has no notes.');
app('log')->debug('Journal has no notes.');
$note = new Note();
$note->noteable()->associate($object);
$note->text = '';
@@ -76,7 +76,7 @@ class AppendNotesToDescription implements ActionInterface
$before = $object->description;
$object->description = trim(sprintf('%s %s', $object->description, (string)$this->clearString($note->text, false)));
$object->save();
Log::debug(sprintf('Journal description is updated to "%s".', $object->description));
app('log')->debug(sprintf('Journal description is updated to "%s".', $object->description));
event(new TriggeredAuditLog($this->action->rule, $object, 'update_description', $before, $object->description));

View File

@@ -56,7 +56,7 @@ class ClearBudget implements ActionInterface
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$budget = $object->budgets()->first();
if (null === $budget) {
Log::debug(sprintf('RuleAction ClearBudget, no budget in journal #%d.', $journal['transaction_journal_id']));
app('log')->debug(sprintf('RuleAction ClearBudget, no budget in journal #%d.', $journal['transaction_journal_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_already_no_budget')));
return false;
}
@@ -65,7 +65,7 @@ class ClearBudget implements ActionInterface
event(new TriggeredAuditLog($this->action->rule, $object, 'clear_budget', $budget->name, null));
Log::debug(sprintf('RuleAction ClearBudget removed all budgets from journal #%d.', $journal['transaction_journal_id']));
app('log')->debug(sprintf('RuleAction ClearBudget removed all budgets from journal #%d.', $journal['transaction_journal_id']));
return true;
}

View File

@@ -56,7 +56,7 @@ class ClearCategory implements ActionInterface
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$category = $object->categories()->first();
if (null === $category) {
Log::debug(sprintf('RuleAction ClearCategory, no category in journal #%d.', $journal['transaction_journal_id']));
app('log')->debug(sprintf('RuleAction ClearCategory, no category in journal #%d.', $journal['transaction_journal_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_already_no_category')));
return false;
}
@@ -65,7 +65,7 @@ class ClearCategory implements ActionInterface
event(new TriggeredAuditLog($this->action->rule, $object, 'clear_category', $category->name, null));
Log::debug(sprintf('RuleAction ClearCategory removed all categories from journal #%d.', $journal['transaction_journal_id']));
app('log')->debug(sprintf('RuleAction ClearCategory removed all categories from journal #%d.', $journal['transaction_journal_id']));
return true;
}

View File

@@ -55,7 +55,7 @@ class ClearNotes implements ActionInterface
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
$notes = $object->notes()->first();
if (null === $notes) {
Log::debug(sprintf('RuleAction ClearNotes, journal #%d has no notes.', $journal['transaction_journal_id']));
app('log')->debug(sprintf('RuleAction ClearNotes, journal #%d has no notes.', $journal['transaction_journal_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_already_no_notes')));
return false;
}
@@ -65,7 +65,7 @@ class ClearNotes implements ActionInterface
->where('noteable_id', $journal['transaction_journal_id'])
->where('noteable_type', TransactionJournal::class)
->delete();
Log::debug(sprintf('RuleAction ClearNotes removed all notes from journal #%d.', $journal['transaction_journal_id']));
app('log')->debug(sprintf('RuleAction ClearNotes removed all notes from journal #%d.', $journal['transaction_journal_id']));
event(new TriggeredAuditLog($this->action->rule, $object, 'clear_notes', $before, null));

View File

@@ -76,7 +76,7 @@ class ConvertToDeposit implements ActionInterface
return false;
}
Log::debug(sprintf('Convert journal #%d to deposit.', $journal['transaction_journal_id']));
app('log')->debug(sprintf('Convert journal #%d to deposit.', $journal['transaction_journal_id']));
$type = $object->transactionType->type;
if (TransactionType::DEPOSIT === $type) {
app('log')->error(sprintf('Journal #%d is already a deposit (rule #%d).', $journal['transaction_journal_id'], $this->action->rule_id));
@@ -85,12 +85,12 @@ class ConvertToDeposit implements ActionInterface
}
if (TransactionType::WITHDRAWAL === $type) {
Log::debug('Going to transform a withdrawal to a deposit.');
app('log')->debug('Going to transform a withdrawal to a deposit.');
try {
$res = $this->convertWithdrawalArray($object);
} catch (JsonException | FireflyException $e) {
Log::debug('Could not convert withdrawal to deposit.');
app('log')->debug('Could not convert withdrawal to deposit.');
app('log')->error($e->getMessage());
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
return false;
@@ -101,12 +101,12 @@ class ConvertToDeposit implements ActionInterface
return $res;
}
if (TransactionType::TRANSFER === $type) {
Log::debug('Going to transform a transfer to a deposit.');
app('log')->debug('Going to transform a transfer to a deposit.');
try {
$res = $this->convertTransferArray($object);
} catch (JsonException | FireflyException $e) {
Log::debug('Could not convert transfer to deposit.');
app('log')->debug('Could not convert transfer to deposit.');
app('log')->error($e->getMessage());
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
return false;
@@ -153,7 +153,7 @@ class ConvertToDeposit implements ActionInterface
$opposingAccount = $factory->findOrCreate($opposingName, AccountType::REVENUE);
}
Log::debug(sprintf('ConvertToDeposit. Action value is "%s", new opposing name is "%s"', $this->action->action_value, $opposingAccount->name));
app('log')->debug(sprintf('ConvertToDeposit. Action value is "%s", new opposing name is "%s"', $this->action->action_value, $opposingAccount->name));
// update the source transaction and put in the new revenue ID.
DB::table('transactions')
@@ -174,7 +174,7 @@ class ConvertToDeposit implements ActionInterface
->where('id', '=', $journal->id)
->update(['transaction_type_id' => $newType->id, 'bill_id' => null]);
Log::debug('Converted withdrawal to deposit.');
app('log')->debug('Converted withdrawal to deposit.');
return true;
}
@@ -245,7 +245,7 @@ class ConvertToDeposit implements ActionInterface
$opposingAccount = $factory->findOrCreate($opposingName, AccountType::REVENUE);
}
Log::debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $this->action->action_value, $opposingAccount->name));
app('log')->debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $this->action->action_value, $opposingAccount->name));
// update source transaction(s) to be revenue account
DB::table('transactions')
@@ -260,7 +260,7 @@ class ConvertToDeposit implements ActionInterface
->where('id', '=', $journal->id)
->update(['transaction_type_id' => $newType->id, 'bill_id' => null]);
Log::debug('Converted transfer to deposit.');
app('log')->debug('Converted transfer to deposit.');
return true;
}

View File

@@ -121,11 +121,11 @@ class ConvertToTransfer implements ActionInterface
}
if (TransactionType::WITHDRAWAL === $type) {
Log::debug('Going to transform a withdrawal to a transfer.');
app('log')->debug('Going to transform a withdrawal to a transfer.');
try {
$res = $this->convertWithdrawalArray($object, $opposing);
} catch (FireflyException $e) {
Log::debug('Could not convert withdrawal to transfer.');
app('log')->debug('Could not convert withdrawal to transfer.');
app('log')->error($e->getMessage());
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
return false;
@@ -136,11 +136,11 @@ class ConvertToTransfer implements ActionInterface
return $res;
}
if (TransactionType::DEPOSIT === $type) {
Log::debug('Going to transform a deposit to a transfer.');
app('log')->debug('Going to transform a deposit to a transfer.');
try {
$res = $this->convertDepositArray($object, $opposing);
} catch (FireflyException $e) {
Log::debug('Could not convert deposit to transfer.');
app('log')->debug('Could not convert deposit to transfer.');
app('log')->error($e->getMessage());
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
return false;
@@ -225,7 +225,7 @@ class ConvertToTransfer implements ActionInterface
->where('id', '=', $journal->id)
->update(['transaction_type_id' => $newType->id, 'bill_id' => null]);
Log::debug('Converted withdrawal to transfer.');
app('log')->debug('Converted withdrawal to transfer.');
return true;
}
@@ -284,7 +284,7 @@ class ConvertToTransfer implements ActionInterface
->where('id', '=', $journal->id)
->update(['transaction_type_id' => $newType->id, 'bill_id' => null]);
Log::debug('Converted deposit to transfer.');
app('log')->debug('Converted deposit to transfer.');
return true;
}

View File

@@ -87,11 +87,11 @@ class ConvertToWithdrawal implements ActionInterface
return false;
}
if (TransactionType::DEPOSIT === $type) {
Log::debug('Going to transform a deposit to a withdrawal.');
app('log')->debug('Going to transform a deposit to a withdrawal.');
try {
$res = $this->convertDepositArray($object);
} catch (JsonException | FireflyException $e) {
Log::debug('Could not convert transfer to deposit.');
app('log')->debug('Could not convert transfer to deposit.');
app('log')->error($e->getMessage());
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
return false;
@@ -101,12 +101,12 @@ class ConvertToWithdrawal implements ActionInterface
return $res;
}
if (TransactionType::TRANSFER === $type) {
Log::debug('Going to transform a transfer to a withdrawal.');
app('log')->debug('Going to transform a transfer to a withdrawal.');
try {
$res = $this->convertTransferArray($object);
} catch (JsonException | FireflyException $e) {
Log::debug('Could not convert transfer to deposit.');
app('log')->debug('Could not convert transfer to deposit.');
app('log')->error($e->getMessage());
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
return false;
@@ -149,7 +149,7 @@ class ConvertToWithdrawal implements ActionInterface
$opposingAccount = $factory->findOrCreate($opposingName, AccountType::EXPENSE);
}
Log::debug(sprintf('ConvertToWithdrawal. Action value is "%s", expense name is "%s"', $this->action->action_value, $opposingName));
app('log')->debug(sprintf('ConvertToWithdrawal. Action value is "%s", expense name is "%s"', $this->action->action_value, $opposingName));
// update source transaction(s) to be the original destination account
DB::table('transactions')
@@ -169,7 +169,7 @@ class ConvertToWithdrawal implements ActionInterface
->where('id', '=', $journal->id)
->update(['transaction_type_id' => $newType->id]);
Log::debug('Converted deposit to withdrawal.');
app('log')->debug('Converted deposit to withdrawal.');
return true;
}
@@ -239,7 +239,7 @@ class ConvertToWithdrawal implements ActionInterface
$opposingAccount = $factory->findOrCreate($opposingName, AccountType::EXPENSE);
}
Log::debug(sprintf('ConvertToWithdrawal. Action value is "%s", destination name is "%s"', $this->action->action_value, $opposingName));
app('log')->debug(sprintf('ConvertToWithdrawal. Action value is "%s", destination name is "%s"', $this->action->action_value, $opposingName));
// update destination transaction(s) to be new expense account.
DB::table('transactions')
@@ -253,7 +253,7 @@ class ConvertToWithdrawal implements ActionInterface
->where('id', '=', $journal->id)
->update(['transaction_type_id' => $newType->id]);
Log::debug('Converted transfer to withdrawal.');
app('log')->debug('Converted transfer to withdrawal.');
return true;
}

View File

@@ -57,7 +57,7 @@ class DeleteTransaction implements ActionInterface
// destroy entire group.
if (1 === $count) {
Log::debug(
app('log')->debug(
sprintf(
'RuleAction DeleteTransaction DELETED the entire transaction group of journal #%d ("%s").',
$journal['transaction_journal_id'],
@@ -72,7 +72,7 @@ class DeleteTransaction implements ActionInterface
return true;
}
Log::debug(
app('log')->debug(
sprintf('RuleAction DeleteTransaction DELETED transaction journal #%d ("%s").', $journal['transaction_journal_id'], $journal['description'])
);

View File

@@ -82,7 +82,7 @@ class LinkToBill implements ActionInterface
DB::table('transaction_journals')
->where('id', '=', $journal['transaction_journal_id'])
->update(['bill_id' => $bill->id]);
Log::debug(
app('log')->debug(
sprintf('RuleAction LinkToBill set the bill of journal #%d to bill #%d ("%s").', $journal['transaction_journal_id'], $bill->id, $bill->name)
);

View File

@@ -61,7 +61,7 @@ class PrependNotes implements ActionInterface
$dbNote->text = '';
}
$before = $dbNote->text;
Log::debug(sprintf('RuleAction PrependNotes prepended "%s" to "%s".', $this->action->action_value, $dbNote->text));
app('log')->debug(sprintf('RuleAction PrependNotes prepended "%s" to "%s".', $this->action->action_value, $dbNote->text));
$text = sprintf('%s%s', $this->action->action_value, $dbNote->text);
$dbNote->text = $text;
$dbNote->save();

View File

@@ -55,11 +55,11 @@ class RemoveAllTags implements ActionInterface
DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal['transaction_journal_id'])->delete();
$count = DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal['transaction_journal_id'])->count();
if (0 === $count) {
Log::debug(sprintf('RuleAction RemoveAllTags, journal #%d has no tags.', $journal['transaction_journal_id']));
app('log')->debug(sprintf('RuleAction RemoveAllTags, journal #%d has no tags.', $journal['transaction_journal_id']));
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_tags_to_remove')));
return false;
}
Log::debug(sprintf('RuleAction RemoveAllTags removed all tags from journal %d.', $journal['transaction_journal_id']));
app('log')->debug(sprintf('RuleAction RemoveAllTags removed all tags from journal %d.', $journal['transaction_journal_id']));
/** @var TransactionJournal $object */
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);

View File

@@ -59,7 +59,7 @@ class RemoveTag implements ActionInterface
$tag = $user->tags()->where('tag', $name)->first();
if (null === $tag) {
Log::debug(
app('log')->debug(
sprintf('RuleAction RemoveTag tried to remove tag "%s" from journal #%d but no such tag exists.', $name, $journal['transaction_journal_id'])
);
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_tag', ['tag' => $name])));
@@ -67,14 +67,14 @@ class RemoveTag implements ActionInterface
}
$count = DB::table('tag_transaction_journal')->where('transaction_journal_id', $journal['transaction_journal_id'])->where('tag_id', $tag->id)->count();
if (0 === $count) {
Log::debug(
app('log')->debug(
sprintf('RuleAction RemoveTag tried to remove tag "%s" from journal #%d but no such tag is linked.', $name, $journal['transaction_journal_id'])
);
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_unlink_tag', ['tag' => $name])));
return false;
}
Log::debug(sprintf('RuleAction RemoveTag removed tag #%d ("%s") from journal #%d.', $tag->id, $tag->tag, $journal['transaction_journal_id']));
app('log')->debug(sprintf('RuleAction RemoveTag removed tag #%d ("%s") from journal #%d.', $tag->id, $tag->tag, $journal['transaction_journal_id']));
DB::table('tag_transaction_journal')
->where('transaction_journal_id', $journal['transaction_journal_id'])
->where('tag_id', $tag->id)

View File

@@ -59,7 +59,7 @@ class SetBudget implements ActionInterface
$budget = $user->budgets()->where('name', $search)->first();
if (null === $budget) {
Log::debug(
app('log')->debug(
sprintf(
'RuleAction SetBudget could not set budget of journal #%d to "%s" because no such budget exists.',
$journal['transaction_journal_id'],
@@ -71,7 +71,7 @@ class SetBudget implements ActionInterface
}
if (TransactionType::WITHDRAWAL !== $journal['transaction_type_type']) {
Log::debug(
app('log')->debug(
sprintf(
'RuleAction SetBudget could not set budget of journal #%d to "%s" because journal is a %s.',
$journal['transaction_journal_id'],
@@ -94,7 +94,7 @@ class SetBudget implements ActionInterface
}
Log::debug(
app('log')->debug(
sprintf('RuleAction SetBudget set the budget of journal #%d to budget #%d ("%s").', $journal['transaction_journal_id'], $budget->id, $budget->name)
);

View File

@@ -67,7 +67,7 @@ class SetCategory implements ActionInterface
$factory->setUser($user);
$category = $factory->findOrCreate(null, $search);
if (null === $category) {
Log::debug(
app('log')->debug(
sprintf(
'RuleAction SetCategory could not set category of journal #%d to "%s" because no such category exists.',
$journal['transaction_journal_id'],
@@ -78,7 +78,7 @@ class SetCategory implements ActionInterface
return false;
}
Log::debug(
app('log')->debug(
sprintf(
'RuleAction SetCategory set the category of journal #%d to category #%d ("%s").',
$journal['transaction_journal_id'],

View File

@@ -59,7 +59,7 @@ class SetDescription implements ActionInterface
->where('id', '=', $journal['transaction_journal_id'])
->update(['description' => $this->action->action_value]);
Log::debug(
app('log')->debug(
sprintf(
'RuleAction SetDescription changed the description of journal #%d from "%s" to "%s".',
$journal['transaction_journal_id'],

View File

@@ -119,7 +119,7 @@ class SetDestinationAccount implements ActionInterface
$newAccount = $this->findWithdrawalDestinationAccount();
}
Log::debug(sprintf('New destination account is #%d ("%s").', $newAccount->id, $newAccount->name));
app('log')->debug(sprintf('New destination account is #%d ("%s").', $newAccount->id, $newAccount->name));
event(new TriggeredAuditLog($this->action->rule, $object, 'set_destination', null, $newAccount->name));
@@ -129,7 +129,7 @@ class SetDestinationAccount implements ActionInterface
->where('amount', '>', 0)
->update(['account_id' => $newAccount->id]);
Log::debug(sprintf('Updated journal #%d (group #%d) and gave it new destination account ID.', $object->id, $object->transaction_group_id));
app('log')->debug(sprintf('Updated journal #%d (group #%d) and gave it new destination account ID.', $object->id, $object->transaction_group_id));
return true;
}
@@ -144,7 +144,7 @@ class SetDestinationAccount implements ActionInterface
// switch on type:
$allowed = config(sprintf('firefly.expected_source_types.destination.%s', $type));
$allowed = is_array($allowed) ? $allowed : [];
Log::debug(sprintf('Check config for expected_source_types.destination.%s, result is', $type), $allowed);
app('log')->debug(sprintf('Check config for expected_source_types.destination.%s, result is', $type), $allowed);
return $this->repository->findByName($this->action->action_value, $allowed);
}
@@ -167,7 +167,7 @@ class SetDestinationAccount implements ActionInterface
];
$account = $this->repository->store($data);
}
Log::debug(sprintf('Found or created expense account #%d ("%s")', $account->id, $account->name));
app('log')->debug(sprintf('Found or created expense account #%d ("%s")', $account->id, $account->name));
return $account;
}

View File

@@ -63,7 +63,7 @@ class SetNotes implements ActionInterface
$dbNote->text = $this->action->action_value;
$dbNote->save();
Log::debug(
app('log')->debug(
sprintf(
'RuleAction SetNotes changed the notes of journal #%d from "%s" to "%s".',
$journal['transaction_journal_id'],

View File

@@ -113,7 +113,7 @@ class SetSourceAccount implements ActionInterface
$newAccount = $this->findDepositSourceAccount();
}
Log::debug(sprintf('New source account is #%d ("%s").', $newAccount->id, $newAccount->name));
app('log')->debug(sprintf('New source account is #%d ("%s").', $newAccount->id, $newAccount->name));
// update source transaction with new source account:
DB::table('transactions')
@@ -123,7 +123,7 @@ class SetSourceAccount implements ActionInterface
event(new TriggeredAuditLog($this->action->rule, $object, 'set_source', null, $newAccount->name));
Log::debug(sprintf('Updated journal #%d (group #%d) and gave it new source account ID.', $object->id, $object->transaction_group_id));
app('log')->debug(sprintf('Updated journal #%d (group #%d) and gave it new source account ID.', $object->id, $object->transaction_group_id));
return true;
}
@@ -138,7 +138,7 @@ class SetSourceAccount implements ActionInterface
// switch on type:
$allowed = config(sprintf('firefly.expected_source_types.source.%s', $type));
$allowed = is_array($allowed) ? $allowed : [];
Log::debug(sprintf('Check config for expected_source_types.source.%s, result is', $type), $allowed);
app('log')->debug(sprintf('Check config for expected_source_types.source.%s, result is', $type), $allowed);
return $this->repository->findByName($this->action->action_value, $allowed);
}
@@ -162,7 +162,7 @@ class SetSourceAccount implements ActionInterface
];
$account = $this->repository->store($data);
}
Log::debug(sprintf('Found or created revenue account #%d ("%s")', $account->id, $account->name));
app('log')->debug(sprintf('Found or created revenue account #%d ("%s")', $account->id, $account->name));
return $account;
}

View File

@@ -57,7 +57,7 @@ class UpdatePiggybank implements ActionInterface
*/
public function actOnArray(array $journal): bool
{
Log::debug(sprintf('Triggered rule action UpdatePiggybank on journal #%d', $journal['transaction_journal_id']));
app('log')->debug(sprintf('Triggered rule action UpdatePiggybank on journal #%d', $journal['transaction_journal_id']));
// refresh the transaction type.
$user = User::find($journal['user_id']);
@@ -74,7 +74,7 @@ class UpdatePiggybank implements ActionInterface
return false;
}
Log::debug(sprintf('Found piggy bank #%d ("%s")', $piggyBank->id, $piggyBank->name));
app('log')->debug(sprintf('Found piggy bank #%d ("%s")', $piggyBank->id, $piggyBank->name));
/** @var Transaction $source */
$source = $journalObj->transactions()->where('amount', '<', 0)->first();
@@ -82,7 +82,7 @@ class UpdatePiggybank implements ActionInterface
$destination = $journalObj->transactions()->where('amount', '>', 0)->first();
if ((int)$source->account_id === (int)$piggyBank->account_id) {
Log::debug('Piggy bank account is linked to source, so remove amount from piggy bank.');
app('log')->debug('Piggy bank account is linked to source, so remove amount from piggy bank.');
$this->removeAmount($piggyBank, $journalObj, $destination->amount);
event(
@@ -103,7 +103,7 @@ class UpdatePiggybank implements ActionInterface
return true;
}
if ((int)$destination->account_id === (int)$piggyBank->account_id) {
Log::debug('Piggy bank account is linked to source, so add amount to piggy bank.');
app('log')->debug('Piggy bank account is linked to source, so add amount to piggy bank.');
$this->addAmount($piggyBank, $journalObj, $destination->amount);
event(
@@ -158,11 +158,11 @@ class UpdatePiggybank implements ActionInterface
// how much can we remove from this piggy bank?
$toRemove = $repository->getCurrentAmount($piggyBank);
Log::debug(sprintf('Amount is %s, max to remove is %s', $amount, $toRemove));
app('log')->debug(sprintf('Amount is %s, max to remove is %s', $amount, $toRemove));
// if $amount is bigger than $toRemove, shrink it.
$amount = -1 === bccomp($amount, $toRemove) ? $amount : $toRemove;
Log::debug(sprintf('Amount is now %s', $amount));
app('log')->debug(sprintf('Amount is now %s', $amount));
// if amount is zero, stop.
if (0 === bccomp('0', $amount)) {
@@ -177,7 +177,7 @@ class UpdatePiggybank implements ActionInterface
return;
}
Log::debug(sprintf('Will now remove %s from piggy bank.', $amount));
app('log')->debug(sprintf('Will now remove %s from piggy bank.', $amount));
$repository->removeAmount($piggyBank, $amount, $journal);
}
@@ -197,14 +197,14 @@ class UpdatePiggybank implements ActionInterface
// how much can we add to the piggy bank?
if (0 !== bccomp($piggyBank->targetamount, '0')) {
$toAdd = bcsub($piggyBank->targetamount, $repository->getCurrentAmount($piggyBank));
Log::debug(sprintf('Max amount to add to piggy bank is %s, amount is %s', $toAdd, $amount));
app('log')->debug(sprintf('Max amount to add to piggy bank is %s, amount is %s', $toAdd, $amount));
// update amount to fit:
$amount = -1 === bccomp($amount, $toAdd) ? $amount : $toAdd;
Log::debug(sprintf('Amount is now %s', $amount));
app('log')->debug(sprintf('Amount is now %s', $amount));
}
if (0 === bccomp($piggyBank->targetamount, '0')) {
Log::debug('Target amount is zero, can add anything.');
app('log')->debug('Target amount is zero, can add anything.');
}
@@ -221,7 +221,7 @@ class UpdatePiggybank implements ActionInterface
return;
}
Log::debug(sprintf('Will now add %s to piggy bank.', $amount));
app('log')->debug(sprintf('Will now add %s to piggy bank.', $amount));
$repository->addAmount($piggyBank, $amount, $journal);
}

View File

@@ -65,7 +65,7 @@ class SearchRuleEngine implements RuleEngineInterface
*/
public function addOperator(array $operator): void
{
Log::debug('Add extra operator: ', $operator);
app('log')->debug('Add extra operator: ', $operator);
$this->operators[] = $operator;
}
@@ -74,7 +74,7 @@ class SearchRuleEngine implements RuleEngineInterface
*/
public function find(): Collection
{
Log::debug('SearchRuleEngine::find()');
app('log')->debug('SearchRuleEngine::find()');
$collection = new Collection();
foreach ($this->rules as $rule) {
$found = new Collection();
@@ -99,7 +99,7 @@ class SearchRuleEngine implements RuleEngineInterface
*/
private function findStrictRule(Rule $rule): Collection
{
Log::debug(sprintf('Now in findStrictRule(#%d)', $rule->id ?? 0));
app('log')->debug(sprintf('Now in findStrictRule(#%d)', $rule->id ?? 0));
$searchArray = [];
$triggers = [];
if ($this->refreshTriggers) {
@@ -118,11 +118,11 @@ class SearchRuleEngine implements RuleEngineInterface
// if needs no context, value is different:
$needsContext = config(sprintf('search.operators.%s.needs_context', $ruleTrigger->trigger_type)) ?? true;
if (false === $needsContext) {
Log::debug(sprintf('SearchRuleEngine:: add a rule trigger: %s:true', $ruleTrigger->trigger_type));
app('log')->debug(sprintf('SearchRuleEngine:: add a rule trigger: %s:true', $ruleTrigger->trigger_type));
$searchArray[$ruleTrigger->trigger_type][] = 'true';
}
if (true === $needsContext) {
Log::debug(sprintf('SearchRuleEngine:: add a rule trigger: %s:"%s"', $ruleTrigger->trigger_type, $ruleTrigger->trigger_value));
app('log')->debug(sprintf('SearchRuleEngine:: add a rule trigger: %s:"%s"', $ruleTrigger->trigger_type, $ruleTrigger->trigger_value));
$searchArray[$ruleTrigger->trigger_type][] = sprintf('"%s"', $ruleTrigger->trigger_value);
}
}
@@ -130,7 +130,7 @@ class SearchRuleEngine implements RuleEngineInterface
// add local operators:
foreach ($this->operators as $operator) {
Log::debug(sprintf('SearchRuleEngine:: add local added operator: %s:"%s"', $operator['type'], $operator['value']));
app('log')->debug(sprintf('SearchRuleEngine:: add local added operator: %s:"%s"', $operator['type'], $operator['value']));
$searchArray[$operator['type']][] = sprintf('"%s"', $operator['value']);
}
$date = today(config('app.timezone'));
@@ -166,21 +166,21 @@ class SearchRuleEngine implements RuleEngineInterface
*/
private function hasSpecificJournalTrigger(array $array): bool
{
Log::debug('Now in hasSpecificJournalTrigger.');
app('log')->debug('Now in hasSpecificJournalTrigger.');
$journalTrigger = false;
$dateTrigger = false;
foreach ($array as $triggerName => $values) {
if ('journal_id' === $triggerName && is_array($values) && 1 === count($values)) {
Log::debug('Found a journal_id trigger with 1 journal, true.');
app('log')->debug('Found a journal_id trigger with 1 journal, true.');
$journalTrigger = true;
}
if (in_array($triggerName, ['date_is', 'date', 'on', 'date_before', 'before', 'date_after', 'after'], true)) {
Log::debug('Found a date related trigger, set to true.');
app('log')->debug('Found a date related trigger, set to true.');
$dateTrigger = true;
}
}
$result = $journalTrigger && $dateTrigger;
Log::debug(sprintf('Result of hasSpecificJournalTrigger is %s.', var_export($result, true)));
app('log')->debug(sprintf('Result of hasSpecificJournalTrigger is %s.', var_export($result, true)));
return $result;
}
@@ -192,12 +192,12 @@ class SearchRuleEngine implements RuleEngineInterface
*/
private function setDateFromJournalTrigger(array $array): Carbon
{
Log::debug('Now in setDateFromJournalTrigger()');
app('log')->debug('Now in setDateFromJournalTrigger()');
$journalId = 0;
foreach ($array as $triggerName => $values) {
if ('journal_id' === $triggerName && is_array($values) && 1 === count($values)) {
$journalId = (int)trim(($values[0] ?? '"0"'), '"'); // follows format "123".
Log::debug(sprintf('Found journal ID #%d', $journalId));
app('log')->debug(sprintf('Found journal ID #%d', $journalId));
}
}
if (0 !== $journalId) {
@@ -206,12 +206,12 @@ class SearchRuleEngine implements RuleEngineInterface
$journal = $repository->find($journalId);
if (null !== $journal) {
$date = $journal->date;
Log::debug(sprintf('Found journal #%d with date %s.', $journal->id, $journal->date->format('Y-m-d')));
app('log')->debug(sprintf('Found journal #%d with date %s.', $journal->id, $journal->date->format('Y-m-d')));
return $date;
}
}
Log::debug('Found no journal, return default date.');
app('log')->debug('Found no journal, return default date.');
return today(config('app.timezone'));
}
@@ -249,23 +249,23 @@ class SearchRuleEngine implements RuleEngineInterface
continue;
}
if ('user_action' === $ruleTrigger->trigger_type) {
Log::debug('Skip trigger type.');
app('log')->debug('Skip trigger type.');
continue;
}
$searchArray = [];
$needsContext = config(sprintf('search.operators.%s.needs_context', $ruleTrigger->trigger_type)) ?? true;
if (false === $needsContext) {
Log::debug(sprintf('SearchRuleEngine:: non strict, will search for: %s:true', $ruleTrigger->trigger_type));
app('log')->debug(sprintf('SearchRuleEngine:: non strict, will search for: %s:true', $ruleTrigger->trigger_type));
$searchArray[$ruleTrigger->trigger_type] = 'true';
}
if (true === $needsContext) {
Log::debug(sprintf('SearchRuleEngine:: non strict, will search for: %s:"%s"', $ruleTrigger->trigger_type, $ruleTrigger->trigger_value));
app('log')->debug(sprintf('SearchRuleEngine:: non strict, will search for: %s:"%s"', $ruleTrigger->trigger_type, $ruleTrigger->trigger_value));
$searchArray[$ruleTrigger->trigger_type] = sprintf('"%s"', $ruleTrigger->trigger_value);
}
// then, add local operators as well:
foreach ($this->operators as $operator) {
Log::debug(sprintf('SearchRuleEngine:: add local added operator: %s:"%s"', $operator['type'], $operator['value']));
app('log')->debug(sprintf('SearchRuleEngine:: add local added operator: %s:"%s"', $operator['type'], $operator['value']));
$searchArray[$operator['type']] = sprintf('"%s"', $operator['value']);
}
@@ -281,13 +281,13 @@ class SearchRuleEngine implements RuleEngineInterface
$result = $searchEngine->searchTransactions();
$collection = $result->getCollection();
Log::debug(sprintf('Found in this run, %d transactions', $collection->count()));
app('log')->debug(sprintf('Found in this run, %d transactions', $collection->count()));
$total = $total->merge($collection);
Log::debug(sprintf('Total collection is now %d transactions', $total->count()));
app('log')->debug(sprintf('Total collection is now %d transactions', $total->count()));
$count++;
}
Log::debug(sprintf('Total collection is now %d transactions', $total->count()));
Log::debug(sprintf('Done running %d trigger(s)', $count));
app('log')->debug(sprintf('Total collection is now %d transactions', $total->count()));
app('log')->debug(sprintf('Done running %d trigger(s)', $count));
// make collection unique
$unique = $total->unique(
@@ -297,13 +297,13 @@ class SearchRuleEngine implements RuleEngineInterface
$str = sprintf('%s%d', $str, $transaction['transaction_journal_id']);
}
$key = sprintf('%d%s', $group['id'], $str);
//Log::debug(sprintf('Return key: %s ', $key));
//app('log')->debug(sprintf('Return key: %s ', $key));
return $key;
}
);
Log::debug(sprintf('SearchRuleEngine:: Found %d transactions using search engine.', $unique->count()));
app('log')->debug(sprintf('SearchRuleEngine:: Found %d transactions using search engine.', $unique->count()));
return $unique;
}
@@ -315,27 +315,27 @@ class SearchRuleEngine implements RuleEngineInterface
public function fire(): void
{
$this->resultCount = [];
Log::debug('SearchRuleEngine::fire()!');
app('log')->debug('SearchRuleEngine::fire()!');
// if rules and no rule groups, file each rule separately.
if (0 !== $this->rules->count()) {
Log::debug(sprintf('SearchRuleEngine:: found %d rule(s) to fire.', $this->rules->count()));
app('log')->debug(sprintf('SearchRuleEngine:: found %d rule(s) to fire.', $this->rules->count()));
foreach ($this->rules as $rule) {
$this->fireRule($rule);
}
Log::debug('SearchRuleEngine:: done processing all rules!');
app('log')->debug('SearchRuleEngine:: done processing all rules!');
return;
}
if (0 !== $this->groups->count()) {
Log::debug(sprintf('SearchRuleEngine:: found %d rule group(s) to fire.', $this->groups->count()));
app('log')->debug(sprintf('SearchRuleEngine:: found %d rule group(s) to fire.', $this->groups->count()));
// fire each group:
/** @var RuleGroup $group */
foreach ($this->groups as $group) {
$this->fireGroup($group);
}
}
Log::debug('SearchRuleEngine:: done processing all rules!');
app('log')->debug('SearchRuleEngine:: done processing all rules!');
}
/**
@@ -348,18 +348,18 @@ class SearchRuleEngine implements RuleEngineInterface
*/
private function fireRule(Rule $rule): bool
{
Log::debug(sprintf('Now going to fire rule #%d', $rule->id));
app('log')->debug(sprintf('Now going to fire rule #%d', $rule->id));
if (false === $rule->active) {
Log::debug(sprintf('Rule #%d is not active!', $rule->id));
app('log')->debug(sprintf('Rule #%d is not active!', $rule->id));
return false;
}
if (true === $rule->strict) {
Log::debug(sprintf('Rule #%d is a strict rule.', $rule->id));
app('log')->debug(sprintf('Rule #%d is a strict rule.', $rule->id));
return $this->fireStrictRule($rule);
}
Log::debug(sprintf('Rule #%d is not strict rule.', $rule->id));
app('log')->debug(sprintf('Rule #%d is not strict rule.', $rule->id));
return $this->fireNonStrictRule($rule);
}
@@ -374,19 +374,19 @@ class SearchRuleEngine implements RuleEngineInterface
*/
private function fireStrictRule(Rule $rule): bool
{
Log::debug(sprintf('SearchRuleEngine::fireStrictRule(%d)!', $rule->id));
app('log')->debug(sprintf('SearchRuleEngine::fireStrictRule(%d)!', $rule->id));
$collection = $this->findStrictRule($rule);
$this->processResults($rule, $collection);
Log::debug(sprintf('SearchRuleEngine:: done processing strict rule #%d', $rule->id));
app('log')->debug(sprintf('SearchRuleEngine:: done processing strict rule #%d', $rule->id));
$result = $collection->count() > 0;
if (true === $result) {
Log::debug(sprintf('SearchRuleEngine:: rule #%d was triggered (on %d transaction(s)).', $rule->id, $collection->count()));
app('log')->debug(sprintf('SearchRuleEngine:: rule #%d was triggered (on %d transaction(s)).', $rule->id, $collection->count()));
return true;
}
Log::debug(sprintf('SearchRuleEngine:: rule #%d was not triggered (on %d transaction(s)).', $rule->id, $collection->count()));
app('log')->debug(sprintf('SearchRuleEngine:: rule #%d was not triggered (on %d transaction(s)).', $rule->id, $collection->count()));
return false;
}
@@ -399,7 +399,7 @@ class SearchRuleEngine implements RuleEngineInterface
*/
private function processResults(Rule $rule, Collection $collection): void
{
Log::debug(sprintf('SearchRuleEngine:: Going to process %d results.', $collection->count()));
app('log')->debug(sprintf('SearchRuleEngine:: Going to process %d results.', $collection->count()));
/** @var array $group */
foreach ($collection as $group) {
$this->processTransactionGroup($rule, $group);
@@ -414,7 +414,7 @@ class SearchRuleEngine implements RuleEngineInterface
*/
private function processTransactionGroup(Rule $rule, array $group): void
{
Log::debug(sprintf('SearchRuleEngine:: Will now execute actions on transaction group #%d', $group['id']));
app('log')->debug(sprintf('SearchRuleEngine:: Will now execute actions on transaction group #%d', $group['id']));
/** @var array $transaction */
foreach ($group['transactions'] as $transaction) {
$this->processTransactionJournal($rule, $transaction);
@@ -429,7 +429,7 @@ class SearchRuleEngine implements RuleEngineInterface
*/
private function processTransactionJournal(Rule $rule, array $transaction): void
{
Log::debug(sprintf('SearchRuleEngine:: Will now execute actions on transaction journal #%d', $transaction['transaction_journal_id']));
app('log')->debug(sprintf('SearchRuleEngine:: Will now execute actions on transaction journal #%d', $transaction['transaction_journal_id']));
$actions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
/** @var RuleAction $ruleAction */
foreach ($actions as $ruleAction) {
@@ -452,13 +452,13 @@ class SearchRuleEngine implements RuleEngineInterface
*/
private function processRuleAction(RuleAction $ruleAction, array $transaction): bool
{
Log::debug(sprintf('Executing rule action "%s" with value "%s"', $ruleAction->action_type, $ruleAction->action_value));
app('log')->debug(sprintf('Executing rule action "%s" with value "%s"', $ruleAction->action_type, $ruleAction->action_value));
$actionClass = ActionFactory::getAction($ruleAction);
$result = $actionClass->actOnArray($transaction);
$journalId = $transaction['transaction_journal_id'] ?? 0;
if (true === $result) {
$this->resultCount[$journalId] = array_key_exists($journalId, $this->resultCount) ? $this->resultCount[$journalId]++ : 1;
Log::debug(
app('log')->debug(
sprintf(
'Action "%s" on journal #%d was executed, so count a result. Updated transaction journal count is now %d.',
$ruleAction->action_type,
@@ -468,12 +468,12 @@ class SearchRuleEngine implements RuleEngineInterface
);
}
if (false === $result) {
Log::debug(sprintf('Action "%s" reports NO changes were made.', $ruleAction->action_type));
app('log')->debug(sprintf('Action "%s" reports NO changes were made.', $ruleAction->action_type));
}
// pick up from the action if it actually acted or not:
if ($ruleAction->stop_processing) {
Log::debug(sprintf('Rule action "%s" asks to break, so break!', $ruleAction->action_type));
app('log')->debug(sprintf('Rule action "%s" asks to break, so break!', $ruleAction->action_type));
return true;
}
@@ -491,11 +491,11 @@ class SearchRuleEngine implements RuleEngineInterface
*/
private function fireNonStrictRule(Rule $rule): bool
{
Log::debug(sprintf('SearchRuleEngine::fireNonStrictRule(%d)!', $rule->id));
app('log')->debug(sprintf('SearchRuleEngine::fireNonStrictRule(%d)!', $rule->id));
$collection = $this->findNonStrictRule($rule);
$this->processResults($rule, $collection);
Log::debug(sprintf('SearchRuleEngine:: done processing non-strict rule #%d', $rule->id));
app('log')->debug(sprintf('SearchRuleEngine:: done processing non-strict rule #%d', $rule->id));
return $collection->count() > 0;
}
@@ -509,16 +509,16 @@ class SearchRuleEngine implements RuleEngineInterface
private function fireGroup(RuleGroup $group): void
{
$all = false;
Log::debug(sprintf('Going to fire group #%d with %d rule(s)', $group->id, $group->rules->count()));
app('log')->debug(sprintf('Going to fire group #%d with %d rule(s)', $group->id, $group->rules->count()));
/** @var Rule $rule */
foreach ($group->rules as $rule) {
Log::debug(sprintf('Going to fire rule #%d from group #%d', $rule->id, $group->id));
app('log')->debug(sprintf('Going to fire rule #%d from group #%d', $rule->id, $group->id));
$result = $this->fireRule($rule);
if (true === $result) {
$all = true;
}
if (true === $result && true === $rule->stop_processing) {
Log::debug(sprintf('The rule was triggered and rule->stop_processing = true, so group #%d will stop processing further rules.', $group->id));
app('log')->debug(sprintf('The rule was triggered and rule->stop_processing = true, so group #%d will stop processing further rules.', $group->id));
return;
}
@@ -548,10 +548,10 @@ class SearchRuleEngine implements RuleEngineInterface
*/
public function setRuleGroups(Collection $ruleGroups): void
{
Log::debug(__METHOD__);
app('log')->debug(__METHOD__);
foreach ($ruleGroups as $group) {
if ($group instanceof RuleGroup) {
Log::debug(sprintf('Adding a rule group to the SearchRuleEngine: #%d ("%s")', $group->id, $group->title));
app('log')->debug(sprintf('Adding a rule group to the SearchRuleEngine: #%d ("%s")', $group->id, $group->title));
$this->groups->push($group);
}
}
@@ -562,10 +562,10 @@ class SearchRuleEngine implements RuleEngineInterface
*/
public function setRules(Collection $rules): void
{
Log::debug(__METHOD__);
app('log')->debug(__METHOD__);
foreach ($rules as $rule) {
if ($rule instanceof Rule) {
Log::debug(sprintf('Adding a rule to the SearchRuleEngine: #%d ("%s")', $rule->id, $rule->title));
app('log')->debug(sprintf('Adding a rule to the SearchRuleEngine: #%d ("%s")', $rule->id, $rule->title));
$this->rules->push($rule);
}
}

View File

@@ -54,7 +54,7 @@ class ActionFactory
public static function getAction(RuleAction $action): ActionInterface
{
$class = self::getActionClass($action->action_type);
Log::debug(sprintf('self::getActionClass("%s") = "%s"', $action->action_type, $class));
app('log')->debug(sprintf('self::getActionClass("%s") = "%s"', $action->action_type, $class));
return new $class($action);
}