Files
firefly-iii/app/Services/Internal/Destroy/RecurrenceDestroyService.php

85 lines
2.3 KiB
PHP
Raw Normal View History

<?php
/**
* RecurrenceDestroyService.php
2020-02-16 13:56:35 +01:00
* Copyright (c) 2019 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\Services\Internal\Destroy;
use Exception;
use FireflyIII\Models\Recurrence;
2018-06-29 19:27:07 +02:00
use FireflyIII\Models\RecurrenceTransaction;
/**
* @codeCoverageIgnore
* Class RecurrenceDestroyService
*/
class RecurrenceDestroyService
{
2021-03-15 10:31:11 +01:00
/**
* Delete recurrence by ID
*
* @param int $recurrenceId
*/
public function destroyById(int $recurrenceId): void
{
$recurrence = Recurrence::find($recurrenceId);
if (null === $recurrence) {
return;
}
$this->destroy($recurrence);
}
/**
2018-07-28 06:27:30 +02:00
* Delete recurrence.
*
* @param Recurrence $recurrence
2019-08-17 10:47:29 +02:00
*
*/
public function destroy(Recurrence $recurrence): void
{
try {
2018-06-29 19:27:07 +02:00
// delete all meta data
$recurrence->recurrenceMeta()->delete();
2022-10-31 05:53:36 +01:00
} catch (Exception $e) {
2021-04-06 18:48:02 +02:00
// @ignoreException
2018-07-26 06:27:52 +02:00
}
// delete all transactions.
/** @var RecurrenceTransaction $transaction */
foreach ($recurrence->recurrenceTransactions as $transaction) {
$transaction->recurrenceTransactionMeta()->delete();
try {
2018-06-29 19:27:07 +02:00
$transaction->delete();
2022-10-31 05:53:36 +01:00
} catch (Exception $e) {
2021-04-06 18:48:02 +02:00
// @ignoreException
2018-06-29 19:27:07 +02:00
}
2018-07-26 06:27:52 +02:00
}
// delete all repetitions
$recurrence->recurrenceRepetitions()->delete();
2018-06-29 19:27:07 +02:00
2018-07-26 06:27:52 +02:00
// delete recurrence
try {
$recurrence->delete();
2022-10-31 05:53:36 +01:00
} catch (Exception $e) {
2021-04-06 18:48:02 +02:00
// @ignoreException
}
}
}