public static function setDefaultCriteriaFilter()
 {
     if (self::$s_criteria_filter == null) {
         self::$s_criteria_filter = new criteriaFilter();
     }
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $partnerId = kCurrentContext::$ks_partner_id ? kCurrentContext::$ks_partner_id : kCurrentContext::$partner_id;
     if ($partnerId != Partner::BATCH_PARTNER_ID) {
         $c->add(self::STATUS, array(CategoryStatus::DELETED, CategoryStatus::PURGED), Criteria::NOT_IN);
     } else {
         $c->add(self::STATUS, CategoryStatus::PURGED, Criteria::NOT_EQUAL);
     }
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         //add context as filter
         $privacyContextCrit = $c->getNewCriterion(self::PRIVACY_CONTEXTS, kEntitlementUtils::getKsPrivacyContext(), KalturaCriteria::IN_LIKE);
         $privacyContextCrit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $c->addAnd($privacyContextCrit);
         $crit = $c->getNewCriterion(self::DISPLAY_IN_SEARCH, DisplayInSearchType::PARTNER_ONLY, Criteria::EQUAL);
         $crit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $kuser = null;
         $ksString = kCurrentContext::$ks ? kCurrentContext::$ks : '';
         if ($ksString != '') {
             $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
             $kuser = kuserPeer::getActiveKuserByPartnerAndUid($partnerId, kCurrentContext::$ks_uid);
         }
         if ($kuser) {
             $membersCrit = $c->getNewCriterion(self::MEMBERS, $kuser->getId(), Criteria::LIKE);
             $membersCrit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
             $crit->addOr($membersCrit);
         }
         $c->addAnd($crit);
     }
     self::$s_criteria_filter->setFilter($c);
 }
Exemplo n.º 2
0
 public function validateForResponseProfile()
 {
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_ENABLE_RESPONSE_PROFILE_USER_CACHE, kCurrentContext::getCurrentPartnerId())) {
             KalturaResponseProfileCacher::useUserCache();
             return;
         }
         throw new KalturaAPIException(KalturaErrors::CANNOT_LIST_RELATED_ENTITLED_WHEN_ENTITLEMENT_IS_ENABLE, get_class($this));
     }
 }
Exemplo n.º 3
0
 /**
  * Creates default criteria filter
  */
 public static function setDefaultCriteriaFilter()
 {
     if (self::$s_criteria_filter == null) {
         self::$s_criteria_filter = new criteriaFilter();
     }
     $c = KalturaCriteria::create(self::OM_CLASS);
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         $privacyContexts = kEntitlementUtils::getKsPrivacyContextArray();
         $c->addAnd(self::PRIVACY_CONTEXT, $privacyContexts, Criteria::IN);
     }
     $c->addAnd(self::INSTANCE_COUNT, 0, Criteria::GREATER_THAN);
     self::$s_criteria_filter->setFilter($c);
 }
Exemplo n.º 4
0
 public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if (kEntitlementUtils::getEntitlementEnforcement() && (is_null($this->objectIdIn) && is_null($this->objectIdEqual))) {
         throw new KalturaAPIException(MetadataErrors::MUST_FILTER_ON_OBJECT_ID);
     }
     if (!$this->metadataObjectTypeEqual) {
         throw new KalturaAPIException(MetadataErrors::MUST_FILTER_ON_OBJECT_TYPE);
     }
     if ($this->metadataObjectTypeEqual == MetadataObjectType::CATEGORY) {
         if ($this->objectIdEqual) {
             $categoryIds = array($this->objectIdEqual);
         } else {
             if ($this->objectIdIn) {
                 $categoryIds = explode(',', $this->objectIdIn);
             }
         }
         if ($categoryIds) {
             $categories = categoryPeer::retrieveByPKs($categoryIds);
             if (!count($categories)) {
                 KalturaLog::debug("No categories found");
                 $response = new KalturaMetadataListResponse();
                 $response->objects = new KalturaMetadataArray();
                 $response->totalCount = 0;
                 return $response;
             }
             $categoryIds = array();
             foreach ($categories as $category) {
                 $categoryIds[] = $category->getId();
             }
             $this->objectIdEqual = null;
             $this->objectIdIn = implode(',', $categoryIds);
         }
     }
     $metadataFilter = $this->toObject();
     $c = KalturaCriteria::create(MetadataPeer::OM_CLASS);
     $metadataFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $list = MetadataPeer::doSelect($c);
     $response = new KalturaMetadataListResponse();
     $response->objects = KalturaMetadataArray::fromDbArray($list, $responseProfile);
     if ($c instanceof SphinxMetadataCriteria) {
         $response->totalCount = $c->getRecordsCount();
     } elseif ($pager->pageIndex == 1 && count($response->objects) < $pager->pageSize) {
         $response->totalCount = count($response->objects);
     } else {
         $pager->detachFromCriteria($c);
         $response->totalCount = MetadataPeer::doCount($c);
     }
     return $response;
 }
 private static function getObjectSpecificCacheKey(IBaseObject $object, $responseProfileKey)
 {
     $userRoles = kPermissionManager::getCurrentRoleIds();
     sort($userRoles);
     $objectType = get_class($object);
     $objectId = $object->getPrimaryKey();
     $partnerId = $object->getPartnerId();
     $profileKey = $responseProfileKey;
     $protocol = infraRequestUtils::getProtocol();
     $ksType = kCurrentContext::getCurrentSessionType();
     $userRoles = implode('-', $userRoles);
     $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
     $entitlement = (int) kEntitlementUtils::getEntitlementEnforcement();
     return "obj_rp{$profileKey}_p{$partnerId}_o{$objectType}_i{$objectId}_h{$protocol}_k{$ksType}_u{$userRoles}_w{$host}_e{$entitlement}";
 }
