2022-11-16 22:59:49 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Membership\Actions;
|
|
|
|
|
2023-07-30 11:08:17 +02:00
|
|
|
use App\Maildispatcher\Actions\ResyncAction;
|
2022-11-16 22:59:49 +01:00
|
|
|
use App\Member\Member;
|
|
|
|
use App\Member\Membership;
|
|
|
|
use App\Setting\NamiSettings;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Lorisleiva\Actions\ActionRequest;
|
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
|
|
|
|
|
|
class MembershipDestroyAction
|
|
|
|
{
|
|
|
|
use AsAction;
|
|
|
|
|
|
|
|
public function handle(Member $member, Membership $membership, NamiSettings $settings): void
|
|
|
|
{
|
|
|
|
$api = $settings->login();
|
2023-07-30 11:08:17 +02:00
|
|
|
|
2023-02-17 11:43:08 +01:00
|
|
|
if ($membership->hasNami) {
|
|
|
|
$settings->login()->deleteMembership(
|
|
|
|
$member->nami_id,
|
|
|
|
$api->membership($member->nami_id, $membership->nami_id)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-16 22:59:49 +01:00
|
|
|
$membership->delete();
|
2023-02-17 11:43:08 +01:00
|
|
|
|
|
|
|
if ($membership->hasNami) {
|
|
|
|
$member->syncVersion();
|
|
|
|
}
|
2022-11-16 22:59:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function asController(Member $member, Membership $membership, ActionRequest $request, NamiSettings $settings): RedirectResponse
|
|
|
|
{
|
|
|
|
$this->handle(
|
|
|
|
$member,
|
|
|
|
$membership,
|
|
|
|
$settings,
|
|
|
|
);
|
|
|
|
|
2023-07-30 11:08:17 +02:00
|
|
|
ResyncAction::dispatch();
|
|
|
|
|
2022-11-16 22:59:49 +01:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
}
|