Skip to content

Firefly III: a personal finances manager

Create events for transaction links.

James Cole6b79f1abdbdf
diff --git a/app/Events/DestroyedTransactionLink.php b/app/Events/DestroyedTransactionLink.php
new file mode 100644
index 0000000000..2e84cdd5dd
--- /dev/null
+++ b/app/Events/DestroyedTransactionLink.php
@@ -0,0 +1,48 @@
+<?php
+/*
+ * DestroyedTransactionLink.php
+ * Copyright (c) 2020 [email protected]
+ *
+ * This file is part of Firefly III (https://github.com/firefly-iii).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace FireflyIII\Events;
+
+
+use FireflyIII\Models\TransactionJournalLink;
+use Illuminate\Queue\SerializesModels;
+
+/**
+ * Class DestroyedTransactionLink
+ */
+class DestroyedTransactionLink extends Event
+{
+ use SerializesModels;
+
+ private TransactionJournalLink $link;
+
+ /**
+ * DestroyedTransactionLink constructor.
+ *
+ * @param TransactionJournalLink $link
+ */
+ public function __construct(TransactionJournalLink $link)
+ {
+ $this->link = $link;
+ }
+}
\ No newline at end of file
diff --git a/app/Events/StoredTransactionLink.php b/app/Events/StoredTransactionLink.php
new file mode 100644
index 0000000000..46fd004b4d
--- /dev/null
+++ b/app/Events/StoredTransactionLink.php
@@ -0,0 +1,47 @@
+<?php
+/*
+ * StoredTransactionLink.php
+ * Copyright (c) 2020 [email protected]
+ *
+ * This file is part of Firefly III (https://github.com/firefly-iii).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+namespace FireflyIII\Events;
+
+
+use FireflyIII\Models\TransactionJournalLink;
+use Illuminate\Queue\SerializesModels;
+
+/**
+ * Class StoredTransactionLink
+ */
+class StoredTransactionLink extends Event
+{
+ use SerializesModels;
+
+ private TransactionJournalLink $link;
+
+ /**
+ * DestroyedTransactionLink constructor.
+ *
+ * @param TransactionJournalLink $link
+ */
+ public function __construct(TransactionJournalLink $link)
+ {
+ $this->link = $link;
+ }
+}
\ No newline at end of file
diff --git a/app/Events/UpdatedTransactionLink.php b/app/Events/UpdatedTransactionLink.php
new file mode 100644
index 0000000000..7627560f4d
--- /dev/null
+++ b/app/Events/UpdatedTransactionLink.php
@@ -0,0 +1,47 @@
+<?php
+/*
+ * UpdatedTransactionLink.php
+ * Copyright (c) 2020 [email protected]
+ *
+ * This file is part of Firefly III (https://github.com/firefly-iii).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+namespace FireflyIII\Events;
+
+
+use FireflyIII\Models\TransactionJournalLink;
+use Illuminate\Queue\SerializesModels;
+
+/**
+ * Class UpdatedTransactionLink
+ */
+class UpdatedTransactionLink extends Event
+{
+ use SerializesModels;
+
+ private TransactionJournalLink $link;
+
+ /**
+ * DestroyedTransactionLink constructor.
+ *
+ * @param TransactionJournalLink $link
+ */
+ public function __construct(TransactionJournalLink $link)
+ {
+ $this->link = $link;
+ }
+}
\ No newline at end of file
diff --git a/app/Http/Controllers/Transaction/LinkController.php b/app/Http/Controllers/Transaction/LinkController.php
index 2b019710b8..24895c1815 100644
--- a/app/Http/Controllers/Transaction/LinkController.php
+++ b/app/Http/Controllers/Transaction/LinkController.php
@@ -40,10 +40,8 @@ use URL;
*/
class LinkController extends Controller
{
- /** @var JournalRepositoryInterface Journals and transactions overview */
- private $journalRepository;
- /** @var LinkTypeRepositoryInterface Link repository. */
- private $repository;
+ private JournalRepositoryInterface $journalRepository;
+ private LinkTypeRepositoryInterface $repository;
/**
* LinkController constructor.
diff --git a/app/Repositories/LinkType/LinkTypeRepository.php b/app/Repositories/LinkType/LinkTypeRepository.php
index cbb404f007..99be363dce 100644
--- a/app/Repositories/LinkType/LinkTypeRepository.php
+++ b/app/Repositories/LinkType/LinkTypeRepository.php
@@ -23,6 +23,10 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\LinkType;
use Exception;
+use FireflyIII\Events\DestroyedTransactionLink;
+use FireflyIII\Events\RemovedTransactionLink;
+use FireflyIII\Events\StoredTransactionLink;
+use FireflyIII\Events\UpdatedTransactionLink;
use FireflyIII\Models\LinkType;
use FireflyIII\Models\Note;
use FireflyIII\Models\TransactionJournal;
@@ -75,6 +79,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
*/
public function destroyLink(TransactionJournalLink $link): bool
{
+ event(new DestroyedTransactionLink($link));
$link->delete();
return true;
@@ -277,6 +282,8 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
// make note in noteable:
$this->setNoteText($link, (string)$information['notes']);
+ event(new StoredTransactionLink($link));
+
return $link;
}
@@ -327,6 +334,8 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
$journalLink->save();
$this->setNoteText($journalLink, $data['notes']);
+ event(new UpdatedTransactionLink($journalLink));
+
return $journalLink;
}