mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-25 13:10:35 +00:00
Better user group management and object observers
This commit is contained in:
58
app/Handlers/Observer/AccountObserver.php
Normal file
58
app/Handlers/Observer/AccountObserver.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/*
|
||||
* AccountObserver.php
|
||||
* Copyright (c) 2023 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\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
|
||||
/**
|
||||
* Class AccountObserver
|
||||
*/
|
||||
class AccountObserver
|
||||
{
|
||||
/**
|
||||
* Also delete related objects.
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(Account $account): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of an account.');
|
||||
$account->accountMeta()->delete();
|
||||
foreach ($account->piggyBanks()->get() as $piggy) {
|
||||
$piggy->delete();
|
||||
}
|
||||
foreach ($account->attachments()->get() as $attachment) {
|
||||
$attachment->delete();
|
||||
}
|
||||
foreach ($account->transactions()->get() as $transaction) {
|
||||
$transaction->delete();
|
||||
}
|
||||
$account->notes()->delete();
|
||||
$account->locations()->delete();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
36
app/Handlers/Observer/AttachmentObserver.php
Normal file
36
app/Handlers/Observer/AttachmentObserver.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*
|
||||
* AttachmentObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\Attachment;
|
||||
|
||||
/**
|
||||
* Class AttachmentObserver
|
||||
*/
|
||||
class AttachmentObserver
|
||||
{
|
||||
public function deleting(Attachment $attachment): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of an attachment.');
|
||||
$attachment->notes()->delete();
|
||||
}
|
||||
}
|
||||
45
app/Handlers/Observer/BillObserver.php
Normal file
45
app/Handlers/Observer/BillObserver.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/*
|
||||
* BillObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
|
||||
/**
|
||||
* Class BillObserver
|
||||
*/
|
||||
class BillObserver
|
||||
{
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(Bill $bill): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a bill.');
|
||||
foreach ($bill->attachments()->get() as $attachment) {
|
||||
$attachment->delete();
|
||||
}
|
||||
$bill->notes()->delete();
|
||||
}
|
||||
|
||||
}
|
||||
49
app/Handlers/Observer/BudgetObserver.php
Normal file
49
app/Handlers/Observer/BudgetObserver.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* BudgetObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\Budget;
|
||||
|
||||
/**
|
||||
* Class BudgetObserver
|
||||
*/
|
||||
class BudgetObserver
|
||||
{
|
||||
/**
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(Budget $budget): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a budget.');
|
||||
foreach ($budget->attachments()->get() as $attachment) {
|
||||
$attachment->delete();
|
||||
}
|
||||
|
||||
$budget->budgetlimits()->delete();
|
||||
|
||||
$budget->notes()->delete();
|
||||
$budget->autoBudgets()->delete();
|
||||
}
|
||||
|
||||
}
|
||||
45
app/Handlers/Observer/CategoryObserver.php
Normal file
45
app/Handlers/Observer/CategoryObserver.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/*
|
||||
* CategoryObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\Category;
|
||||
|
||||
/**
|
||||
* Class CategoryObserver
|
||||
*/
|
||||
class CategoryObserver
|
||||
{
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(Category $category): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a category.');
|
||||
foreach ($category->attachments()->get() as $attachment) {
|
||||
$attachment->delete();
|
||||
}
|
||||
$category->notes()->delete();
|
||||
}
|
||||
|
||||
}
|
||||
71
app/Handlers/Observer/PiggyBankObserver.php
Normal file
71
app/Handlers/Observer/PiggyBankObserver.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/*
|
||||
* PiggyBankObserver.php
|
||||
* Copyright (c) 2023 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\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankRepetition;
|
||||
|
||||
/**
|
||||
* Class PiggyBankObserver
|
||||
*/
|
||||
class PiggyBankObserver
|
||||
{
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function created(PiggyBank $piggyBank): void
|
||||
{
|
||||
app('log')->debug('Observe "created" of a piggy bank.');
|
||||
$repetition = new PiggyBankRepetition();
|
||||
$repetition->piggyBank()->associate($piggyBank);
|
||||
$repetition->startdate = $piggyBank->startdate;
|
||||
$repetition->targetdate = $piggyBank->targetdate;
|
||||
$repetition->currentamount = 0;
|
||||
$repetition->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Also delete related objects.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(PiggyBank $piggyBank): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a piggy bank.');
|
||||
|
||||
foreach ($piggyBank->attachments()->get() as $attachment) {
|
||||
$attachment->delete();
|
||||
}
|
||||
|
||||
$piggyBank->piggyBankEvents()->delete();
|
||||
$piggyBank->piggyBankRepetitions()->delete();
|
||||
|
||||
$piggyBank->notes()->delete();
|
||||
}
|
||||
|
||||
}
|
||||
52
app/Handlers/Observer/RecurrenceObserver.php
Normal file
52
app/Handlers/Observer/RecurrenceObserver.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/*
|
||||
* RecurrenceObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\Recurrence;
|
||||
|
||||
/**
|
||||
* Class RecurrenceObserver
|
||||
*/
|
||||
class RecurrenceObserver
|
||||
{
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(Recurrence $recurrence): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a recurrence.');
|
||||
foreach ($recurrence->attachments()->get() as $attachment) {
|
||||
$attachment->delete();
|
||||
}
|
||||
|
||||
$recurrence->recurrenceRepetitions()->delete();
|
||||
$recurrence->recurrenceMeta()->delete();
|
||||
foreach ($recurrence->recurrenceTransactions()->get() as $transaction) {
|
||||
$transaction->delete();
|
||||
}
|
||||
$recurrence->notes()->delete();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
42
app/Handlers/Observer/RecurrenceTransactionObserver.php
Normal file
42
app/Handlers/Observer/RecurrenceTransactionObserver.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* RecurrenceTransactionObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\RecurrenceTransaction;
|
||||
|
||||
/**
|
||||
* Class RecurrenceTransactionObserver
|
||||
*/
|
||||
class RecurrenceTransactionObserver
|
||||
{
|
||||
/**
|
||||
* @param RecurrenceTransaction $transaction
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(RecurrenceTransaction $transaction): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a recurrence transaction.');
|
||||
$transaction->recurrenceTransactionMeta()->delete();
|
||||
}
|
||||
|
||||
}
|
||||
45
app/Handlers/Observer/RuleGroupObserver.php
Normal file
45
app/Handlers/Observer/RuleGroupObserver.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
/*
|
||||
* RuleGroupObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
|
||||
/**
|
||||
* Class RuleGroupObserver
|
||||
*/
|
||||
class RuleGroupObserver
|
||||
{
|
||||
/**
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(RuleGroup $ruleGroup): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a rule group.');
|
||||
foreach ($ruleGroup->rules()->get() as $rule) {
|
||||
$rule->delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
43
app/Handlers/Observer/RuleObserver.php
Normal file
43
app/Handlers/Observer/RuleObserver.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*
|
||||
* RuleObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\Rule;
|
||||
|
||||
/**
|
||||
* Class RuleObserver
|
||||
*/
|
||||
class RuleObserver
|
||||
{
|
||||
/**
|
||||
* @param Rule $rule
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(Rule $rule): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a rule.');
|
||||
$rule->ruleActions()->delete();
|
||||
$rule->ruleTriggers()->delete();
|
||||
}
|
||||
|
||||
}
|
||||
48
app/Handlers/Observer/TagObserver.php
Normal file
48
app/Handlers/Observer/TagObserver.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/*
|
||||
* TagObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\Tag;
|
||||
|
||||
/**
|
||||
* Class TagObserver
|
||||
*/
|
||||
class TagObserver
|
||||
{
|
||||
/**
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(Tag $tag): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a tag.');
|
||||
|
||||
foreach ($tag->attachments()->get() as $attachment) {
|
||||
$attachment->delete();
|
||||
}
|
||||
|
||||
$tag->locations()->delete();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
39
app/Handlers/Observer/TransactionGroupObserver.php
Normal file
39
app/Handlers/Observer/TransactionGroupObserver.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/*
|
||||
* TransactionGroup.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
|
||||
/**
|
||||
* Class TransactionGroup
|
||||
*/
|
||||
class TransactionGroupObserver
|
||||
{
|
||||
public function deleting(TransactionGroup $transactionGroup): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a transaction group.');
|
||||
foreach ($transactionGroup->transactionJournals()->get() as $journal) {
|
||||
$journal->delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
55
app/Handlers/Observer/TransactionJournalObserver.php
Normal file
55
app/Handlers/Observer/TransactionJournalObserver.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/*
|
||||
* TransactionJournalObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
|
||||
/**
|
||||
* Class TransactionJournalObserver
|
||||
*/
|
||||
class TransactionJournalObserver
|
||||
{
|
||||
/**
|
||||
* @param TransactionJournal $transactionJournal
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(TransactionJournal $transactionJournal): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a transaction journal.');
|
||||
|
||||
// to make sure the listener doesn't get back to use and loop
|
||||
TransactionJournal::withoutEvents(function () use ($transactionJournal) {
|
||||
foreach ($transactionJournal->transactions()->get() as $transaction) {
|
||||
$transaction->delete();
|
||||
}
|
||||
});
|
||||
foreach ($transactionJournal->attachments()->get() as $attachment) {
|
||||
$attachment->delete();
|
||||
}
|
||||
$transactionJournal->locations()->delete();
|
||||
$transactionJournal->sourceJournalLinks()->delete();
|
||||
$transactionJournal->destJournalLinks()->delete();
|
||||
$transactionJournal->auditLogEntries()->delete();
|
||||
}
|
||||
|
||||
}
|
||||
37
app/Handlers/Observer/TransactionObserver.php
Normal file
37
app/Handlers/Observer/TransactionObserver.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/*
|
||||
* TransactionObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\Transaction;
|
||||
|
||||
/**
|
||||
* Class TransactionObserver
|
||||
*/
|
||||
class TransactionObserver
|
||||
{
|
||||
public function deleting(Transaction $transaction): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a transaction.');
|
||||
$transaction->transactionJournal->delete();
|
||||
}
|
||||
|
||||
}
|
||||
43
app/Handlers/Observer/WebhookMessageObserver.php
Normal file
43
app/Handlers/Observer/WebhookMessageObserver.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*
|
||||
* WebhookMessageObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\Webhook;
|
||||
use FireflyIII\Models\WebhookMessage;
|
||||
|
||||
/**
|
||||
* Class WebhookMessageObserver
|
||||
*/
|
||||
class WebhookMessageObserver
|
||||
{
|
||||
|
||||
/**
|
||||
* @param WebhookMessage $webhookMessage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(WebhookMessage $webhookMessage): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a webhook message.');
|
||||
$webhookMessage->webhookAttempts()->delete();
|
||||
}
|
||||
}
|
||||
44
app/Handlers/Observer/WebhookObserver.php
Normal file
44
app/Handlers/Observer/WebhookObserver.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
* WebhookObserver.php
|
||||
* Copyright (c) 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Handlers\Observer;
|
||||
|
||||
use FireflyIII\Models\Webhook;
|
||||
|
||||
/**
|
||||
* Class WebhookObserver
|
||||
*/
|
||||
class WebhookObserver
|
||||
{
|
||||
/**
|
||||
* @param Webhook $webhook
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleting(Webhook $webhook): void
|
||||
{
|
||||
app('log')->debug('Observe "deleting" of a webhook.');
|
||||
foreach ($webhook->webhookMessages() as $message) {
|
||||
$message->delete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user