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;
|
2023-07-30 11:08:17 +02:00
|
|
|
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-18 13:45:41 +02:00
|
|
|
public function handle(int $membershipId): void
|
2022-11-16 22:59:49 +01:00
|
|
|
{
|
2023-10-18 13:45:41 +02:00
|
|
|
$membership = Membership::find($membershipId);
|
2023-10-16 15:41:37 +02:00
|
|
|
$api = app(NamiSettings::class)->login();
|
2023-07-30 11:08:17 +02:00
|
|
|
|
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-18 13:45:41 +02:00
|
|
|
$this->startJob($membership->id, $membership->member->fullname);
|
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
|
|
|
|
{
|
2023-10-18 13:45:41 +02:00
|
|
|
$memberName = $parameters[1];
|
2023-10-16 15:41:37 +02:00
|
|
|
|
|
|
|
return $jobState
|
2023-10-18 13:45:41 +02:00
|
|
|
->before('Mitgliedschaft für ' . $memberName . ' wird gelöscht')
|
|
|
|
->after('Mitgliedschaft für ' . $memberName . ' gelöscht')
|
|
|
|
->failed('Fehler beim Löschen der Mitgliedschaft für ' . $memberName)
|
2023-10-16 15:41:37 +02:00
|
|
|
->shouldReload(JobChannels::make()->add('member')->add('membership'));
|
|
|
|
}
|
2022-11-16 22:59:49 +01:00
|
|
|
}
|