public function createRoleDraft(APIRole $role)
{
if ($this->repository->hasAccess('role', 'create') !== true) {
throw new UnauthorizedException('role', 'create');
}
try {
$this->userHandler->loadRole($role->id, Role::STATUS_DRAFT);
// Throw exception, so platformui et al can do conflict management. Follow-up: EZP-24719
throw new InvalidArgumentException('$role', "Cannot create a draft for role '{$role->identifier}' because another draft exists");
} catch (APINotFoundException $e) {
$this->repository->beginTransaction();
try {
$spiRole = $this->userHandler->createRoleDraft($role->id);
$this->repository->commit();
} catch (Exception $e) {
$this->repository->rollback();
throw $e;
}
}
return $this->roleDomainMapper->buildDomainRoleDraftObject($spiRole);
}