Exemplo n.º 6
0
 public static function setDefaultCriteriaFilter()
 {
     if (self::$s_criteria_filter == null) {
         self::$s_criteria_filter = new criteriaFilter();
     }
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $partnerId = kCurrentContext::$ks_partner_id ? kCurrentContext::$ks_partner_id : kCurrentContext::$partner_id;
     if ($partnerId != Partner::BATCH_PARTNER_ID || self::$ignoreDeleted) {
         $c->add(self::STATUS, array(CategoryStatus::DELETED, CategoryStatus::PURGED), Criteria::NOT_IN);
     } else {
         $c->add(self::STATUS, CategoryStatus::PURGED, Criteria::NOT_EQUAL);
     }
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         //add context as filter
         $privacyContextCrit = $c->getNewCriterion(self::PRIVACY_CONTEXTS, kEntitlementUtils::getKsPrivacyContext(), KalturaCriteria::IN_LIKE);
         $privacyContextCrit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $c->addAnd($privacyContextCrit);
         $crit = $c->getNewCriterion(self::DISPLAY_IN_SEARCH, DisplayInSearchType::PARTNER_ONLY, Criteria::EQUAL);
         $crit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $kuser = null;
         $ksString = kCurrentContext::$ks ? kCurrentContext::$ks : '';
         if ($ksString != '') {
             $kuser = kCurrentContext::getCurrentKsKuser();
         }
         if ($kuser) {
             // get the groups that the user belongs to in case she is not associated to the category directly
             $kgroupIds = KuserKgroupPeer::retrieveKgroupIdsByKuserId($kuser->getId());
             $kgroupIds[] = $kuser->getId();
             $membersCrit = $c->getNewCriterion(self::MEMBERS, $kgroupIds, KalturaCriteria::IN_LIKE);
             $membersCrit->addTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
             $crit->addOr($membersCrit);
         }
         $c->addAnd($crit);
     }
     self::$s_criteria_filter->setFilter($c);
 }
Exemplo n.º 7
0
 /**
  * Override in order to filter objects returned from doSelect.
  *
  * @param      array $selectResults The array of objects to filter.
  * @param	   Criteria $criteria
  */
 public static function filterSelectResults(&$selectResults, Criteria $criteria)
 {
     if (empty($selectResults)) {
         return;
     }
     $partnerId = kCurrentContext::getCurrentPartnerId();
     $partner = PartnerPeer::retrieveByPK($partnerId);
     if ($partner && $partner->getShouldApplyAccessControlOnEntryMetadata() && !kCurrentContext::$is_admin_session) {
         if (is_null(self::$accessControlScope)) {
             self::$accessControlScope = new accessControlScope();
             self::$accessControlScope->setContexts(array(ContextType::METADATA));
         }
         $selectResults = array_filter($selectResults, array('entryPeer', 'filterByAccessControl'));
         if ($criteria instanceof KalturaCriteria) {
             $criteria->setRecordsCount(count($selectResults));
         }
     }
     $removedRecordsCount = 0;
     if (!kEntitlementUtils::getEntitlementEnforcement() && !is_null(kCurrentContext::$ks) || !self::$filerResults || !kEntitlementUtils::getInitialized()) {
         // if initEntitlement hasn't run - skip filters.
         return parent::filterSelectResults($selectResults, $criteria);
     }
     if (is_null(kCurrentContext::$ks) && count($selectResults)) {
         $entry = $selectResults[0];
         $partner = $entry->getPartner();
         if (!$partner) {
             throw new kCoreException('entry partner not found');
         }
         if (!$partner->getDefaultEntitlementEnforcement() || !PermissionPeer::isValidForPartner(PermissionName::FEATURE_ENTITLEMENT, $partner->getId())) {
             return parent::filterSelectResults($selectResults, $criteria);
         }
     }
     foreach ($selectResults as $key => $entry) {
         if (!kEntitlementUtils::isEntryEntitled($entry)) {
             unset($selectResults[$key]);
             $removedRecordsCount++;
         }
     }
     if ($criteria instanceof KalturaCriteria) {
         $recordsCount = $criteria->getRecordsCount();
         $criteria->setRecordsCount($recordsCount - $removedRecordsCount);
     }
     self::$filerResults = false;
     parent::filterSelectResults($selectResults, $criteria);
 }
Exemplo n.º 8
0
 /**
  * validate category fields
  * 1. category that inherit memebers cannot set values to inherited fields.
  * 2. validate the owner id exists as kuser
  * 
  * @param category $sourceObject
  */
 private function validateCategory(category $sourceObject = null)
 {
     if ($this->privacyContext != null && kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_PRIVACY_CONTEXT);
     }
     if (!$this->privacyContext && (!$sourceObject || !$sourceObject->getPrivacyContexts())) {
         $isInheritedPrivacyContext = true;
         if ($this->parentId != null) {
             $parentCategory = categoryPeer::retrieveByPK($this->parentId);
             if (!$parentCategory) {
                 throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->parentId);
             }
             if ($parentCategory->getPrivacyContexts() == '') {
                 $isInheritedPrivacyContext = false;
             }
         } else {
             $isInheritedPrivacyContext = false;
         }
         if (!$isInheritedPrivacyContext) {
             if ($this->appearInList != KalturaAppearInListType::PARTNER_ONLY && !$this->isNull('appearInList')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_APPEAR_IN_LIST_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if ($this->inheritanceType != KalturaInheritanceType::MANUAL && !$this->isNull('inheritanceType')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_INHERITANCE_TYPE_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if ($this->privacy != KalturaPrivacyType::ALL && !$this->isNull('privacy')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_PRIVACY_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if (!$this->isNull('owner')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if ($this->userJoinPolicy != KalturaUserJoinPolicyType::NOT_ALLOWED && !$this->isNull('userJoinPolicy')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_USER_JOIN_POLICY_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if ($this->contributionPolicy != KalturaContributionPolicyType::ALL && !$this->isNull('contributionPolicy')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_CONTIRUBUTION_POLICY_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
             if ($this->defaultPermissionLevel != KalturaCategoryUserPermissionLevel::MEMBER && !$this->isNull('defaultPermissionLevel')) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_DEFAULT_PERMISSION_LEVEL_FIELD_WITH_NO_PRIVACY_CONTEXT);
             }
         }
     }
     if ($this->inheritanceType != KalturaInheritanceType::MANUAL && $this->inheritanceType != null || $this->inheritanceType == null && $sourceObject && $sourceObject->getInheritanceType() != KalturaInheritanceType::MANUAL) {
         if ($this->owner != null) {
             if (!$sourceObject) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_WHEN_CATEGORY_INHERIT_MEMBERS);
             } elseif ($this->owner != $sourceObject->getKuserId()) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_WHEN_CATEGORY_INHERIT_MEMBERS);
             }
         }
         if ($this->userJoinPolicy != null) {
             if (!$sourceObject) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_USER_JOIN_POLICY_WHEN_CATEGORY_INHERIT_MEMBERS);
             } elseif ($this->userJoinPolicy != $sourceObject->getUserJoinPolicy()) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_USER_JOIN_POLICY_WHEN_CATEGORY_INHERIT_MEMBERS);
             }
         }
         if ($this->defaultPermissionLevel != null) {
             if (!$sourceObject) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_DEFAULT_PERMISSION_LEVEL_WHEN_CATEGORY_INHERIT_MEMBERS);
             } elseif ($this->defaultPermissionLevel != $sourceObject->getDefaultPermissionLevel()) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_SET_DEFAULT_PERMISSION_LEVEL_WHEN_CATEGORY_INHERIT_MEMBERS);
             }
         }
     }
     if (!is_null($sourceObject)) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $partner = PartnerPeer::retrieveByPK($partnerId);
         if (!$partner || $partner->getFeaturesStatusByType(IndexObjectType::LOCK_CATEGORY)) {
             throw new KalturaAPIException(KalturaErrors::CATEGORIES_LOCKED);
         }
     }
     if ($this->owner && $this->owner != '' && !$this->owner instanceof KalturaNullField) {
         if (!preg_match(kuser::PUSER_ID_REGEXP, $this->owner)) {
             throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_FIELD_WITH_USER_ID, $this->owner);
         }
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         kuserPeer::createKuserForPartner($partnerId, $this->owner);
     }
 }
