2023-08-15 23:03:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Member\Actions;
|
|
|
|
|
2023-08-16 00:43:28 +02:00
|
|
|
use App\Lib\JobMiddleware\WithJobState;
|
2023-08-17 12:46:48 +02:00
|
|
|
use App\Lib\Queue\TracksJob;
|
2023-08-15 23:03:51 +02:00
|
|
|
use App\Maildispatcher\Actions\ResyncAction;
|
|
|
|
use App\Member\Member;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
class MemberDeleteAction
|
|
|
|
{
|
|
|
|
|
|
|
|
use AsAction;
|
2023-08-17 12:46:48 +02:00
|
|
|
use TracksJob;
|
2023-08-15 23:03:51 +02:00
|
|
|
|
2023-08-16 00:43:28 +02:00
|
|
|
public function handle(int $memberId): void
|
2023-08-15 23:03:51 +02:00
|
|
|
{
|
2023-08-16 00:43:28 +02:00
|
|
|
$member = Member::findOrFail($memberId);
|
|
|
|
|
2023-08-15 23:03:51 +02:00
|
|
|
if ($member->nami_id) {
|
2023-08-16 00:43:28 +02:00
|
|
|
NamiDeleteMemberAction::run($member->nami_id);
|
2023-08-15 23:03:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$member->delete();
|
2023-08-16 00:43:28 +02:00
|
|
|
ResyncAction::run();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function asController(Member $member): RedirectResponse
|
|
|
|
{
|
2023-08-17 12:46:48 +02:00
|
|
|
$this->startJob($member->id);
|
2023-08-15 23:03:51 +02:00
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
2023-08-16 00:43:28 +02:00
|
|
|
|
|
|
|
/**
|
2023-08-17 12:46:48 +02:00
|
|
|
* @param mixed $parameters
|
2023-08-16 00:43:28 +02:00
|
|
|
*/
|
2023-08-17 12:46:48 +02:00
|
|
|
public function jobState(WithJobState $jobState, ...$parameters): WithJobState
|
2023-08-16 00:43:28 +02:00
|
|
|
{
|
2023-08-17 12:46:48 +02:00
|
|
|
$member = Member::findOrFail($parameters[0]);
|
|
|
|
|
|
|
|
return $jobState
|
|
|
|
->before('Mitglied ' . $member->fullname . ' wird gelöscht')
|
|
|
|
->after('Mitglied ' . $member->fullname . ' gelöscht')
|
|
|
|
->failed('Löschen von ' . $member->fullname . ' fehlgeschlagen.')
|
|
|
|
->shouldReload();
|
|
|
|
}
|
2023-08-16 00:43:28 +02:00
|
|
|
|
2023-08-17 12:46:48 +02:00
|
|
|
public function jobChannel(): string
|
|
|
|
{
|
|
|
|
return 'member';
|
2023-08-16 00:43:28 +02:00
|
|
|
}
|
2023-08-15 23:03:51 +02:00
|
|
|
}
|