コード例 #1
0
 public function processUpdatePolicy(FormActionEvent $event)
 {
     // Don't update anything if we just want to cancel the draft.
     if ($event->getClickedButton() === 'removeDraft') {
         return;
     }
     /** @var \EzSystems\RepositoryForms\Data\Role\PolicyCreateData|\EzSystems\RepositoryForms\Data\Role\PolicyUpdateData $data */
     $data = $event->getData();
     if ($data->isNew() && $data->moduleFunction) {
         list($module, $function) = explode('|', $data->moduleFunction);
         $data->module = $module;
         $data->function = $function;
         $initialRoleDraft = $data->roleDraft;
         $updatedRoleDraft = $this->roleService->addPolicyByRoleDraft($initialRoleDraft, $data);
         $initialPoliciesById = $this->getPoliciesById($initialRoleDraft);
         $updatedPoliciesById = $this->getPoliciesById($updatedRoleDraft);
         foreach ($updatedPoliciesById as $policyId => $policyDraft) {
             if (!isset($initialPoliciesById[$policyId])) {
                 $data->setPolicyDraft($policyDraft);
                 break;
             }
         }
     } else {
         // Only save limitations on update.
         // It is not possible by design to update policy module/function.
         foreach ($data->limitationsData as $limitation) {
             // Add posted limitations as valid ones, recognized by RoleService.
             if (!empty($limitation->limitationValues)) {
                 $data->addLimitation($limitation);
             }
         }
         $this->roleService->updatePolicyByRoleDraft($data->roleDraft, $data->policyDraft, $data);
     }
 }
コード例 #2
0
ファイル: RoleService.php プロジェクト: Pixy/ezpublish-kernel
 /**
  * Updates the limitations of a policy. The module and function cannot be changed and
  * the limitations are replaced by the ones in $roleUpdateStruct.
  *
  * @since 6.0
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a policy
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy update
  *                                                                        struct or if limitation is not allowed on module/function
  * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyUpdateStruct is not valid
  *
  * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
  * @param \eZ\Publish\API\Repository\Values\User\PolicyDraft $policy
  * @param \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct $policyUpdateStruct
  *
  * @return \eZ\Publish\API\Repository\Values\User\PolicyDraft
  */
 public function updatePolicyByRoleDraft(RoleDraft $roleDraft, PolicyDraft $policy, PolicyUpdateStruct $policyUpdateStruct)
 {
     $returnValue = $this->service->updatePolicyByRoleDraft($roleDraft, $policy, $policyUpdateStruct);
     $this->signalDispatcher->emit(new UpdatePolicySignal(array('policyId' => $policy->id)));
     return $returnValue;
 }