Migrate actions

This commit is contained in:
James Cole
2022-10-02 06:23:31 +02:00
parent f2f3d69aa8
commit 10d2a91d99
26 changed files with 319 additions and 33 deletions

View File

@@ -22,6 +22,7 @@ declare(strict_types=1);
namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Events\TriggeredAuditLog;
use FireflyIII\Models\Note;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
@@ -32,8 +33,7 @@ use Log;
*/
class PrependNotes implements ActionInterface
{
/** @var RuleAction The rule action */
private $action;
private RuleAction $action;
/**
* TriggerInterface constructor.
@@ -61,11 +61,19 @@ class PrependNotes implements ActionInterface
$dbNote->noteable_type = TransactionJournal::class;
$dbNote->text = '';
}
$before = $dbNote->text;
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();
// journal
/** @var TransactionJournal $journal */
$journal = TransactionJournal::where('user_id', $journal['user_id'])->find($journal['transaction_journal_id']);
// audit log
event(new TriggeredAuditLog($this->action->rule, $journal, 'update_notes', $before, $text));
return true;
}
}