public function publishRoleDraft(APIRoleDraft $roleDraft)
{
if ($this->repository->hasAccess('role', 'update') !== true) {
throw new UnauthorizedException('role', 'update');
}
try {
$loadedRoleDraft = $this->loadRoleDraft($roleDraft->id);
} catch (APINotFoundException $e) {
throw new BadStateException('$roleDraft', 'The role does not have a draft.', $e);
}
// TODO: Uncomment when role policy editing is done, see EZP-24711 & EZP-24713
/*if (count($loadedRoleDraft->getPolicies()) === 0) {
throw new InvalidArgumentException(
"\$roleDraft",
'The role draft should have at least one policy.'
);
}*/
$this->repository->beginTransaction();
try {
$this->userHandler->publishRoleDraft($loadedRoleDraft->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}