. */ declare(strict_types=1); namespace FireflyIII\TransactionRules\Actions; use FireflyIII\Models\Note; use FireflyIII\Models\RuleAction; use FireflyIII\Models\TransactionJournal; use Log; /** * Class AppendNotes. */ class AppendNotes implements ActionInterface { /** @var RuleAction The rule action */ private $action; /** * TriggerInterface constructor. * * @param RuleAction $action */ public function __construct(RuleAction $action) { $this->action = $action; } /** * Append notes with X * * @param TransactionJournal $journal * * @return bool */ public function act(TransactionJournal $journal): bool { $dbNote = $journal->notes()->first(); if (null === $dbNote) { $dbNote = new Note; $dbNote->noteable()->associate($journal); } $notes = $dbNote->text; Log::debug(sprintf('RuleAction AppendNotes appended "%s" to "%s".', $this->action->action_value, $notes)); $notes .= $this->action->action_value; $dbNote->text = $notes; $dbNote->save(); $journal->save(); return true; } }