Skip to content

Firefly III: a personal finances manager

Update rule actions.

James Cole07220eb167a8
diff --git a/app/TransactionRules/Actions/ActionInterface.php b/app/TransactionRules/Actions/ActionInterface.php
index 6c836a51b6..4c845f08ba 100644
--- a/app/TransactionRules/Actions/ActionInterface.php
+++ b/app/TransactionRules/Actions/ActionInterface.php
@@ -39,6 +39,7 @@ interface ActionInterface
/**
* Execute the action.
+ * @deprecated
*
* @param TransactionJournal $journal
*
diff --git a/app/TransactionRules/Actions/AppendDescription.php b/app/TransactionRules/Actions/AppendDescription.php
index 12e3768429..ba0e68615f 100644
--- a/app/TransactionRules/Actions/AppendDescription.php
+++ b/app/TransactionRules/Actions/AppendDescription.php
@@ -25,14 +25,14 @@ namespace FireflyIII\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use Log;
+use DB;
/**
* Class AppendDescription.
*/
class AppendDescription implements ActionInterface
{
- /** @var RuleAction The rule action */
- private $action;
+ private RuleAction $action;
/**
* TriggerInterface constructor.
@@ -59,4 +59,14 @@ class AppendDescription implements ActionInterface
return true;
}
+
+ /**
+ * @inheritDoc
+ */
+ public function actOnArray(array $journal): bool
+ {
+ $description = sprintf('%s%s', $journal['description'], $this->action->action_value);
+ DB::table('transaction_journals')->where('id', $journal['transaction_journal_id'])->limit(1)->update(['description' => $description]);
+ return true;
+ }
}
diff --git a/app/TransactionRules/Actions/AppendNotes.php b/app/TransactionRules/Actions/AppendNotes.php
index 8cc1c0921a..7217740307 100644
--- a/app/TransactionRules/Actions/AppendNotes.php
+++ b/app/TransactionRules/Actions/AppendNotes.php
@@ -68,4 +68,29 @@ class AppendNotes implements ActionInterface
return true;
}
+
+ /**
+ * @inheritDoc
+ */
+ public function actOnArray(array $journal): bool
+ {
+ $dbNote = Note
+ ::
+ where('noteable_id', (int) $journal['transaction_journal_id'])
+ ->where('noteable_type', TransactionJournal::class)
+ ->first(['notes.*']);
+ if (null === $dbNote) {
+ $dbNote = new Note;
+ $dbNote->noteable_id = (int) $journal['transaction_journal_id'];
+ $dbNote->noteable_type = TransactionJournal::class;
+ $dbNote->text = '';
+
+
+ }
+ Log::debug(sprintf('RuleAction AppendNotes appended "%s" to "%s".', $this->action->action_value, $dbNote->text));
+ $text = sprintf('%s%s', $dbNote->text, $this->action->action_value);
+ $dbNote->text = $text;
+ $dbNote->save();
+ return true;
+ }
}