Exemplo n.º 9
0
 /**
  * Index CategoryUser by userid and category id
  * 
  * @action index
  * @param string $userId
  * @param int $categoryId
  * @param bool $shouldUpdate
  * @throws KalturaErrors::INVALID_CATEGORY_USER_ID
  * @return int
  */
 public function indexAction($userId, $categoryId, $shouldUpdate = true)
 {
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_INDEX_OBJECT_WHEN_ENTITLEMENT_IS_ENABLE);
     }
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $kuser = kuserPeer::getActiveKuserByPartnerAndUid($partnerId, $userId);
     if (!$kuser) {
         throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
     }
     $dbCategoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($categoryId, $kuser->getId(), null, false);
     if (!$dbCategoryKuser) {
         throw new KalturaAPIException(KalturaErrors::INVALID_CATEGORY_USER_ID);
     }
     if (!$shouldUpdate) {
         $dbCategoryKuser->setUpdatedAt(time());
         $dbCategoryKuser->save();
         return $dbCategoryKuser->getId();
     }
     $dbCategoryKuser->reSetCategoryFullIds();
     $dbCategoryKuser->reSetScreenName();
     $dbCategoryKuser->save();
     return $dbCategoryKuser->getId();
 }
Exemplo n.º 10
0
 /**
  * Index metadata by id, will also index the related object
  *
  * @action index
  * @param string $id
  * @param bool $shouldUpdate
  * @return int
  */
 function indexAction($id, $shouldUpdate)
 {
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_INDEX_OBJECT_WHEN_ENTITLEMENT_IS_ENABLE);
     }
     $dbMetadata = MetadataPeer::retrieveByPK($id);
     if (!$dbMetadata) {
         throw new KalturaAPIException(MetadataErrors::METADATA_NOT_FOUND, $id);
     }
     $dbMetadata->indexToSearchIndex();
     $relatedObject = kMetadataManager::getObjectFromPeer($dbMetadata);
     if ($relatedObject && $relatedObject instanceof IIndexable) {
         $relatedObject->indexToSearchIndex();
     }
     return $dbMetadata->getId();
 }
Exemplo n.º 11
0
 public function validateForUpdate($sourceObject, $propertiesToSkip = null)
 {
     /* @var $sourceObject categoryKuser */
     $category = categoryPeer::retrieveByPK($sourceObject->getCategoryId());
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $sourceObject->getCategoryId());
     }
     if ($this->permissionNames && $this->permissionNames != $sourceObject->getPermissionNames()) {
         if ($sourceObject->getKuserId() == $category->getKuserId()) {
             if (strpos($this->permissionNames, PermissionName::CATEGORY_EDIT) === false) {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_USER_OWNER);
             }
         }
     }
     $currentKuserCategoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($sourceObject->getCategoryId(), kCurrentContext::getCurrentKsKuserId());
     if (kEntitlementUtils::getEntitlementEnforcement() && (!$currentKuserCategoryKuser || !$currentKuserCategoryKuser->hasPermission(PermissionName::CATEGORY_EDIT))) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_USER, $sourceObject->getCategoryId());
     }
     return parent::validateForUpdate($sourceObject, $propertiesToSkip);
 }
Exemplo n.º 12
0
 /**
  * Move categories that belong to the same parent category to a target categroy - enabled only for ks with disable entitlement
  * 
  * @action move
  * @param string $categoryIds
  * @param int $targetCategoryParentId
  * @return KalturaCategoryListResponse
  */
 function moveAction($categoryIds, $targetCategoryParentId)
 {
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_MOVE_CATEGORIES_FROM_DIFFERENT_PARENT_CATEGORY);
     }
     if ($this->getPartner()->getFeaturesStatusByType(IndexObjectType::LOCK_CATEGORY)) {
         throw new KalturaAPIException(KalturaErrors::CATEGORIES_LOCKED);
     }
     $categories = explode(',', $categoryIds);
     $dbCategories = array();
     $parentId = category::CATEGORY_ID_THAT_DOES_NOT_EXIST;
     foreach ($categories as $categoryId) {
         if ($categoryId == '') {
             continue;
         }
         $dbCategory = categoryPeer::retrieveByPK($categoryId);
         if (!$dbCategory) {
             throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryId);
         }
         if ($parentId == category::CATEGORY_ID_THAT_DOES_NOT_EXIST) {
             $parentId = $dbCategory->getParentId();
         }
         if ($parentId != $dbCategory->getParentId()) {
             throw new KalturaAPIException(KalturaErrors::CANNOT_MOVE_CATEGORIES_FROM_DIFFERENT_PARENT_CATEGORY);
         }
         $dbCategories[] = $dbCategory;
     }
     // if $targetCategoryParentId = 0 - it means that categories should be with no parent category
     if ($targetCategoryParentId != 0) {
         $dbTargetCategory = categoryPeer::retrieveByPK($targetCategoryParentId);
         if (!$dbTargetCategory) {
             throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $targetCategoryParentId);
         }
     }
     foreach ($dbCategories as $dbCategory) {
         $dbCategory->setParentId($targetCategoryParentId);
         $dbCategory->save();
     }
 }
 public function validateForInsert($propertiesToSkip = array())
 {
     $category = categoryPeer::retrieveByPK($this->categoryId);
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryId);
     }
     if ($category->getInheritanceType() == InheritanceType::INHERIT) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_INHERIT_MEMBERS, $this->categoryId);
     }
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $this->userId);
     if ($kuser) {
         $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndKuserId($this->categoryId, $kuser->getId());
         if ($categoryKuser) {
             throw new KalturaAPIException(KalturaErrors::CATEGORY_USER_ALREADY_EXISTS);
         }
     }
     $currentKuserCategoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($this->categoryId, kCurrentContext::$ks_kuser_id);
     if ((!$currentKuserCategoryKuser || $currentKuserCategoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER) && $category->getUserJoinPolicy() == UserJoinPolicyType::NOT_ALLOWED && kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_USER_JOIN_NOT_ALLOWED, $this->categoryId);
     }
     //if user doesn't exists - create it
     $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
     $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $this->userId);
     if (!$kuser) {
         if (!preg_match(kuser::PUSER_ID_REGEXP, $this->userId)) {
             throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'userId');
         }
         kuserPeer::createKuserForPartner($partnerId, $this->userId);
     }
     return parent::validateForInsert($propertiesToSkip);
 }
