Ejemplo n.º 1
0
 /**
  * Publishes a given RoleDraft.
  *
  * @since 6.0
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to publish this RoleDraft
  * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the role draft cannot be loaded
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the role draft has no policies
  *
  * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
  */
 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;
     }
 }