. */ declare(strict_types=1); namespace FireflyIII\TransactionRules\Actions; use FireflyIII\Events\TriggeredAuditLog; use FireflyIII\Models\RuleAction; use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionJournal; use FireflyIII\Services\Internal\Destroy\JournalDestroyService; use FireflyIII\Services\Internal\Destroy\TransactionGroupDestroyService; use Illuminate\Support\Facades\Log; /** * Class DeleteTransaction. */ class DeleteTransaction implements ActionInterface { private RuleAction $action; /** * TriggerInterface constructor. * * @param RuleAction $action */ public function __construct(RuleAction $action) { $this->action = $action; } /** * @inheritDoc */ public function actOnArray(array $journal): bool { $count = TransactionJournal::where('transaction_group_id', $journal['transaction_group_id'])->count(); // destroy entire group. if (1 === $count) { Log::debug( sprintf( 'RuleAction DeleteTransaction DELETED the entire transaction group of journal #%d ("%s").', $journal['transaction_journal_id'], $journal['description'] ) ); $group = TransactionGroup::find($journal['transaction_group_id']); $service = app(TransactionGroupDestroyService::class); $service->destroy($group); event(new TriggeredAuditLog($this->action->rule, $group, 'delete_group', null, null)); return true; } Log::debug( sprintf('RuleAction DeleteTransaction DELETED transaction journal #%d ("%s").', $journal['transaction_journal_id'], $journal['description']) ); // trigger delete factory: $object = TransactionJournal::find($journal['transaction_group_id']); if (null !== $object) { /** @var JournalDestroyService $service */ $service = app(JournalDestroyService::class); $service->destroy($object); event(new TriggeredAuditLog($this->action->rule, $object, 'delete_journal', null, null)); } return true; } }