Exemplo n.º 14
0
 public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if ($this->entryIdEqual == null && $this->categoryIdIn == null && $this->categoryIdEqual == null && (kEntitlementUtils::getEntitlementEnforcement() || !kCurrentContext::$is_admin_session)) {
         throw new KalturaAPIException(KalturaErrors::MUST_FILTER_ON_ENTRY_OR_CATEGORY);
     }
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         //validate entitl for entry
         if ($this->entryIdEqual != null) {
             $entry = entryPeer::retrieveByPK($this->entryIdEqual);
             if (!$entry) {
                 throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $this->entryIdEqual);
             }
         }
         //validate entitl for entryIn
         if ($this->entryIdIn != null) {
             $entry = entryPeer::retrieveByPKs($this->entryIdIn);
             if (!$entry) {
                 throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $this->entryIdIn);
             }
         }
         //validate entitl categories
         if ($this->categoryIdIn != null) {
             $categoryIdInArr = explode(',', $this->categoryIdIn);
             if (!categoryKuserPeer::areCategoriesAllowed($categoryIdInArr)) {
                 $categoryIdInArr = array_unique($categoryIdInArr);
             }
             $entitledCategories = categoryPeer::retrieveByPKs($categoryIdInArr);
             if (!count($entitledCategories) || count($entitledCategories) != count($categoryIdInArr)) {
                 throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdIn);
             }
             $categoriesIdsUnlisted = array();
             foreach ($entitledCategories as $category) {
                 if ($category->getDisplayInSearch() == DisplayInSearchType::CATEGORY_MEMBERS_ONLY) {
                     $categoriesIdsUnlisted[] = $category->getId();
                 }
             }
             if (count($categoriesIdsUnlisted)) {
                 if (!categoryKuserPeer::areCategoriesAllowed($categoriesIdsUnlisted)) {
                     throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdIn);
                 }
             }
         }
         //validate entitl category
         if ($this->categoryIdEqual != null) {
             $category = categoryPeer::retrieveByPK($this->categoryIdEqual);
             if (!$category && kCurrentContext::$master_partner_id != Partner::BATCH_PARTNER_ID) {
                 throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdEqual);
             }
             if ($category->getDisplayInSearch() == DisplayInSearchType::CATEGORY_MEMBERS_ONLY && !categoryKuserPeer::retrievePermittedKuserInCategory($category->getId(), kCurrentContext::getCurrentKsKuserId())) {
                 throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryIdEqual);
             }
         }
     }
     $categoryEntryFilter = $this->toObject();
     $c = KalturaCriteria::create(categoryEntryPeer::OM_CLASS);
     $categoryEntryFilter->attachToCriteria($c);
     if (!kEntitlementUtils::getEntitlementEnforcement() || $this->entryIdEqual == null) {
         $pager->attachToCriteria($c);
     }
     $dbCategoriesEntry = categoryEntryPeer::doSelect($c);
     if (kEntitlementUtils::getEntitlementEnforcement() && count($dbCategoriesEntry) && $this->entryIdEqual != null) {
         //remove unlisted categories: display in search is set to members only
         $categoriesIds = array();
         foreach ($dbCategoriesEntry as $dbCategoryEntry) {
             $categoriesIds[] = $dbCategoryEntry->getCategoryId();
         }
         $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
         $c->add(categoryPeer::ID, $categoriesIds, Criteria::IN);
         $pager->attachToCriteria($c);
         $c->applyFilters();
         $categoryIds = $c->getFetchedIds();
         foreach ($dbCategoriesEntry as $key => $dbCategoryEntry) {
             if (!in_array($dbCategoryEntry->getCategoryId(), $categoryIds)) {
                 KalturaLog::debug('Category [' . print_r($dbCategoryEntry->getCategoryId(), true) . '] is not listed to user');
                 unset($dbCategoriesEntry[$key]);
             }
         }
         $totalCount = $c->getRecordsCount();
     } else {
         $resultCount = count($dbCategoriesEntry);
         if ($resultCount && $resultCount < $pager->pageSize) {
             $totalCount = ($pager->pageIndex - 1) * $pager->pageSize + $resultCount;
         } else {
             KalturaFilterPager::detachFromCriteria($c);
             $totalCount = categoryEntryPeer::doCount($c);
         }
     }
     $categoryEntrylist = KalturaCategoryEntryArray::fromDbArray($dbCategoriesEntry, $responseProfile);
     $response = new KalturaCategoryEntryListResponse();
     $response->objects = $categoryEntrylist;
     $response->totalCount = $totalCount;
     // no pager since category entry is limited to ENTRY::MAX_CATEGORIES_PER_ENTRY
     return $response;
 }
