. */ declare(strict_types=1); namespace FireflyIII\TransactionRules\Actions; use FireflyIII\Events\TriggeredAuditLog; use FireflyIII\Models\RuleAction; use FireflyIII\Models\TransactionJournal; use FireflyIII\TransactionRules\Traits\RefreshNotesTrait; /** * Class AppendDescription. * TODO Can be replaced (and migrated) to action "set description" with a prefilled expression */ class AppendDescription implements ActionInterface { use RefreshNotesTrait; private RuleAction $action; /** * TriggerInterface constructor. */ public function __construct(RuleAction $action) { $this->action = $action; } public function actOnArray(array $journal): bool { $this->refreshNotes($journal); $append = $this->action->getValue($journal); $description = sprintf('%s %s', $journal['description'], $append); \DB::table('transaction_journals')->where('id', $journal['transaction_journal_id'])->limit(1)->update(['description' => $description]); // event for audit log entry /** @var TransactionJournal $object */ $object = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']); event(new TriggeredAuditLog($this->action->rule, $object, 'update_description', $journal['description'], $description)); return true; } }