adrema/app/Member/Actions/MemberDeleteAction.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2023-08-15 23:03:51 +02:00
<?php
namespace App\Member\Actions;
2023-10-16 15:41:37 +02:00
use App\Lib\JobMiddleware\JobChannels;
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
public function handle(int $memberId): void
2023-08-15 23:03:51 +02:00
{
$member = Member::findOrFail($memberId);
2023-08-15 23:03:51 +02:00
if ($member->nami_id) {
NamiDeleteMemberAction::run($member->nami_id);
2023-08-15 23:03:51 +02:00
}
$member->delete();
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-17 12:46:48 +02:00
* @param mixed $parameters
*/
2023-08-17 12:46:48 +02:00
public function jobState(WithJobState $jobState, ...$parameters): WithJobState
{
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.')
2023-10-16 15:41:37 +02:00
->shouldReload(JobChannels::make()->add('member'));
}
2023-08-15 23:03:51 +02:00
}