Exemplo n.º 15
0
 /**
  * activate CategoryEntry when it is pending moderation
  * 
  * @action reject
  * @param string $entryId
  * @param int $categoryId
  * @throws KalturaErrors::INVALID_ENTRY_ID
  * @throws KalturaErrors::CATEGORY_NOT_FOUND
  * @throws KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY
  * @throws KalturaErrors::CANNOT_ACTIVATE_CATEGORY_ENTRY
  */
 function rejectAction($entryId, $categoryId)
 {
     $entry = entryPeer::retrieveByPK($entryId);
     if (!$entry) {
         throw new KalturaAPIException(KalturaErrors::INVALID_ENTRY_ID, $entryId);
     }
     $category = categoryPeer::retrieveByPK($categoryId);
     if (!$category) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryId);
     }
     $dbCategoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($categoryId, $entryId);
     if (!$dbCategoryEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY);
     }
     //validate user is entiteld to reject entry from category
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         $categoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($categoryId, kCurrentContext::getCurrentKsKuserId());
         if (!$categoryKuser || $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER && $categoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MODERATOR) {
             throw new KalturaAPIException(KalturaErrors::CANNOT_REJECT_CATEGORY_ENTRY);
         }
     }
     if ($dbCategoryEntry->getStatus() != CategoryEntryStatus::PENDING) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_REJECT_CATEGORY_ENTRY_SINCE_IT_IS_NOT_PENDING);
     }
     $dbCategoryEntry->setStatus(CategoryEntryStatus::REJECTED);
     $dbCategoryEntry->save();
 }
Exemplo n.º 16
0
 protected function validateEntryEntitlement($entryId, $assetId)
 {
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         $entry = entryPeer::retrieveByPK($entryId);
         if (!$entry) {
             //we will throw asset not found, as the user is not entitled, and should not know that the entry exists.
             throw new KalturaAPIException(KalturaErrors::ASSET_ID_NOT_FOUND, $assetId);
         }
     }
 }
 /**
  * Index an entry by id.
  * 
  * @action index
  * @param string $id
  * @param bool $shouldUpdate
  * @return int entry int id
  */
 function indexAction($id, $shouldUpdate = true)
 {
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_INDEX_OBJECT_WHEN_ENTITLEMENT_IS_ENABLE);
     }
     $entryDb = entryPeer::retrieveByPK($id);
     if (!$entryDb) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $id);
     }
     if (!$shouldUpdate) {
         $entryDb->indexToSearchIndex();
         return $entryDb->getIntId();
     }
     return myEntryUtils::index($entryDb);
 }
 /**
  * Get remote storage existing paths for the asset
  * 
  * @action getRemotePaths
  * @param string $id
  * @return KalturaRemotePathListResponse
  * @throws KalturaErrors::THUMB_ASSET_ID_NOT_FOUND
  * @throws KalturaErrors::THUMB_ASSET_IS_NOT_READY
  */
 public function getRemotePathsAction($id)
 {
     $assetDb = assetPeer::retrieveById($id);
     if (!$assetDb || !$assetDb instanceof thumbAsset) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $id);
     }
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         $entry = entryPeer::retrieveByPK($assetDb->getEntryId());
         if (!$entry) {
             //we will throw thumb asset not found, as the user is not entitled, and should not know that the entry exists.
             throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_ID_NOT_FOUND, $id);
         }
     }
     if ($assetDb->getStatus() != asset::ASSET_STATUS_READY) {
         throw new KalturaAPIException(KalturaErrors::THUMB_ASSET_IS_NOT_READY);
     }
     $c = new Criteria();
     $c->add(FileSyncPeer::OBJECT_TYPE, FileSyncObjectType::ASSET);
     $c->add(FileSyncPeer::OBJECT_SUB_TYPE, asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
     $c->add(FileSyncPeer::OBJECT_ID, $id);
     $c->add(FileSyncPeer::VERSION, $assetDb->getVersion());
     $c->add(FileSyncPeer::PARTNER_ID, $assetDb->getPartnerId());
     $c->add(FileSyncPeer::STATUS, FileSync::FILE_SYNC_STATUS_READY);
     $c->add(FileSyncPeer::FILE_TYPE, FileSync::FILE_SYNC_FILE_TYPE_URL);
     $fileSyncs = FileSyncPeer::doSelect($c);
     $listResponse = new KalturaRemotePathListResponse();
     $listResponse->objects = KalturaRemotePathArray::fromFileSyncArray($fileSyncs);
     $listResponse->totalCount = count($listResponse->objects);
     return $listResponse;
 }
 /**
  * List metadata objects by filter and pager
  * 
  * @action list
  * @param KalturaMetadataFilter $filter
  * @param KalturaFilterPager $pager
  * @return KalturaMetadataListResponse
  */
 function listAction(KalturaMetadataFilter $filter = null, KalturaFilterPager $pager = null)
 {
     if (!$filter) {
         $filter = new KalturaMetadataFilter();
     }
     if (kEntitlementUtils::getEntitlementEnforcement() && (is_null($filter->objectIdIn) && is_null($filter->objectIdEqual))) {
         throw new KalturaAPIException(MetadataErrors::MUST_FILTER_ON_OBJECT_ID);
     }
     $entryIds = null;
     if ($filter->metadataObjectTypeEqual == MetadataObjectType::ENTRY) {
         if ($filter->objectIdEqual) {
             $entryIds = array($filter->objectIdEqual);
         } else {
             if ($filter->objectIdIn) {
                 $entryIds = explode(',', $filter->objectIdIn);
             }
         }
     }
     if (is_null($entryIds)) {
         myPartnerUtils::addPartnerToCriteria(new MetadataPeer(), $this->getPartnerId(), $this->private_partner_data, $this->partnerGroup());
     } else {
         $entryIds = entryPeer::filterEntriesByPartnerOrKalturaNetwork($entryIds, $this->getPartnerId());
         $filter->objectIdEqual = null;
         $filter->objectIdIn = implode(',', $entryIds);
     }
     $metadataFilter = new MetadataFilter();
     $filter->toObject($metadataFilter);
     $c = new Criteria();
     $metadataFilter->attachToCriteria($c);
     if ($entryIds === array()) {
         $c->addAnd(MetadataPeer::OBJECT_ID, array(), Criteria::IN);
     }
     $count = MetadataPeer::doCount($c);
     if (!$pager) {
         $pager = new KalturaFilterPager();
     }
     $pager->attachToCriteria($c);
     $list = MetadataPeer::doSelect($c);
     $response = new KalturaMetadataListResponse();
     $response->objects = KalturaMetadataArray::fromDbArray($list);
     $response->totalCount = $count;
     return $response;
 }
