. */ namespace SP\Modules\Web\Controllers\AuthToken; use Exception; use JsonException; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Http\Dtos\JsonMessage; /** * Class DeleteController * * @package SP\Modules\Web\Controllers */ final class DeleteController extends AuthTokenSaveBase { /** * Delete action * * @param int|null $id * * @return bool * @throws JsonException */ public function deleteAction(?int $id = null): bool { try { if (!$this->acl->checkUserAccess(AclActionsInterface::AUTHTOKEN_DELETE)) { return $this->returnJsonResponse( JsonMessage::JSON_ERROR, __u('You don\'t have permission to do this operation') ); } if ($id === null) { $this->authTokenService->deleteByIdBatch($this->getItemsIdFromRequest($this->request)); $this->deleteCustomFieldsForItem(AclActionsInterface::AUTHTOKEN, $id, $this->customFieldService); $this->eventDispatcher->notify( 'delete.authToken.selection', new Event($this, EventMessage::factory()->addDescription(__u('Authorizations deleted'))) ); return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Authorizations deleted')); } $this->authTokenService->delete($id); $this->deleteCustomFieldsForItem(AclActionsInterface::AUTHTOKEN, $id, $this->customFieldService); $this->eventDispatcher->notify( 'delete.authToken', new Event( $this, EventMessage::factory() ->addDescription(__u('Authorization deleted')) ->addDetail(__u('Authorization'), $id) ) ); return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Authorization deleted')); } catch (Exception $e) { processException($e); $this->eventDispatcher->notify('exception', new Event($e)); return $this->returnJsonResponseException($e); } } }