mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-22 17:06:39 -06:00
Update rule actions.
This commit is contained in:
parent
216a0a186c
commit
07220eb167
@ -39,6 +39,7 @@ interface ActionInterface
|
||||
|
||||
/**
|
||||
* Execute the action.
|
||||
* @deprecated
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user