Exemplo n.º 20
0
 /**
  * Update exisiting widget
  * 
  * @action update
  * @param string $id 
  * @param KalturaWidget $widget
  * @return KalturaWidget
  */
 function updateAction($id, KalturaWidget $widget)
 {
     $dbWidget = widgetPeer::retrieveByPK($id);
     if (!$dbWidget) {
         throw new KalturaAPIException(APIErrors::INVALID_WIDGET_ID, $id);
     }
     if (!is_null($widget->enforceEntitlement) && $widget->enforceEntitlement == false && kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_DISABLE_ENTITLEMENT_FOR_WIDGET_WHEN_ENTITLEMENT_ENFORCEMENT_ENABLE);
     }
     if ($widget->entryId !== null) {
         $entry = entryPeer::retrieveByPK($widget->entryId);
         if (!$entry) {
             throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $widget->entryId);
         }
     } elseif ($widget->enforceEntitlement != null && $widget->enforceEntitlement == false) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_DISABLE_ENTITLEMENT_WITH_NO_ENTRY_ID);
     }
     $widgetUpdate = $widget->toWidget();
     if ($entry && $entry->getType() == entryType::PLAYLIST) {
         $dbWidget->setIsPlayList(true);
     } else {
         $dbWidget->setIsPlayList(false);
     }
     $allow_empty = true;
     // TODO - what is the policy  ?
     baseObjectUtils::autoFillObjectFromObject($widgetUpdate, $dbWidget, $allow_empty);
     $dbWidget->save();
     // TODO: widget in cache, should drop from cache
     $widget->fromObject($dbWidget, $this->getResponseProfile());
     return $widget;
 }
 public static function syncEntriesCategories(entry $entry, $isCategoriesModified)
 {
     self::$skipEntrySave = true;
     if ($entry->getNewCategories() != null && $entry->getNewCategories() !== "") {
         $newCats = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getNewCategories());
     } else {
         $newCats = array();
     }
     if (!$isCategoriesModified) {
         if ($entry->getNewCategoriesIds() != null && $entry->getNewCategoriesIds() !== "") {
             $newCatsIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getNewCategoriesIds());
         } else {
             $newCatsIds = array();
         }
         KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $dbCategories = categoryPeer::retrieveByPKs($newCatsIds);
         KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         foreach ($dbCategories as $dbCategory) {
             //skip categoy with privacy contexts.
             if ($dbCategory->getPrivacyContexts() != null && $dbCategory->getPrivacyContexts() != '') {
                 continue;
             }
             $newCats[] = $dbCategory->getFullName();
         }
     }
     $newCats = array_unique($newCats);
     $allIds = array();
     $allCats = array();
     $allIdsWithParents = array();
     $addedCats = array();
     $removedCats = array();
     $remainingCats = array();
     $oldCats = array();
     $oldCatsIds = array();
     $dbOldCategoriesEntry = categoryEntryPeer::selectByEntryId($entry->getId());
     foreach ($dbOldCategoriesEntry as $dbOldCategoryEntry) {
         $oldCatsIds[] = $dbOldCategoryEntry->getCategoryId();
     }
     $oldCategoris = categoryPeer::retrieveByPKsNoFilter($oldCatsIds);
     foreach ($oldCategoris as $category) {
         if ($category->getPrivacyContexts() != '' && $category->getPrivacyContexts() != null) {
             continue;
         }
         $oldCats[] = $category->getFullName();
     }
     foreach ($oldCats as $cat) {
         if (array_search($cat, $newCats) === false) {
             $removedCats[] = $cat;
         }
     }
     foreach ($newCats as $cat) {
         if (array_search($cat, $oldCats) === false) {
             $addedCats[] = $cat;
         } else {
             $remainingCats[] = $cat;
         }
     }
     foreach ($remainingCats as $cat) {
         KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         $category = categoryPeer::getByFullNameExactMatch($cat);
         KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
         if ($category) {
             if ($category->getPrivacyContext() == '' || $category->getPrivacyContext() == null) {
                 $allCats[] = $category->getFullName();
                 $allIds[] = $category->getId();
             }
             $allIdsWithParents[] = $category->getId();
             $allIdsWithParents = array_merge($allIdsWithParents, $category->getAllParentsIds());
         }
     }
     $alreadyAddedCatIds = $allIdsWithParents;
     foreach ($addedCats as $cat) {
         $category = categoryPeer::getByFullNameExactMatch($cat);
         if (!$category) {
             KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
             $unentitedCategory = categoryPeer::getByFullNameExactMatch($cat);
             KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
             if (!$unentitedCategory) {
                 $category = category::createByPartnerAndFullName($entry->getPartnerId(), $cat);
                 //it is possible to add on an entry a few new categories on the same new parent -
                 //and we need to sync sphinx once we add so the category will not be duplicated
                 kEventsManager::flushEvents();
             }
         } else {
             $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($category->getId(), kCurrentContext::$ks_kuser_id);
             if (kEntitlementUtils::getEntitlementEnforcement() && $category->getContributionPolicy() != ContributionPolicyType::ALL && (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER)) {
                 //user is not entitled to add entry to this category
                 $category = null;
             }
         }
         if (!$category) {
             continue;
         }
         //when use caetgoryEntry->add categoryEntry object was alreay created - and no need to create it.
         //when using baseEntry->categories = 'my category' will need to add the new category.
         $categoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($category->getId(), $entry->getId());
         if (!$categoryEntry) {
             $categoryEntry = new categoryEntry();
             $categoryEntry->setEntryId($entry->getId());
             $categoryEntry->setCategoryId($category->getId());
             $categoryEntry->setEntryCategoriesAddedIds($alreadyAddedCatIds);
             $categoryEntry->setPartnerId($entry->getPartnerId());
             $categoryEntry->setStatus(CategoryEntryStatus::ACTIVE);
             $categoryEntry->save();
         }
         if ($category->getPrivacyContext() == '' || $category->getPrivacyContext() == null) {
             // only categories with no context should be set on entry->categories and entry->categoriesIds
             $allCats[] = $category->getFullName();
             $allIds[] = $category->getId();
         }
         $alreadyAddedCatIds[] = $category->getId();
         $alreadyAddedCatIds = array_merge($alreadyAddedCatIds, $category->getAllParentsIds());
     }
     $alreadyRemovedCatIds = $allIdsWithParents;
     foreach ($removedCats as $cat) {
         $category = categoryPeer::getByFullNameExactMatch($cat);
         if ($category) {
             $categoryEntryToDelete = categoryEntryPeer::retrieveByCategoryIdAndEntryId($category->getId(), $entry->getId());
             if ($categoryEntryToDelete) {
                 $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryEntryToDelete->getCategoryId(), kCurrentContext::$ks_kuser_id);
                 if ($category->getPrivacyContexts() && (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER)) {
                     //not entiteld to delete - should be set back on the entry.
                     $allCats[] = $category->getFullName();
                     $allIds[] = $category->getId();
                 } else {
                     $categoryEntryToDelete->setEntryCategoriesRemovedIds($alreadyRemovedCatIds);
                     $categoryEntryToDelete->setStatus(CategoryEntryStatus::DELETED);
                     $categoryEntryToDelete->save();
                 }
             }
             $alreadyRemovedCatIds[] = $category->getId();
             $alreadyRemovedCatIds = array_merge($alreadyRemovedCatIds, $category->getAllParentsIds());
         } else {
             //category was not found - it could be that user is not entitled to remove it
             KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
             $category = categoryPeer::getByFullNameExactMatch($cat);
             KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
             if ($category) {
                 $allCats[] = $category->getFullName();
                 $allIds[] = $category->getId();
             }
         }
     }
     self::$skipEntrySave = false;
     $entry->parentSetCategories(implode(",", $allCats));
     $entry->parentSetCategoriesIds(implode(',', $allIds));
 }
 /**
  * validate category fields
  * 1. category that inherit memebers canno set values to inherited fields.
  * 2. validate the owner id exists as kuser
  * 
  * @param category $sourceObject
  */
 private function validateCategory(category $sourceObject = null)
 {
     if ($this->privacyContext != null && kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_PRIVACY_CONTEXT);
     }
     if (!$this->privacyContext && (!$sourceObject || !$sourceObject->getPrivacyContexts())) {
         if ($this->appearInList != KalturaAppearInListType::PARTNER_ONLY && $this->appearInList != null || $this->moderation != KalturaNullableBoolean::FALSE_VALUE && $this->moderation != null || $this->inheritanceType != KalturaInheritanceType::MANUAL && $this->inheritanceType != null || $this->privacy != KalturaPrivacyType::ALL && $this->privacy != null || $this->owner != null || $this->userJoinPolicy != KalturaUserJoinPolicyType::NOT_ALLOWED && $this->userJoinPolicy != null || $this->contributionPolicy != KalturaContributionPolicyType::ALL && $this->contributionPolicy != null || $this->defaultPermissionLevel != KalturaCategoryUserPermissionLevel::MEMBER && $this->defaultPermissionLevel !== null) {
             if ($this->parentId != null) {
                 $parentCategory = categoryPeer::retrieveByPK($this->parentId);
                 if (!$parentCategory) {
                     throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->parentId);
                 }
                 if ($parentCategory->getPrivacyContexts() == '') {
                     throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_ENTITLEMENT_FIELDS_WITH_NO_PRIVACY_CONTEXT);
                 }
             } else {
                 throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_ENTITLEMENT_FIELDS_WITH_NO_PRIVACY_CONTEXT);
             }
         }
     }
     if ($this->inheritanceType != KalturaInheritanceType::MANUAL && $this->inheritanceType != null || $this->inheritanceType == null && $sourceObject && $sourceObject->getInheritanceType() != KalturaInheritanceType::MANUAL) {
         if (!$sourceObject && $this->owner != null || $sourceObject && $this->owner != null && $this->owner != $sourceObject->getKuserId() || !$sourceObject && $this->userJoinPolicy != null || $sourceObject && $this->userJoinPolicy != null && $this->userJoinPolicy != $sourceObject->getUserJoinPolicy() || !$sourceObject && $this->defaultPermissionLevel != null || $sourceObject && $this->defaultPermissionLevel != null && $this->defaultPermissionLevel != $sourceObject->getDefaultPermissionLevel()) {
             throw new KalturaAPIException(KalturaErrors::CATEGORY_INHERIT_MEMBERS_CANNOT_UPDATE_INHERITED_ATTRIBUTES);
         }
     }
     if (!is_null($sourceObject)) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $partner = PartnerPeer::retrieveByPK($partnerId);
         if (!$partner || $partner->getFeaturesStatusByType(IndexObjectType::LOCK_CATEGORY)) {
             throw new KalturaAPIException(KalturaErrors::CATEGORIES_LOCKED);
         }
     }
     if ($this->owner && $this->owner != '' && !$this->owner instanceof KalturaNullField) {
         if (!preg_match(kuser::PUSER_ID_REGEXP, $this->owner)) {
             throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'owner');
         }
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         kuserPeer::createKuserForPartner($partnerId, $this->owner);
     }
 }
