Akaunting/app/Jobs/Common/DeleteReport.php

72 lines
1.7 KiB
PHP
Raw Normal View History

2019-11-16 07:21:14 +00:00
<?php
namespace App\Jobs\Common;
use App\Abstracts\Job;
2021-09-06 08:53:57 +00:00
use App\Interfaces\Job\ShouldDelete;
2019-11-16 07:21:14 +00:00
2021-09-06 08:53:57 +00:00
class DeleteReport extends Job implements ShouldDelete
2019-11-16 07:21:14 +00:00
{
2021-09-06 08:53:57 +00:00
public function handle(): bool
2019-11-16 07:21:14 +00:00
{
2020-06-26 10:40:19 +00:00
\DB::transaction(function () {
2023-12-08 12:43:59 +00:00
$this->deleteFavorite();
2023-12-08 12:44:27 +00:00
$this->deletePin();
2023-12-08 12:43:59 +00:00
2021-09-06 08:53:57 +00:00
$this->model->delete();
2020-06-26 10:40:19 +00:00
});
2019-11-16 07:21:14 +00:00
return true;
}
2023-12-08 12:43:59 +00:00
public function deleteFavorite()
{
$favorites = setting('favorites.menu', []);
if (empty($favorites)) {
return;
}
foreach ($favorites as $user_id => $user_favorites) {
$user_favorites = json_decode($user_favorites, true);
foreach ($user_favorites as $key => $favorite) {
if (! is_array($favorite['route'])) {
continue;
}
if (str_contains($favorite['route'][0], 'reports.show') && $this->model->id == $favorite['route'][1]) {
unset($user_favorites[$key]);
}
}
setting()->set('favorites.menu.' . $user_id, json_encode($user_favorites));
setting()->save();
}
}
2023-12-08 12:44:27 +00:00
public function deletePin()
{
$pins = setting('favorites.report', []);
if (empty($pins)) {
return;
}
foreach ($pins as $user_id => $user_pins) {
$user_pins = json_decode($user_pins, true);
foreach ($user_pins as $key => $pin) {
if ($this->model->id == $pin) {
unset($user_pins[$key]);
break;
}
}
setting()->set('favorites.report.' . $user_id, json_encode($user_pins));
setting()->save();
}
}
2019-11-16 07:21:14 +00:00
}