adrema/app/Membership/Actions/MembershipDestroyAction.php

60 lines
1.6 KiB
PHP
Raw Normal View History

2022-11-16 22:59:49 +01:00
<?php
namespace App\Membership\Actions;
2023-10-16 15:41:37 +02:00
use App\Lib\JobMiddleware\JobChannels;
use App\Lib\JobMiddleware\WithJobState;
use App\Lib\Queue\TracksJob;
use App\Maildispatcher\Actions\ResyncAction;
2022-11-16 22:59:49 +01:00
use App\Member\Membership;
use App\Setting\NamiSettings;
2023-09-12 16:54:13 +02:00
use Illuminate\Http\JsonResponse;
2022-11-16 22:59:49 +01:00
use Lorisleiva\Actions\Concerns\AsAction;
class MembershipDestroyAction
{
use AsAction;
2023-10-16 15:41:37 +02:00
use TracksJob;
2022-11-16 22:59:49 +01:00
2023-10-16 15:41:37 +02:00
public function handle(Membership $membership): void
2022-11-16 22:59:49 +01:00
{
2023-10-16 15:41:37 +02:00
$api = app(NamiSettings::class)->login();
2023-02-17 11:43:08 +01:00
if ($membership->hasNami) {
2023-10-16 15:41:37 +02:00
$api->deleteMembership(
$membership->member->nami_id,
$api->membership($membership->member->nami_id, $membership->nami_id)
2023-02-17 11:43:08 +01:00
);
}
2022-11-16 22:59:49 +01:00
$membership->delete();
2023-02-17 11:43:08 +01:00
if ($membership->hasNami) {
2023-10-16 15:41:37 +02:00
$membership->member->syncVersion();
2023-02-17 11:43:08 +01:00
}
2023-10-16 15:41:37 +02:00
ResyncAction::dispatch();
2022-11-16 22:59:49 +01:00
}
2023-10-16 15:41:37 +02:00
public function asController(Membership $membership): JsonResponse
2022-11-16 22:59:49 +01:00
{
2023-10-16 15:41:37 +02:00
$this->startJob($membership);
2022-11-16 22:59:49 +01:00
2023-09-12 16:54:13 +02:00
return response()->json([]);
2022-11-16 22:59:49 +01:00
}
2023-10-16 15:41:37 +02:00
/**
* @param mixed $parameters
*/
public function jobState(WithJobState $jobState, ...$parameters): WithJobState
{
$member = $parameters[0]->member;
return $jobState
->before('Mitgliedschaft für ' . $member->fullname . ' wird gelöscht')
->after('Mitgliedschaft für ' . $member->fullname . ' gelöscht')
->failed('Fehler beim Löschen der Mitgliedschaft für ' . $member->fullname)
->shouldReload(JobChannels::make()->add('member')->add('membership'));
}
2022-11-16 22:59:49 +01:00
}