Exemplo n.º 23
0
 public function validateForResponseProfile()
 {
     if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_ENABLE_RESPONSE_PROFILE_USER_CACHE, kCurrentContext::getCurrentPartnerId())) {
         return;
     }
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_LIST_RELATED_ENTITLED_WHEN_ENTITLEMENT_IS_ENABLE, get_class($this));
     }
     if (!kCurrentContext::$is_admin_session && !$this->idEqual && !$this->idIn && !$this->referenceIdEqual && !$this->redirectFromEntryId && !$this->referenceIdIn && !$this->parentEntryIdEqual) {
         if (kCurrentContext::$ks_object->privileges === ks::PATTERN_WILDCARD) {
             return;
         }
         if (kCurrentContext::$ks_object->getPrivilegeValue(ks::PRIVILEGE_LIST) === ks::PATTERN_WILDCARD) {
             return;
         }
         throw new KalturaAPIException(KalturaErrors::USER_KS_CANNOT_LIST_RELATED_ENTRIES, get_class($this));
     }
 }
Exemplo n.º 24
0
 /**
  * Search caption asset items by filter, pager and free text
  *
  * @action searchEntries
  * @param KalturaBaseEntryFilter $entryFilter
  * @param KalturaCaptionAssetItemFilter $captionAssetItemFilter
  * @param KalturaFilterPager $captionAssetItemPager
  * @return KalturaBaseEntryListResponse
  */
 public function searchEntriesAction(KalturaBaseEntryFilter $entryFilter = null, KalturaCaptionAssetItemFilter $captionAssetItemFilter = null, KalturaFilterPager $captionAssetItemPager = null)
 {
     if (!$captionAssetItemPager) {
         $captionAssetItemPager = new KalturaFilterPager();
     }
     if (!$captionAssetItemFilter) {
         $captionAssetItemFilter = new KalturaCaptionAssetItemFilter();
     }
     $captionAssetItemFilter->validatePropertyNotNull(array("contentLike", "contentMultiLikeOr", "contentMultiLikeAnd"));
     $captionAssetItemCoreFilter = new CaptionAssetItemFilter();
     $captionAssetItemFilter->toObject($captionAssetItemCoreFilter);
     $entryIdChunks = array(NULL);
     if ($entryFilter || kEntitlementUtils::getEntitlementEnforcement()) {
         $entryCoreFilter = new entryFilter();
         if ($entryFilter) {
             $entryFilter->toObject($entryCoreFilter);
         }
         $entryCoreFilter->setPartnerSearchScope($this->getPartnerId());
         $this->addEntryAdvancedSearchFilter($captionAssetItemFilter, $entryCoreFilter);
         $entryCriteria = KalturaCriteria::create(entryPeer::OM_CLASS);
         $entryCoreFilter->attachToCriteria($entryCriteria);
         $entryCriteria->setLimit(self::MAX_NUMBER_OF_ENTRIES);
         $entryCriteria->applyFilters();
         $entryIds = $entryCriteria->getFetchedIds();
         if (!$entryIds || !count($entryIds)) {
             $entryIds = array('NOT_EXIST');
         }
         $entryIdChunks = array_chunk($entryIds, self::SIZE_OF_ENTRIES_CHUNK);
     }
     $entries = array();
     $counter = 0;
     $shouldSortCaptionFiltering = $entryFilter->orderBy ? true : false;
     $captionAssetItemCriteria = KalturaCriteria::create(CaptionAssetItemPeer::OM_CLASS);
     $captionAssetItemCoreFilter->attachToCriteria($captionAssetItemCriteria);
     $captionAssetItemCriteria->setGroupByColumn('str_entry_id');
     $captionAssetItemCriteria->setSelectColumn('str_entry_id');
     foreach ($entryIdChunks as $chunk) {
         $currCriteria = clone $captionAssetItemCriteria;
         if ($chunk) {
             $currCriteria->add(CaptionAssetItemPeer::ENTRY_ID, $chunk, KalturaCriteria::IN);
         } else {
             $captionAssetItemPager->attachToCriteria($currCriteria);
         }
         $currCriteria->applyFilters();
         $currEntries = $currCriteria->getFetchedIds();
         //sorting this chunk according to results of first sphinx query
         if ($shouldSortCaptionFiltering) {
             $currEntries = array_intersect($entryIds, $currEntries);
         }
         $entries = array_merge($entries, $currEntries);
         $counter += $currCriteria->getRecordsCount();
     }
     $inputPageSize = $captionAssetItemPager->pageSize;
     $inputPageIndex = $captionAssetItemPager->pageIndex;
     //page index & size validation - no negative values & size not too big
     $pageSize = max(min($inputPageSize, baseObjectFilter::getMaxInValues()), 0);
     $pageIndex = max($captionAssetItemPager::MIN_PAGE_INDEX, $inputPageIndex) - 1;
     $firstIndex = $pageSize * $pageIndex;
     $entries = array_slice($entries, $firstIndex, $pageSize);
     $dbList = entryPeer::retrieveByPKs($entries);
     if ($shouldSortCaptionFiltering) {
         //results ids mapping
         $entriesMapping = array();
         foreach ($dbList as $item) {
             $entriesMapping[$item->getId()] = $item;
         }
         $dbList = array();
         foreach ($entries as $entryId) {
             if (isset($entriesMapping[$entryId])) {
                 $dbList[] = $entriesMapping[$entryId];
             }
         }
     }
     $list = KalturaBaseEntryArray::fromDbArray($dbList, $this->getResponseProfile());
     $response = new KalturaBaseEntryListResponse();
     $response->objects = $list;
     $response->totalCount = $counter;
     return $response;
 }
