Create events for transaction links.

This commit is contained in:
James Cole 2020-11-08 14:27:03 +01:00
parent 52ce873aac
commit 6b79f1abdb
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
5 changed files with 153 additions and 4 deletions

View File

@ -0,0 +1,48 @@
<?php
/*
* DestroyedTransactionLink.php
* Copyright (c) 2020 james@firefly-iii.org
*
* 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;
}
}

View File

@ -0,0 +1,47 @@
<?php
/*
* StoredTransactionLink.php
* Copyright (c) 2020 james@firefly-iii.org
*
* 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;
}
}

View File

@ -0,0 +1,47 @@
<?php
/*
* UpdatedTransactionLink.php
* Copyright (c) 2020 james@firefly-iii.org
*
* 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;
}
}

View File

@ -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.

View File

@ -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;
}