/** * Updates an existing user role object. * * @action update * @param int $userRoleId The user role's unique identifier * @param KalturaUserRole $userRole The user role's unique identifier * @return KalturaUserRole The updated user role object * * @throws KalturaErrors::INVALID_OBJECT_ID * @throws KalturaErrors::PERMISSION_NOT_FOUND */ public function updateAction($userRoleId, KalturaUserRole $userRole) { /* critera is used here instead of retrieveByPk on purpose! if the current context is assigned to a partner 0 role, then retrieveByPk will return it from cache even though partner 0 is not in the partner group for the current action and context */ $c = new Criteria(); $c->addAnd(UserRolePeer::ID, $userRoleId, Criteria::EQUAL); if ($this->partnerGroup() != myPartnerUtils::ALL_PARTNERS_WILD_CHAR) { $c->addAnd(UserRolePeer::PARTNER_ID, explode(',', $this->partnerGroup()), Criteria::IN); } $dbUserRole = UserRolePeer::doSelectOne($c); if (!$dbUserRole) { throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $userRoleId); } // cannot update name to a name that already exists if ($userRole->name && $userRole->name != $dbUserRole->getName()) { if (UserRolePeer::getByNameAndPartnerId($userRole->name, $this->getPartnerId())) { throw new KalturaAPIException(KalturaErrors::ROLE_NAME_ALREADY_EXISTS); } } if (!is_null($userRole->permissionNames) && !$userRole->permissionNames instanceof KalturaNullField) { try { PermissionPeer::checkValidPermissionsForRole($userRole->permissionNames, $this->getPartnerId()); } catch (kPermissionException $e) { $code = $e->getCode(); if ($code == kPermissionException::PERMISSION_NOT_FOUND) { throw new KalturaAPIException(KalturaErrors::PERMISSION_NOT_FOUND, $e->getMessage()); } } } $dbUserRole = $userRole->toUpdatableObject($dbUserRole); $dbUserRole->save(); $userRole = new KalturaUserRole(); $userRole->fromObject($dbUserRole, $this->getResponseProfile()); return $userRole; }