Exemplo n.º 25
0
 public function syncCategories()
 {
     if (!$this->is_categories_modified) {
         return;
     }
     if (!kEntitlementUtils::getEntitlementEnforcement() || !kEntitlementUtils::isKsPrivacyContextSet()) {
         categoryEntryPeer::syncEntriesCategories($this, $this->is_categories_names_modified);
     }
     parent::save();
     $this->is_categories_modified = false;
 }
 /**
  * Override in order to filter objects returned from doSelect.
  *  
  * @param      array $selectResults The array of objects to filter.
  * @param	   Criteria $criteria
  */
 public static function filterSelectResults(&$selectResults, Criteria $criteria)
 {
     if (!kEntitlementUtils::getEntitlementEnforcement() && !is_null(kCurrentContext::$ks) || !self::$filerResults || !kEntitlementUtils::getInitialized()) {
         // if initEntitlement hasn't run - skip filters.
         return parent::filterSelectResults($selectResults, $criteria);
     }
     KalturaLog::debug('Entitlement: Filter Results');
     if (is_null(kCurrentContext::$ks) && count($selectResults)) {
         $entry = $selectResults[0];
         $partner = $entry->getPartner();
         if (!$partner) {
             throw new kCoreException('entry partner not found');
         }
         if (!$partner->getDefaultEntitlementEnforcement() || !PermissionPeer::isValidForPartner(PermissionName::FEATURE_ENTITLEMENT, $partner->getId())) {
             return parent::filterSelectResults($selectResults, $criteria);
         }
     }
     $removedRecordsCount = 0;
     foreach ($selectResults as $key => $entry) {
         if (!kEntitlementUtils::isEntryEntitled($entry)) {
             unset($selectResults[$key]);
             $removedRecordsCount++;
         }
     }
     if ($criteria instanceof KalturaCriteria) {
         $recordsCount = $criteria->getRecordsCount();
         $criteria->setRecordsCount($recordsCount - $removedRecordsCount);
     }
     self::$filerResults = false;
     parent::filterSelectResults($selectResults, $criteria);
     KalturaLog::debug('Entitlement: Filter Results - done');
 }