mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-01 02:21:45 +00:00
Fix code quality with rector [skip ci]
This commit is contained in:
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Factory\TagFactory;
|
||||
@@ -68,7 +69,7 @@ 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']]);
|
||||
app('log')->debug(sprintf('RuleAction AddTag. Added tag #%d ("%s") to journal %d.', $tag->id, $tag->tag, $journal['transaction_journal_id']));
|
||||
Log::debug(sprintf('RuleAction AddTag. Added tag #%d ("%s") to journal %d.', $tag->id, $tag->tag, $journal['transaction_journal_id']));
|
||||
|
||||
/** @var TransactionJournal $object */
|
||||
$object = TransactionJournal::find($journal['transaction_journal_id']);
|
||||
@@ -78,7 +79,7 @@ class AddTag implements ActionInterface
|
||||
|
||||
return true;
|
||||
}
|
||||
app('log')->debug(
|
||||
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' => $tagName])));
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\Note;
|
||||
@@ -51,7 +52,7 @@ class AppendDescriptionToNotes implements ActionInterface
|
||||
/** @var null|TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
if (null === $object) {
|
||||
app('log')->error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
|
||||
Log::error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, (string) trans('rules.journal_other_user')));
|
||||
|
||||
return false;
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
@@ -64,7 +65,7 @@ class AppendNotes implements ActionInterface
|
||||
/** @var TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
|
||||
app('log')->debug(sprintf('RuleAction AppendNotes appended "%s" to "%s".', $append, $before));
|
||||
Log::debug(sprintf('RuleAction AppendNotes appended "%s" to "%s".', $append, $before));
|
||||
event(new TriggeredAuditLog($this->action->rule, $object, 'update_notes', $before, $text));
|
||||
|
||||
return true;
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\Note;
|
||||
@@ -48,20 +49,20 @@ class AppendNotesToDescription implements ActionInterface
|
||||
|
||||
public function actOnArray(array $journal): bool
|
||||
{
|
||||
app('log')->debug('Now in AppendNotesToDescription');
|
||||
Log::debug('Now in AppendNotesToDescription');
|
||||
$this->refreshNotes($journal);
|
||||
|
||||
/** @var null|TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
if (null === $object) {
|
||||
app('log')->error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
|
||||
Log::error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_other_user')));
|
||||
|
||||
return false;
|
||||
}
|
||||
$note = $object->notes()->first();
|
||||
if (null === $note) {
|
||||
app('log')->debug('Journal has no notes.');
|
||||
Log::debug('Journal has no notes.');
|
||||
$note = new Note();
|
||||
$note->noteable()->associate($object);
|
||||
$note->text = '';
|
||||
@@ -71,7 +72,7 @@ class AppendNotesToDescription implements ActionInterface
|
||||
$before = $object->description;
|
||||
$object->description = trim(sprintf('%s %s', $object->description, (string) $this->clearString($note->text)));
|
||||
$object->save();
|
||||
app('log')->debug(sprintf('Journal description is updated to "%s".', $object->description));
|
||||
Log::debug(sprintf('Journal description is updated to "%s".', $object->description));
|
||||
|
||||
event(new TriggeredAuditLog($this->action->rule, $object, 'update_description', $before, $object->description));
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
@@ -45,7 +46,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) {
|
||||
app('log')->debug(sprintf('RuleAction ClearBudget, no budget in journal #%d.', $journal['transaction_journal_id']));
|
||||
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;
|
||||
@@ -55,7 +56,7 @@ class ClearBudget implements ActionInterface
|
||||
|
||||
event(new TriggeredAuditLog($this->action->rule, $object, 'clear_budget', $budget->name, null));
|
||||
|
||||
app('log')->debug(sprintf('RuleAction ClearBudget removed all budgets from journal #%d.', $journal['transaction_journal_id']));
|
||||
Log::debug(sprintf('RuleAction ClearBudget removed all budgets from journal #%d.', $journal['transaction_journal_id']));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
@@ -45,7 +46,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) {
|
||||
app('log')->debug(sprintf('RuleAction ClearCategory, no category in journal #%d.', $journal['transaction_journal_id']));
|
||||
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;
|
||||
@@ -55,7 +56,7 @@ class ClearCategory implements ActionInterface
|
||||
|
||||
event(new TriggeredAuditLog($this->action->rule, $object, 'clear_category', $category->name, null));
|
||||
|
||||
app('log')->debug(sprintf('RuleAction ClearCategory removed all categories from journal #%d.', $journal['transaction_journal_id']));
|
||||
Log::debug(sprintf('RuleAction ClearCategory removed all categories from journal #%d.', $journal['transaction_journal_id']));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\Note;
|
||||
@@ -48,7 +49,7 @@ class ClearNotes implements ActionInterface
|
||||
/** @var null|Note $notes */
|
||||
$notes = $object->notes()->first();
|
||||
if (null === $notes) {
|
||||
app('log')->debug(sprintf('RuleAction ClearNotes, journal #%d has no notes.', $journal['transaction_journal_id']));
|
||||
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;
|
||||
@@ -60,7 +61,7 @@ class ClearNotes implements ActionInterface
|
||||
->where('noteable_type', TransactionJournal::class)
|
||||
->delete()
|
||||
;
|
||||
app('log')->debug(sprintf('RuleAction ClearNotes removed all notes from journal #%d.', $journal['transaction_journal_id']));
|
||||
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));
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
@@ -56,36 +57,36 @@ class ConvertToDeposit implements ActionInterface
|
||||
/** @var null|TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
if (null === $object) {
|
||||
app('log')->error(sprintf('Cannot find journal #%d, cannot convert to deposit.', $journal['transaction_journal_id']));
|
||||
Log::error(sprintf('Cannot find journal #%d, cannot convert to deposit.', $journal['transaction_journal_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_not_found')));
|
||||
|
||||
return false;
|
||||
}
|
||||
$groupCount = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count();
|
||||
if ($groupCount > 1) {
|
||||
app('log')->error(sprintf('Group #%d has more than one transaction in it, cannot convert to deposit.', $journal['transaction_group_id']));
|
||||
Log::error(sprintf('Group #%d has more than one transaction in it, cannot convert to deposit.', $journal['transaction_group_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.split_group')));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('Convert journal #%d to deposit.', $journal['transaction_journal_id']));
|
||||
Log::debug(sprintf('Convert journal #%d to deposit.', $journal['transaction_journal_id']));
|
||||
$type = $object->transactionType->type;
|
||||
if (TransactionTypeEnum::DEPOSIT->value === $type) {
|
||||
app('log')->error(sprintf('Journal #%d is already a deposit (rule #%d).', $journal['transaction_journal_id'], $this->action->rule_id));
|
||||
Log::error(sprintf('Journal #%d is already a deposit (rule #%d).', $journal['transaction_journal_id'], $this->action->rule_id));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.is_already_deposit')));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||
app('log')->debug('Going to transform a withdrawal to a deposit.');
|
||||
Log::debug('Going to transform a withdrawal to a deposit.');
|
||||
|
||||
try {
|
||||
$res = $this->convertWithdrawalArray($object, $actionValue);
|
||||
} catch (FireflyException $e) {
|
||||
app('log')->debug('Could not convert withdrawal to deposit.');
|
||||
app('log')->error($e->getMessage());
|
||||
Log::debug('Could not convert withdrawal to deposit.');
|
||||
Log::error($e->getMessage());
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
|
||||
|
||||
return false;
|
||||
@@ -96,13 +97,13 @@ class ConvertToDeposit implements ActionInterface
|
||||
return $res;
|
||||
}
|
||||
if (TransactionTypeEnum::TRANSFER->value === $type) {
|
||||
app('log')->debug('Going to transform a transfer to a deposit.');
|
||||
Log::debug('Going to transform a transfer to a deposit.');
|
||||
|
||||
try {
|
||||
$res = $this->convertTransferArray($object, $actionValue);
|
||||
} catch (FireflyException $e) {
|
||||
app('log')->debug('Could not convert transfer to deposit.');
|
||||
app('log')->error($e->getMessage());
|
||||
Log::debug('Could not convert transfer to deposit.');
|
||||
Log::error($e->getMessage());
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
|
||||
|
||||
return false;
|
||||
@@ -147,7 +148,7 @@ class ConvertToDeposit implements ActionInterface
|
||||
$opposingAccount = $factory->findOrCreate($opposingName, AccountTypeEnum::REVENUE->value);
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('ConvertToDeposit. Action value is "%s", new opposing name is "%s"', $actionValue, $opposingAccount->name));
|
||||
Log::debug(sprintf('ConvertToDeposit. Action value is "%s", new opposing name is "%s"', $actionValue, $opposingAccount->name));
|
||||
|
||||
// update the source transaction and put in the new revenue ID.
|
||||
DB::table('transactions')
|
||||
@@ -171,7 +172,7 @@ class ConvertToDeposit implements ActionInterface
|
||||
->update(['transaction_type_id' => $newType->id, 'bill_id' => null])
|
||||
;
|
||||
|
||||
app('log')->debug('Converted withdrawal to deposit.');
|
||||
Log::debug('Converted withdrawal to deposit.');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -235,7 +236,7 @@ class ConvertToDeposit implements ActionInterface
|
||||
$opposingAccount = $factory->findOrCreate($opposingName, AccountTypeEnum::REVENUE->value);
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $actionValue, $opposingAccount->name));
|
||||
Log::debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $actionValue, $opposingAccount->name));
|
||||
|
||||
// update source transaction(s) to be revenue account
|
||||
DB::table('transactions')
|
||||
@@ -252,7 +253,7 @@ class ConvertToDeposit implements ActionInterface
|
||||
->update(['transaction_type_id' => $newType->id, 'bill_id' => null])
|
||||
;
|
||||
|
||||
app('log')->debug('Converted transfer to deposit.');
|
||||
Log::debug('Converted transfer to deposit.');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnObject;
|
||||
@@ -59,14 +60,14 @@ class ConvertToTransfer implements ActionInterface
|
||||
/** @var null|TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
if (null === $object) {
|
||||
app('log')->error(sprintf('Cannot find journal #%d, cannot convert to transfer.', $journal['transaction_journal_id']));
|
||||
Log::error(sprintf('Cannot find journal #%d, cannot convert to transfer.', $journal['transaction_journal_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_not_found')));
|
||||
|
||||
return false;
|
||||
}
|
||||
$groupCount = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count();
|
||||
if ($groupCount > 1) {
|
||||
app('log')->error(sprintf('Group #%d has more than one transaction in it, cannot convert to transfer.', $journal['transaction_group_id']));
|
||||
Log::error(sprintf('Group #%d has more than one transaction in it, cannot convert to transfer.', $journal['transaction_group_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.split_group')));
|
||||
|
||||
return false;
|
||||
@@ -76,7 +77,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
$user = $object->user;
|
||||
$journalId = $object->id;
|
||||
if (TransactionTypeEnum::TRANSFER->value === $type) {
|
||||
app('log')->error(
|
||||
Log::error(
|
||||
sprintf('Journal #%d is already a transfer so cannot be converted (rule #%d).', $object->id, $this->action->rule_id)
|
||||
);
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.is_already_transfer')));
|
||||
@@ -105,7 +106,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
$opposing = $repository->findByName($accountName, [$expectedType]);
|
||||
|
||||
if (null === $opposing) {
|
||||
app('log')->error(
|
||||
Log::error(
|
||||
sprintf(
|
||||
'Journal #%d cannot be converted because no valid %s account with name "%s" exists (rule #%d).',
|
||||
$expectedType,
|
||||
@@ -120,36 +121,36 @@ class ConvertToTransfer implements ActionInterface
|
||||
}
|
||||
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||
app('log')->debug('Going to transform a withdrawal to a transfer.');
|
||||
Log::debug('Going to transform a withdrawal to a transfer.');
|
||||
|
||||
try {
|
||||
$res = $this->convertWithdrawalArray($object, $opposing);
|
||||
} catch (FireflyException $e) {
|
||||
app('log')->debug('Could not convert withdrawal to transfer.');
|
||||
app('log')->error($e->getMessage());
|
||||
Log::debug('Could not convert withdrawal to transfer.');
|
||||
Log::error($e->getMessage());
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
|
||||
|
||||
return false;
|
||||
}
|
||||
if (false !== $res) {
|
||||
if ($res) {
|
||||
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::WITHDRAWAL->value, TransactionTypeEnum::TRANSFER->value));
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
// can only be a deposit at this point.
|
||||
app('log')->debug('Going to transform a deposit to a transfer.');
|
||||
Log::debug('Going to transform a deposit to a transfer.');
|
||||
|
||||
try {
|
||||
$res = $this->convertDepositArray($object, $opposing);
|
||||
} catch (FireflyException $e) {
|
||||
app('log')->debug('Could not convert deposit to transfer.');
|
||||
app('log')->error($e->getMessage());
|
||||
Log::debug('Could not convert deposit to transfer.');
|
||||
Log::error($e->getMessage());
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
|
||||
|
||||
return false;
|
||||
}
|
||||
if (false !== $res) {
|
||||
if ($res) {
|
||||
event(new TriggeredAuditLog($this->action->rule, $object, 'update_transaction_type', TransactionTypeEnum::DEPOSIT->value, TransactionTypeEnum::TRANSFER->value));
|
||||
}
|
||||
|
||||
@@ -161,7 +162,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
/** @var null|TransactionJournal $journal */
|
||||
$journal = TransactionJournal::find($journalId);
|
||||
if (null === $journal) {
|
||||
app('log')->error(sprintf('Journal #%d does not exist. Cannot convert to transfer.', $journalId));
|
||||
Log::error(sprintf('Journal #%d does not exist. Cannot convert to transfer.', $journalId));
|
||||
|
||||
return '';
|
||||
}
|
||||
@@ -174,7 +175,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
/** @var null|TransactionJournal $journal */
|
||||
$journal = TransactionJournal::find($journalId);
|
||||
if (null === $journal) {
|
||||
app('log')->error(sprintf('Journal #%d does not exist. Cannot convert to transfer.', $journalId));
|
||||
Log::error(sprintf('Journal #%d does not exist. Cannot convert to transfer.', $journalId));
|
||||
|
||||
return '';
|
||||
}
|
||||
@@ -193,7 +194,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
{
|
||||
$sourceAccount = $this->getSourceAccount($journal);
|
||||
if ($sourceAccount->id === $opposing->id) {
|
||||
app('log')->error(
|
||||
Log::error(
|
||||
vsprintf(
|
||||
'Journal #%d has already has "%s" as a source asset. ConvertToTransfer failed. (rule #%d).',
|
||||
[$journal->id, $opposing->name, $this->action->rule_id]
|
||||
@@ -219,7 +220,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
->update(['transaction_type_id' => $newType->id, 'bill_id' => null])
|
||||
;
|
||||
|
||||
app('log')->debug('Converted withdrawal to transfer.');
|
||||
Log::debug('Converted withdrawal to transfer.');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -248,7 +249,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
{
|
||||
$destAccount = $this->getDestinationAccount($journal);
|
||||
if ($destAccount->id === $opposing->id) {
|
||||
app('log')->error(
|
||||
Log::error(
|
||||
vsprintf(
|
||||
'Journal #%d has already has "%s" as a destination asset. ConvertToTransfer failed. (rule #%d).',
|
||||
[$journal->id, $opposing->name, $this->action->rule_id]
|
||||
@@ -274,7 +275,7 @@ class ConvertToTransfer implements ActionInterface
|
||||
->update(['transaction_type_id' => $newType->id, 'bill_id' => null])
|
||||
;
|
||||
|
||||
app('log')->debug('Converted deposit to transfer.');
|
||||
Log::debug('Converted deposit to transfer.');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
@@ -56,14 +57,14 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
/** @var null|TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
if (null === $object) {
|
||||
app('log')->error(sprintf('Cannot find journal #%d, cannot convert to withdrawal.', $journal['transaction_journal_id']));
|
||||
Log::error(sprintf('Cannot find journal #%d, cannot convert to withdrawal.', $journal['transaction_journal_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_not_found')));
|
||||
|
||||
return false;
|
||||
}
|
||||
$groupCount = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count();
|
||||
if ($groupCount > 1) {
|
||||
app('log')->error(sprintf('Group #%d has more than one transaction in it, cannot convert to withdrawal.', $journal['transaction_group_id']));
|
||||
Log::error(sprintf('Group #%d has more than one transaction in it, cannot convert to withdrawal.', $journal['transaction_group_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.split_group')));
|
||||
|
||||
return false;
|
||||
@@ -71,7 +72,7 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
|
||||
$type = $object->transactionType->type;
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
|
||||
app('log')->error(sprintf('Journal #%d is already a withdrawal (rule #%d).', $journal['transaction_journal_id'], $this->action->rule_id));
|
||||
Log::error(sprintf('Journal #%d is already a withdrawal (rule #%d).', $journal['transaction_journal_id'], $this->action->rule_id));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.is_already_withdrawal')));
|
||||
|
||||
return false;
|
||||
@@ -82,13 +83,13 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
return false;
|
||||
}
|
||||
if (TransactionTypeEnum::DEPOSIT->value === $type) {
|
||||
app('log')->debug('Going to transform a deposit to a withdrawal.');
|
||||
Log::debug('Going to transform a deposit to a withdrawal.');
|
||||
|
||||
try {
|
||||
$res = $this->convertDepositArray($object, $actionValue);
|
||||
} catch (FireflyException $e) {
|
||||
app('log')->debug('Could not convert transfer to deposit.');
|
||||
app('log')->error($e->getMessage());
|
||||
Log::debug('Could not convert transfer to deposit.');
|
||||
Log::error($e->getMessage());
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
|
||||
|
||||
return false;
|
||||
@@ -98,13 +99,13 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
return $res;
|
||||
}
|
||||
// can only be transfer at this point.
|
||||
app('log')->debug('Going to transform a transfer to a withdrawal.');
|
||||
Log::debug('Going to transform a transfer to a withdrawal.');
|
||||
|
||||
try {
|
||||
$res = $this->convertTransferArray($object, $actionValue);
|
||||
} catch (FireflyException $e) {
|
||||
app('log')->debug('Could not convert transfer to deposit.');
|
||||
app('log')->error($e->getMessage());
|
||||
Log::debug('Could not convert transfer to deposit.');
|
||||
Log::error($e->getMessage());
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.complex_error')));
|
||||
|
||||
return false;
|
||||
@@ -141,7 +142,7 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
$opposingAccount = $factory->findOrCreate($opposingName, AccountTypeEnum::EXPENSE->value);
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('ConvertToWithdrawal. Action value is "%s", expense name is "%s"', $actionValue, $opposingName));
|
||||
Log::debug(sprintf('ConvertToWithdrawal. Action value is "%s", expense name is "%s"', $actionValue, $opposingName));
|
||||
|
||||
// update source transaction(s) to be the original destination account
|
||||
DB::table('transactions')
|
||||
@@ -164,7 +165,7 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
->update(['transaction_type_id' => $newType->id])
|
||||
;
|
||||
|
||||
app('log')->debug('Converted deposit to withdrawal.');
|
||||
Log::debug('Converted deposit to withdrawal.');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -227,7 +228,7 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
$opposingAccount = $factory->findOrCreate($opposingName, AccountTypeEnum::EXPENSE->value);
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('ConvertToWithdrawal. Action value is "%s", destination name is "%s"', $actionValue, $opposingName));
|
||||
Log::debug(sprintf('ConvertToWithdrawal. Action value is "%s", destination name is "%s"', $actionValue, $opposingName));
|
||||
|
||||
// update destination transaction(s) to be new expense account.
|
||||
DB::table('transactions')
|
||||
@@ -243,7 +244,7 @@ class ConvertToWithdrawal implements ActionInterface
|
||||
->update(['transaction_type_id' => $newType->id])
|
||||
;
|
||||
|
||||
app('log')->debug('Converted transfer to withdrawal.');
|
||||
Log::debug('Converted transfer to withdrawal.');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
@@ -46,7 +47,7 @@ class DeleteTransaction implements ActionInterface
|
||||
|
||||
// destroy entire group.
|
||||
if (1 === $count) {
|
||||
app('log')->debug(
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'RuleAction DeleteTransaction DELETED the entire transaction group of journal #%d ("%s").',
|
||||
$journal['transaction_journal_id'],
|
||||
@@ -63,7 +64,7 @@ class DeleteTransaction implements ActionInterface
|
||||
|
||||
return true;
|
||||
}
|
||||
app('log')->debug(
|
||||
Log::debug(
|
||||
sprintf('RuleAction DeleteTransaction DELETED transaction journal #%d ("%s").', $journal['transaction_journal_id'], $journal['description'])
|
||||
);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\Note;
|
||||
@@ -46,7 +47,7 @@ class MoveDescriptionToNotes implements ActionInterface
|
||||
/** @var null|TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
if (null === $object) {
|
||||
app('log')->error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
|
||||
Log::error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_other_user')));
|
||||
|
||||
return false;
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
@@ -52,7 +53,7 @@ class MoveNotesToDescription implements ActionInterface
|
||||
/** @var null|TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
if (null === $object) {
|
||||
app('log')->error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
|
||||
Log::error(sprintf('No journal #%d belongs to user #%d.', $journal['transaction_journal_id'], $journal['user_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_other_user')));
|
||||
|
||||
return false;
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
@@ -53,7 +54,7 @@ class PrependNotes implements ActionInterface
|
||||
}
|
||||
$before = $dbNote->text;
|
||||
$after = $this->action->getValue($journal);
|
||||
app('log')->debug(sprintf('RuleAction PrependNotes prepended "%s" to "%s".', $after, $dbNote->text));
|
||||
Log::debug(sprintf('RuleAction PrependNotes prepended "%s" to "%s".', $after, $dbNote->text));
|
||||
$text = sprintf('%s%s', $after, $dbNote->text);
|
||||
$dbNote->text = $text;
|
||||
$dbNote->save();
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
@@ -44,12 +45,12 @@ 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) {
|
||||
app('log')->debug(sprintf('RuleAction RemoveAllTags, journal #%d has no tags.', $journal['transaction_journal_id']));
|
||||
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;
|
||||
}
|
||||
app('log')->debug(sprintf('RuleAction RemoveAllTags removed all tags from journal %d.', $journal['transaction_journal_id']));
|
||||
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']);
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
@@ -50,7 +51,7 @@ class RemoveTag implements ActionInterface
|
||||
|
||||
// if tag does not exist, no need to continue:
|
||||
if (null === $tag) {
|
||||
app('log')->debug(
|
||||
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])));
|
||||
@@ -59,7 +60,7 @@ 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) {
|
||||
app('log')->debug(
|
||||
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])));
|
||||
@@ -67,7 +68,7 @@ class RemoveTag implements ActionInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('RuleAction RemoveTag removed tag #%d ("%s") from journal #%d.', $tag->id, $tag->tag, $journal['transaction_journal_id']));
|
||||
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)
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
@@ -47,7 +48,7 @@ class SetAmount implements ActionInterface
|
||||
// not on slpit transactions
|
||||
$groupCount = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count();
|
||||
if ($groupCount > 1) {
|
||||
app('log')->error(sprintf('Group #%d has more than one transaction in it, cannot convert to transfer.', $journal['transaction_group_id']));
|
||||
Log::error(sprintf('Group #%d has more than one transaction in it, cannot convert to transfer.', $journal['transaction_group_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.split_group')));
|
||||
|
||||
return false;
|
||||
@@ -56,7 +57,7 @@ class SetAmount implements ActionInterface
|
||||
$value = $this->action->getValue($journal);
|
||||
|
||||
if (!is_numeric($value) || 0 === bccomp($value, '0')) {
|
||||
app('log')->debug(sprintf('RuleAction SetAmount, amount "%s" is not a number or is zero, will not continue.', $value));
|
||||
Log::debug(sprintf('RuleAction SetAmount, amount "%s" is not a number or is zero, will not continue.', $value));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.journal_invalid_amount', ['amount' => $value])));
|
||||
|
||||
return false;
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
@@ -49,7 +50,7 @@ class SetBudget implements ActionInterface
|
||||
|
||||
$budget = $user->budgets()->where('name', $search)->first();
|
||||
if (null === $budget) {
|
||||
app('log')->debug(
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'RuleAction SetBudget could not set budget of journal #%d to "%s" because no such budget exists.',
|
||||
$journal['transaction_journal_id'],
|
||||
@@ -62,7 +63,7 @@ class SetBudget implements ActionInterface
|
||||
}
|
||||
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value !== $journal['transaction_type_type']) {
|
||||
app('log')->debug(
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'RuleAction SetBudget could not set budget of journal #%d to "%s" because journal is a %s.',
|
||||
$journal['transaction_journal_id'],
|
||||
@@ -86,7 +87,7 @@ class SetBudget implements ActionInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
app('log')->debug(
|
||||
Log::debug(
|
||||
sprintf('RuleAction SetBudget set the budget of journal #%d to budget #%d ("%s").', $journal['transaction_journal_id'], $budget->id, $budget->name)
|
||||
);
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Factory\CategoryFactory;
|
||||
@@ -47,7 +48,7 @@ class SetCategory implements ActionInterface
|
||||
$user = User::find($journal['user_id']);
|
||||
$search = $this->action->getValue($journal);
|
||||
if (null === $user) {
|
||||
app('log')->error(sprintf('Journal has no valid user ID so action SetCategory("%s") cannot be applied', $search), $journal);
|
||||
Log::error(sprintf('Journal has no valid user ID so action SetCategory("%s") cannot be applied', $search), $journal);
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_such_journal')));
|
||||
|
||||
return false;
|
||||
@@ -58,7 +59,7 @@ class SetCategory implements ActionInterface
|
||||
$factory->setUser($user);
|
||||
$category = $factory->findOrCreate(null, $search);
|
||||
if (null === $category) {
|
||||
app('log')->debug(
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'RuleAction SetCategory could not set category of journal #%d to "%s" because no such category exists.',
|
||||
$journal['transaction_journal_id'],
|
||||
@@ -70,7 +71,7 @@ class SetCategory implements ActionInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
app('log')->debug(
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'RuleAction SetCategory set the category of journal #%d to category #%d ("%s").',
|
||||
$journal['transaction_journal_id'],
|
||||
|
||||
@@ -64,7 +64,7 @@ class SetDescription implements ActionInterface
|
||||
->update(['description' => $after])
|
||||
;
|
||||
|
||||
app('log')->debug(
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'RuleAction SetDescription changed the description of journal #%d from "%s" to "%s".',
|
||||
$journal['transaction_journal_id'],
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
@@ -58,7 +59,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
if (null === $object) {
|
||||
app('log')->error('Could not find journal.');
|
||||
Log::error('Could not find journal.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_such_journal')));
|
||||
|
||||
return false;
|
||||
@@ -69,7 +70,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
// if this is a transfer or a deposit, the new destination account must be an asset account or a default account, and it MUST exist:
|
||||
$newAccount = $this->findAssetAccount($type, $accountName);
|
||||
if ((TransactionTypeEnum::DEPOSIT->value === $type || TransactionTypeEnum::TRANSFER->value === $type) && !$newAccount instanceof Account) {
|
||||
app('log')->error(
|
||||
Log::error(
|
||||
sprintf(
|
||||
'Cant change destination account of journal #%d because no asset account with name "%s" exists.',
|
||||
$object->id,
|
||||
@@ -85,20 +86,20 @@ class SetDestinationAccount implements ActionInterface
|
||||
/** @var null|Transaction $source */
|
||||
$source = $object->transactions()->where('amount', '<', 0)->first();
|
||||
if (null === $source) {
|
||||
app('log')->error('Could not find source transaction.');
|
||||
Log::error('Could not find source transaction.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_source_transaction')));
|
||||
|
||||
return false;
|
||||
}
|
||||
// account must not be deleted (in the meantime):
|
||||
if (null === $source->account) {
|
||||
app('log')->error('Could not find source transaction account.');
|
||||
Log::error('Could not find source transaction account.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_source_transaction_account')));
|
||||
|
||||
return false;
|
||||
}
|
||||
if ($newAccount instanceof Account && $newAccount->id === $source->account_id) {
|
||||
app('log')->error(
|
||||
Log::error(
|
||||
sprintf(
|
||||
'New destination account ID #%d and current source account ID #%d are the same. Do nothing.',
|
||||
$newAccount->id,
|
||||
@@ -117,7 +118,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
$newAccount = $this->findWithdrawalDestinationAccount($accountName);
|
||||
}
|
||||
if (!$newAccount instanceof Account) {
|
||||
app('log')->error(
|
||||
Log::error(
|
||||
sprintf(
|
||||
'No destination account found for name "%s".',
|
||||
$accountName
|
||||
@@ -129,7 +130,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('New destination account is #%d ("%s").', $newAccount->id, $newAccount->name));
|
||||
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));
|
||||
|
||||
@@ -140,7 +141,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
->update(['account_id' => $newAccount->id])
|
||||
;
|
||||
|
||||
app('log')->debug(sprintf('Updated journal #%d (group #%d) and gave it new destination account ID.', $object->id, $object->transaction_group_id));
|
||||
Log::debug(sprintf('Updated journal #%d (group #%d) and gave it new destination account ID.', $object->id, $object->transaction_group_id));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -150,7 +151,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
// switch on type:
|
||||
$allowed = config(sprintf('firefly.expected_source_types.destination.%s', $type));
|
||||
$allowed = is_array($allowed) ? $allowed : [];
|
||||
app('log')->debug(sprintf('Check config for expected_source_types.destination.%s, result is', $type), $allowed);
|
||||
Log::debug(sprintf('Check config for expected_source_types.destination.%s, result is', $type), $allowed);
|
||||
|
||||
return $this->repository->findByName($accountName, $allowed);
|
||||
}
|
||||
@@ -170,7 +171,7 @@ class SetDestinationAccount implements ActionInterface
|
||||
];
|
||||
$account = $this->repository->store($data);
|
||||
}
|
||||
app('log')->debug(sprintf('Found or created expense account #%d ("%s")', $account->id, $account->name));
|
||||
Log::debug(sprintf('Found or created expense account #%d ("%s")', $account->id, $account->name));
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
@@ -54,14 +55,14 @@ class SetDestinationToCashAccount implements ActionInterface
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
if (null === $object) {
|
||||
app('log')->error('Could not find journal.');
|
||||
Log::error('Could not find journal.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_such_journal')));
|
||||
|
||||
return false;
|
||||
}
|
||||
$type = $object->transactionType->type;
|
||||
if (TransactionTypeEnum::WITHDRAWAL->value !== $type) {
|
||||
app('log')->error('Transaction must be withdrawal.');
|
||||
Log::error('Transaction must be withdrawal.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.not_withdrawal')));
|
||||
|
||||
return false;
|
||||
@@ -75,20 +76,20 @@ class SetDestinationToCashAccount implements ActionInterface
|
||||
/** @var null|Transaction $source */
|
||||
$source = $object->transactions()->where('amount', '<', 0)->first();
|
||||
if (null === $source) {
|
||||
app('log')->error('Could not find source transaction.');
|
||||
Log::error('Could not find source transaction.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_source_transaction')));
|
||||
|
||||
return false;
|
||||
}
|
||||
// account must not be deleted (in the meantime):
|
||||
if (null === $source->account) {
|
||||
app('log')->error('Could not find source transaction account.');
|
||||
Log::error('Could not find source transaction account.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_source_transaction_account')));
|
||||
|
||||
return false;
|
||||
}
|
||||
if ($cashAccount->id === $source->account_id) {
|
||||
app('log')->error(
|
||||
Log::error(
|
||||
sprintf(
|
||||
'New destination account ID #%d and current source account ID #%d are the same. Do nothing.',
|
||||
$cashAccount->id,
|
||||
@@ -110,7 +111,7 @@ class SetDestinationToCashAccount implements ActionInterface
|
||||
->update(['account_id' => $cashAccount->id])
|
||||
;
|
||||
|
||||
app('log')->debug(sprintf('Updated journal #%d (group #%d) and gave it new destination account ID.', $object->id, $object->transaction_group_id));
|
||||
Log::debug(sprintf('Updated journal #%d (group #%d) and gave it new destination account ID.', $object->id, $object->transaction_group_id));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
@@ -54,7 +55,7 @@ class SetNotes implements ActionInterface
|
||||
$dbNote->text = $newNotes;
|
||||
$dbNote->save();
|
||||
|
||||
app('log')->debug(
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'RuleAction SetNotes changed the notes of journal #%d from "%s" to "%s".',
|
||||
$journal['transaction_journal_id'],
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
@@ -57,7 +58,7 @@ class SetSourceAccount implements ActionInterface
|
||||
$object = $user->transactionJournals()->find((int) $journal['transaction_journal_id']);
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
if (null === $object) {
|
||||
app('log')->error('Could not find journal.');
|
||||
Log::error('Could not find journal.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_such_journal')));
|
||||
|
||||
return false;
|
||||
@@ -68,7 +69,7 @@ class SetSourceAccount implements ActionInterface
|
||||
// if this is a transfer or a withdrawal, the new source account must be an asset account or a default account, and it MUST exist:
|
||||
$newAccount = $this->findAssetAccount($type, $accountName);
|
||||
if ((TransactionTypeEnum::WITHDRAWAL->value === $type || TransactionTypeEnum::TRANSFER->value === $type) && !$newAccount instanceof Account) {
|
||||
app('log')->error(
|
||||
Log::error(
|
||||
sprintf('Cant change source account of journal #%d because no asset account with name "%s" exists.', $object->id, $accountName)
|
||||
);
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_asset', ['name' => $accountName])));
|
||||
@@ -80,20 +81,20 @@ class SetSourceAccount implements ActionInterface
|
||||
/** @var null|Transaction $destination */
|
||||
$destination = $object->transactions()->where('amount', '>', 0)->first();
|
||||
if (null === $destination) {
|
||||
app('log')->error('Could not find destination transaction.');
|
||||
Log::error('Could not find destination transaction.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_destination_transaction')));
|
||||
|
||||
return false;
|
||||
}
|
||||
// account must not be deleted (in the meantime):
|
||||
if (null === $destination->account) {
|
||||
app('log')->error('Could not find destination transaction account.');
|
||||
Log::error('Could not find destination transaction account.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_destination_transaction_account')));
|
||||
|
||||
return false;
|
||||
}
|
||||
if ($newAccount instanceof Account && $newAccount->id === $destination->account_id) {
|
||||
app('log')->error(
|
||||
Log::error(
|
||||
sprintf(
|
||||
'New source account ID #%d and current destination account ID #%d are the same. Do nothing.',
|
||||
$newAccount->id,
|
||||
@@ -111,7 +112,7 @@ class SetSourceAccount implements ActionInterface
|
||||
$newAccount = $this->findDepositSourceAccount($accountName);
|
||||
}
|
||||
|
||||
app('log')->debug(sprintf('New source account is #%d ("%s").', $newAccount->id, $newAccount->name));
|
||||
Log::debug(sprintf('New source account is #%d ("%s").', $newAccount->id, $newAccount->name));
|
||||
|
||||
// update source transaction with new source account:
|
||||
DB::table('transactions')
|
||||
@@ -122,7 +123,7 @@ class SetSourceAccount implements ActionInterface
|
||||
|
||||
event(new TriggeredAuditLog($this->action->rule, $object, 'set_source', null, $newAccount->name));
|
||||
|
||||
app('log')->debug(sprintf('Updated journal #%d (group #%d) and gave it new source account ID.', $object->id, $object->transaction_group_id));
|
||||
Log::debug(sprintf('Updated journal #%d (group #%d) and gave it new source account ID.', $object->id, $object->transaction_group_id));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -132,7 +133,7 @@ class SetSourceAccount implements ActionInterface
|
||||
// switch on type:
|
||||
$allowed = config(sprintf('firefly.expected_source_types.source.%s', $type));
|
||||
$allowed = is_array($allowed) ? $allowed : [];
|
||||
app('log')->debug(sprintf('Check config for expected_source_types.source.%s, result is', $type), $allowed);
|
||||
Log::debug(sprintf('Check config for expected_source_types.source.%s, result is', $type), $allowed);
|
||||
|
||||
return $this->repository->findByName($accountName, $allowed);
|
||||
}
|
||||
@@ -153,7 +154,7 @@ class SetSourceAccount implements ActionInterface
|
||||
];
|
||||
$account = $this->repository->store($data);
|
||||
}
|
||||
app('log')->debug(sprintf('Found or created revenue account #%d ("%s")', $account->id, $account->name));
|
||||
Log::debug(sprintf('Found or created revenue account #%d ("%s")', $account->id, $account->name));
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
@@ -54,14 +55,14 @@ class SetSourceToCashAccount implements ActionInterface
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
if (null === $object) {
|
||||
app('log')->error('Could not find journal.');
|
||||
Log::error('Could not find journal.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_such_journal')));
|
||||
|
||||
return false;
|
||||
}
|
||||
$type = $object->transactionType->type;
|
||||
if (TransactionTypeEnum::DEPOSIT->value !== $type) {
|
||||
app('log')->error('Transaction must be deposit.');
|
||||
Log::error('Transaction must be deposit.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.not_deposit')));
|
||||
|
||||
return false;
|
||||
@@ -75,20 +76,20 @@ class SetSourceToCashAccount implements ActionInterface
|
||||
/** @var null|Transaction $destination */
|
||||
$destination = $object->transactions()->where('amount', '>', 0)->first();
|
||||
if (null === $destination) {
|
||||
app('log')->error('Could not find destination transaction.');
|
||||
Log::error('Could not find destination transaction.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_destination_transaction')));
|
||||
|
||||
return false;
|
||||
}
|
||||
// account must not be deleted (in the meantime):
|
||||
if (null === $destination->account) {
|
||||
app('log')->error('Could not find destination transaction account.');
|
||||
Log::error('Could not find destination transaction account.');
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_destination_transaction_account')));
|
||||
|
||||
return false;
|
||||
}
|
||||
if ($cashAccount->id === $destination->account_id) {
|
||||
app('log')->error(
|
||||
Log::error(
|
||||
sprintf(
|
||||
'New source account ID #%d and current destination account ID #%d are the same. Do nothing.',
|
||||
$cashAccount->id,
|
||||
@@ -110,7 +111,7 @@ class SetSourceToCashAccount implements ActionInterface
|
||||
->update(['account_id' => $cashAccount->id])
|
||||
;
|
||||
|
||||
app('log')->debug(sprintf('Updated journal #%d (group #%d) and gave it new source account ID.', $object->id, $object->transaction_group_id));
|
||||
Log::debug(sprintf('Updated journal #%d (group #%d) and gave it new source account ID.', $object->id, $object->transaction_group_id));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Events\Model\Rule\RuleActionFailedOnArray;
|
||||
use FireflyIII\Events\TriggeredAuditLog;
|
||||
@@ -47,14 +48,14 @@ class SwitchAccounts implements ActionInterface
|
||||
/** @var null|TransactionJournal $object */
|
||||
$object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
|
||||
if (null === $object) {
|
||||
app('log')->error(sprintf('Cannot find journal #%d, cannot switch accounts.', $journal['transaction_journal_id']));
|
||||
Log::error(sprintf('Cannot find journal #%d, cannot switch accounts.', $journal['transaction_journal_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.no_such_journal')));
|
||||
|
||||
return false;
|
||||
}
|
||||
$groupCount = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count();
|
||||
if ($groupCount > 1) {
|
||||
app('log')->error(sprintf('Group #%d has more than one transaction in it, cannot switch accounts.', $journal['transaction_group_id']));
|
||||
Log::error(sprintf('Group #%d has more than one transaction in it, cannot switch accounts.', $journal['transaction_group_id']));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.split_group')));
|
||||
|
||||
return false;
|
||||
@@ -62,7 +63,7 @@ class SwitchAccounts implements ActionInterface
|
||||
|
||||
$type = $object->transactionType->type;
|
||||
if (TransactionTypeEnum::TRANSFER->value !== $type) {
|
||||
app('log')->error(sprintf('Journal #%d is NOT a transfer (rule #%d), cannot switch accounts.', $journal['transaction_journal_id'], $this->action->rule_id));
|
||||
Log::error(sprintf('Journal #%d is NOT a transfer (rule #%d), cannot switch accounts.', $journal['transaction_journal_id'], $this->action->rule_id));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.is_not_transfer')));
|
||||
|
||||
return false;
|
||||
@@ -74,7 +75,7 @@ class SwitchAccounts implements ActionInterface
|
||||
/** @var null|Transaction $destTransaction */
|
||||
$destTransaction = $object->transactions()->where('amount', '>', 0)->first();
|
||||
if (null === $sourceTransaction || null === $destTransaction) {
|
||||
app('log')->error(sprintf('Journal #%d has no source or destination transaction (rule #%d), cannot switch accounts.', $journal['transaction_journal_id'], $this->action->rule_id));
|
||||
Log::error(sprintf('Journal #%d has no source or destination transaction (rule #%d), cannot switch accounts.', $journal['transaction_journal_id'], $this->action->rule_id));
|
||||
event(new RuleActionFailedOnArray($this->action, $journal, trans('rules.cannot_find_accounts')));
|
||||
|
||||
return false;
|
||||
|
||||
@@ -45,9 +45,10 @@ use Illuminate\Support\Facades\Log;
|
||||
class SearchRuleEngine implements RuleEngineInterface
|
||||
{
|
||||
private readonly Collection $groups;
|
||||
private array $operators;
|
||||
private bool $refreshTriggers;
|
||||
private array $resultCount;
|
||||
private array $operators = [];
|
||||
// always collect the triggers from the database, unless indicated otherwise.
|
||||
private bool $refreshTriggers = true;
|
||||
private array $resultCount = [];
|
||||
private readonly Collection $rules;
|
||||
private User $user;
|
||||
|
||||
@@ -55,11 +56,6 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
{
|
||||
$this->rules = new Collection();
|
||||
$this->groups = new Collection();
|
||||
$this->operators = [];
|
||||
$this->resultCount = [];
|
||||
|
||||
// always collect the triggers from the database, unless indicated otherwise.
|
||||
$this->refreshTriggers = true;
|
||||
}
|
||||
|
||||
public function addOperator(array $operator): void
|
||||
@@ -119,7 +115,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
Log::debug(sprintf('SearchRuleEngine:: add a rule trigger (no context): %s:true', $ruleTrigger->trigger_type));
|
||||
$searchArray[$ruleTrigger->trigger_type][] = 'true';
|
||||
}
|
||||
if (true === $needsContext) {
|
||||
if ($needsContext) {
|
||||
Log::debug(sprintf('SearchRuleEngine:: add a rule trigger (context): %s:"%s"', $ruleTrigger->trigger_type, $ruleTrigger->trigger_value));
|
||||
$searchArray[$ruleTrigger->trigger_type][] = sprintf('"%s"', $ruleTrigger->trigger_value);
|
||||
}
|
||||
@@ -288,7 +284,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
|
||||
// make collection unique
|
||||
$unique = $total->unique(
|
||||
static function (array $group) {
|
||||
static function (array $group): string {
|
||||
$str = '';
|
||||
foreach ($group['transactions'] as $transaction) {
|
||||
$str = sprintf('%s%d', $str, $transaction['transaction_journal_id']);
|
||||
@@ -319,7 +315,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
/** @var Rule $rule */
|
||||
foreach ($this->rules as $rule) { // @phpstan-ignore-line
|
||||
$result = $this->fireRule($rule);
|
||||
if (true === $result && true === $rule->stop_processing) {
|
||||
if ($result && true === $rule->stop_processing) {
|
||||
Log::debug(sprintf('Rule #%d has triggered and executed, but calls to stop processing. Since not in the context of a group, do not stop.', $rule->id));
|
||||
}
|
||||
if (false === $result && true === $rule->stop_processing) {
|
||||
@@ -378,7 +374,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
$this->processResults($rule, $collection);
|
||||
|
||||
$result = $collection->count() > 0;
|
||||
if (true === $result) {
|
||||
if ($result) {
|
||||
Log::debug(sprintf('SearchRuleEngine:: Done. Rule #%d was triggered (on %d transaction(s)).', $rule->id, $collection->count()));
|
||||
|
||||
return true;
|
||||
@@ -428,7 +424,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
continue;
|
||||
}
|
||||
$break = $this->processRuleAction($ruleAction, $transaction);
|
||||
if (true === $break) {
|
||||
if ($break) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -444,7 +440,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
$actionClass = ActionFactory::getAction($ruleAction);
|
||||
$result = $actionClass->actOnArray($transaction);
|
||||
$journalId = $transaction['transaction_journal_id'] ?? 0;
|
||||
if (true === $result) {
|
||||
if ($result) {
|
||||
$this->resultCount[$journalId] = array_key_exists($journalId, $this->resultCount) ? $this->resultCount[$journalId]++ : 1;
|
||||
Log::debug(
|
||||
sprintf(
|
||||
@@ -460,7 +456,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
}
|
||||
|
||||
// pick up from the action if it actually acted or not:
|
||||
if (true === $ruleAction->stop_processing && true === $result) {
|
||||
if (true === $ruleAction->stop_processing && $result) {
|
||||
Log::debug(sprintf('Rule action "%s" reports changes AND asks to break, so break!', $ruleAction->action_type));
|
||||
|
||||
return true;
|
||||
@@ -527,7 +523,7 @@ class SearchRuleEngine implements RuleEngineInterface
|
||||
foreach ($rules as $rule) {
|
||||
Log::debug(sprintf('Going to fire rule #%d with order #%d from group #%d', $rule->id, $rule->order, $group->id));
|
||||
$result = $this->fireRule($rule);
|
||||
if (true === $result && true === $rule->stop_processing) {
|
||||
if ($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));
|
||||
|
||||
return;
|
||||
|
||||
@@ -90,11 +90,11 @@ class ActionExpression
|
||||
{
|
||||
$this->expressionLanguage = app(ExpressionLanguage::class);
|
||||
|
||||
$this->isExpression = self::isExpression($this->expr);
|
||||
$this->isExpression = $this->isExpression($this->expr);
|
||||
$this->validationError = $this->validate();
|
||||
}
|
||||
|
||||
private static function isExpression(string $expr): bool
|
||||
private function isExpression(string $expr): bool
|
||||
{
|
||||
return str_starts_with($expr, '=') && strlen($expr) > 1;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\TransactionRules\Factory;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Support\Domain;
|
||||
@@ -47,7 +48,7 @@ class ActionFactory
|
||||
public static function getAction(RuleAction $action): ActionInterface
|
||||
{
|
||||
$class = self::getActionClass($action->action_type);
|
||||
app('log')->debug(sprintf('self::getActionClass("%s") = "%s"', $action->action_type, $class));
|
||||
Log::debug(sprintf('self::getActionClass("%s") = "%s"', $action->action_type, $class));
|
||||
|
||||
return new $class($action); // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user