. */ declare(strict_types=1); namespace FireflyIII\TransactionRules\Actions; use FireflyIII\Models\Note; use FireflyIII\Models\RuleAction; use FireflyIII\Models\TransactionJournal; use Log; /** * Class PrependNotes. */ class PrependNotes implements ActionInterface { /** @var RuleAction The rule action */ private $action; /** * TriggerInterface constructor. * * @param RuleAction $action */ public function __construct(RuleAction $action) { $this->action = $action; } /** * Prepend 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 PrependNotes prepended "%s" with "%s".', $notes, $this->action->action_value)); $notes = $this->action->action_value . $notes; $dbNote->text = $notes; $dbNote->save(); $journal->save(); return true; } }