public function clearMemory()
 {
     accessControlPeer::clearInstancePool();
     BatchJobPeer::clearInstancePool();
     BulkUploadResultPeer::clearInstancePool();
     categoryPeer::clearInstancePool();
     EmailIngestionProfilePeer::clearInstancePool();
     entryPeer::clearInstancePool();
     FileSyncPeer::clearInstancePool();
     flavorAssetPeer::clearInstancePool();
     flavorParamsConversionProfilePeer::clearInstancePool();
     flavorParamsOutputPeer::clearInstancePool();
     flavorParamsPeer::clearInstancePool();
     kshowPeer::clearInstancePool();
     mediaInfoPeer::clearInstancePool();
     moderationFlagPeer::clearInstancePool();
     moderationPeer::clearInstancePool();
     notificationPeer::clearInstancePool();
     roughcutEntryPeer::clearInstancePool();
     SchedulerConfigPeer::clearInstancePool();
     SchedulerPeer::clearInstancePool();
     SchedulerStatusPeer::clearInstancePool();
     SchedulerWorkerPeer::clearInstancePool();
     StorageProfilePeer::clearInstancePool();
     syndicationFeedPeer::clearInstancePool();
     TrackEntryPeer::clearInstancePool();
     uiConfPeer::clearInstancePool();
     UploadTokenPeer::clearInstancePool();
     // TODO clear default filters
     // TODO call all memory cleaner plugins
     if (function_exists('gc_collect_cycles')) {
         // php 5.3 and above
         gc_collect_cycles();
     }
 }
Exemple #2
0
 /**
  * Get categories by full name using full name wildcard match (returns an array)
  *  
  * @param $partnerId
  * @param $fullName
  * @param $con
  * @return array
  */
 public static function getByFullNameWildcardMatch($fullName, $con = null)
 {
     $fullName = str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $fullName);
     $c = new Criteria();
     $c->add(categoryPeer::FULL_NAME, $fullName . "%", Criteria::LIKE);
     return categoryPeer::doSelect($c, $con);
 }
 public function retrieveByIdentifier($value)
 {
     switch ($this->identifier) {
         case CategoryIdentifierField::FULL_NAME:
             return categoryPeer::getByFullNameExactMatch($value);
         case CategoryIdentifierField::ID:
             return categoryPeer::retrieveByPK($value);
         case CategoryIdentifierField::REFERENCE_ID:
             $objects = categoryPeer::getByReferenceId($value);
             return $objects[0];
     }
 }
Exemple #4
0
 public function validateParentId(KalturaCategory $category)
 {
     if ($category->parentId === null) {
         $category->parentId = 0;
     }
     if ($category->parentId !== 0) {
         $parentCategoryDb = categoryPeer::retrieveByPK($category->parentId);
         if (!$parentCategoryDb) {
             throw new KalturaAPIException(KalturaErrors::PARENT_CATEGORY_NOT_FOUND, $category->parentId);
         }
     }
 }
 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;
 }
 /**
  * Convert the categories to categories ids
  * 
  * @param string $cats Categories full names
  * @return string Categogories indexes ids
  */
 public static function categoryNamesToIds($cats)
 {
     if ($cats === "") {
         $cats = array();
     } else {
         $cats = explode(",", $cats);
     }
     kArray::trim($cats);
     $catsIds = array();
     foreach ($cats as $cat) {
         $categories = categoryPeer::getByFullNameWildcardMatch($cat);
         foreach ($categories as $category) {
             $catsIds[] = $category->getId();
         }
     }
     return implode(",", $catsIds);
 }
 public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if ($this->orderBy === null) {
         $this->orderBy = KalturaCategoryOrderBy::DEPTH_ASC;
     }
     $categoryFilter = $this->toObject();
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $categoryFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $dbList = categoryPeer::doSelect($c);
     $totalCount = $c->getRecordsCount();
     $list = KalturaCategoryArray::fromDbArray($dbList, $responseProfile);
     $response = new KalturaCategoryListResponse();
     $response->objects = $list;
     $response->totalCount = $totalCount;
     return $response;
 }
 /**
  * Convert the categories to categories ids - not includes the category itself (only sub categories)
  * 
  * @param string $cats Categories full names
  * @param string $statuses comma seperated
  * @return string Comma seperated fullIds
  */
 public static function categoryIdsToAllSubCategoriesIdsParsed($cats)
 {
     if ($cats === "") {
         $cats = array();
     } else {
         $cats = explode(",", $cats);
     }
     kArray::trim($cats);
     $categoryFullIdsToIds = array();
     foreach ($cats as $cat) {
         $category = categoryPeer::retrieveByPK($cat);
         //all sub categories and not the category itself
         if (!$category) {
             continue;
         }
         $categoryFullIdsToIds[] = $category->getFullIds() . '>';
     }
     return implode(",", $categoryFullIdsToIds);
 }
 public static function copyCategories(Partner $fromPartner, Partner $toPartner)
 {
     KalturaLog::log("Copying categories from partner [" . $fromPartner->getId() . "] to partner [" . $toPartner->getId() . "]");
     categoryPeer::setUseCriteriaFilter(false);
     $c = new Criteria();
     $c->addAnd(categoryPeer::PARTNER_ID, $fromPartner->getId());
     $c->addAnd(categoryPeer::STATUS, CategoryStatus::ACTIVE);
     $c->addAscendingOrderByColumn(categoryPeer::DEPTH);
     $c->addAscendingOrderByColumn(categoryPeer::CREATED_AT);
     $categories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     foreach ($categories as $category) {
         /* @var $category category */
         $category->setPuserId(null);
         $newCategory = $category->copy();
         $newCategory->setPartnerId($toPartner->getId());
         if ($category->getParentId()) {
             $newCategory->setParentId(kObjectCopyHandler::getMappedId('category', $category->getParentId()));
         }
         $newCategory->save();
         $newCategory->setIsIndex(true);
         categoryPeer::setUseCriteriaFilter(false);
         $newCategory->reSetFullIds();
         $newCategory->reSetInheritedParentId();
         $newCategory->reSetDepth();
         $newCategory->reSetFullName();
         categoryPeer::setUseCriteriaFilter(true);
         $newCategory->setEntriesCount(0);
         $newCategory->setMembersCount(0);
         $newCategory->setPendingMembersCount(0);
         $newCategory->setDirectSubCategoriesCount(0);
         $newCategory->setDirectEntriesCount(0);
         $newCategory->save();
         KalturaLog::log("Copied [" . $category->getId() . "], new id is [" . $newCategory->getId() . "]");
     }
 }
Exemple #10
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = KalturaCriteria::create(categoryPeer::OM_CLASS);
         $criteria->add(categoryPeer::ID, $pks, Criteria::IN);
         $objs = categoryPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 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::info('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;
 }
 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));
 }
Exemple #13
0
 public static function doCountOnPeer(Criteria $c)
 {
     return categoryPeer::doCount($c);
 }
}
$countLimitEachLoop = 200;
//------------------------------------------------------
require_once dirname(__FILE__) . '/../bootstrap.php';
$con = myDbHelper::getConnection(myDbHelper::DB_HELPER_CONN_PROPEL2);
KalturaStatement::setDryRun($dryRun);
$lastCategoryId = 0;
while (1) {
    $c = new Criteria();
    $c->add(categoryPeer::STATUS, CategoryStatus::ACTIVE, Criteria::EQUAL);
    $c->add(categoryPeer::ID, $lastCategoryId, Criteria::GREATER_THAN);
    $c->add(categoryPeer::PRIVACY_CONTEXTS, null, Criteria::ISNOTNULL);
    $c->add(categoryPeer::PRIVACY_CONTEXTS, '', Criteria::NOT_EQUAL);
    $c->addAscendingOrderByColumn(categoryPeer::ID);
    $c->setLimit($countLimitEachLoop);
    $categories = categoryPeer::doSelect($c, $con);
    if (!count($categories)) {
        break;
    }
    foreach ($categories as $category) {
        /* @var $category category */
        KalturaLog::debug('Category [' . $category->getId() . ']');
        $lastCategoryEntryId = 0;
        while (1) {
            $c = new Criteria();
            $c->add(categoryEntryPeer::CATEGORY_ID, $category->getId(), Criteria::EQUAL);
            $c->add(categoryEntryPeer::STATUS, CategoryEntryStatus::ACTIVE, Criteria::EQUAL);
            $c->add(categoryEntryPeer::ID, $lastCategoryEntryId, Criteria::GREATER_THAN);
            $c->addAscendingOrderByColumn(categoryEntryPeer::ID);
            $c->setLimit($countLimitEachLoop);
            $categoryEntries = categoryEntryPeer::doSelect($c, $con);
Exemple #15
0
 /**
  * To validate if user is entitled to the category � all needed is to select from the db.
  * 
  * @throws KalturaErrors::ENTRY_CATEGORY_FIELD_IS_DEPRECATED
  */
 public function validateCategories()
 {
     $partnerId = kCurrentContext::$ks_partner_id ? kCurrentContext::$ks_partner_id : kCurrentContext::$partner_id;
     if (implode(',', kEntitlementUtils::getKsPrivacyContext()) != kEntitlementUtils::DEFAULT_CONTEXT . $partnerId && ($this->categoriesIds != null || $this->categories != null)) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_CATEGORY_FIELD_IS_DEPRECATED);
     }
     if ($this->categoriesIds != null) {
         $catsNames = array();
         $cats = explode(",", $this->categoriesIds);
         foreach ($cats as $cat) {
             $catName = categoryPeer::retrieveByPK($cat);
             if (is_null($catName)) {
                 throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $cat);
             }
         }
     }
     if ($this->categories != null) {
         $catsNames = array();
         $cats = explode(",", $this->categories);
         foreach ($cats as $cat) {
             $catName = categoryPeer::getByFullNameExactMatch($cat);
             if (is_null($catName)) {
                 KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
                 $catName = categoryPeer::getByFullNameExactMatch($cat);
                 if ($catName) {
                     throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_PERMITTED, $cat);
                 }
                 KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
             }
         }
     }
 }
 public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if ($this->userIdIn) {
         $usersIds = explode(',', $this->userIdIn);
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId, Criteria::EQUAL);
         $c->add(kuserPeer::PUSER_ID, $usersIds, Criteria::IN);
         $kusers = kuserPeer::doSelect($c);
         $usersIds = array();
         foreach ($kusers as $kuser) {
             /* @var $kuser kuser */
             $usersIds[] = $kuser->getId();
         }
         $this->userIdIn = implode(',', $usersIds);
     }
     if ($this->relatedGroupsByUserId) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $userIds = array();
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId);
         $c->add(kuserPeer::PUSER_ID, $this->relatedGroupsByUserId);
         $c->add(kuserPeer::TYPE, KuserType::USER);
         $kuser = kuserPeer::doSelectOne($c);
         if (!$kuser) {
             $response = new KalturaCategoryUserListResponse();
             $response->objects = new KalturaCategoryUserArray();
             $response->totalCount = 0;
             return $response;
         }
         $kgroupIds = KuserKgroupPeer::retrieveKgroupIdsByKuserId($kuser->getId());
         if (!is_null($kgroupIds) && is_array($kgroupIds)) {
             $userIds = $kgroupIds;
         }
         $userIds[] = $kuser->getId();
         // if userIdIn is also set in the filter need to intersect the two arrays.
         if (isset($this->userIdIn)) {
             $curUserIds = explode(',', $this->userIdIn);
             $userIds = array_intersect($curUserIds, $userIds);
         }
         $this->userIdIn = implode(',', $userIds);
     }
     if ($this->userIdEqual) {
         $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id;
         $c = new Criteria();
         $c->add(kuserPeer::PARTNER_ID, $partnerId);
         $c->add(kuserPeer::PUSER_ID, $this->userIdEqual);
         if (kCurrentContext::$ks_partner_id == Partner::BATCH_PARTNER_ID) {
             //batch should be able to get categoryUser of deleted users.
             kuserPeer::setUseCriteriaFilter(false);
         }
         // in case of more than one deleted kusers - get the last one
         $c->addDescendingOrderByColumn(kuserPeer::UPDATED_AT);
         $kuser = kuserPeer::doSelectOne($c);
         kuserPeer::setUseCriteriaFilter(true);
         if (!$kuser) {
             KalturaLog::debug('User not found');
             $response = new KalturaCategoryUserListResponse();
             $response->objects = new KalturaCategoryUserArray();
             $response->totalCount = 0;
             return $response;
         }
         $this->userIdEqual = $kuser->getId();
     }
     $categories = array();
     if ($this->categoryIdEqual) {
         $categories[] = categoryPeer::retrieveByPK($this->categoryIdEqual);
     } elseif ($this->categoryIdIn) {
         $categories = categoryPeer::retrieveByPKs(explode(',', $this->categoryIdIn));
     }
     $categoriesInheritanceRoot = array();
     foreach ($categories as $category) {
         /* @var $category category */
         if (is_null($category)) {
             continue;
         }
         if ($category->getInheritanceType() == InheritanceType::INHERIT) {
             if ($this->categoryDirectMembers && kCurrentContext::$master_partner_id == Partner::BATCH_PARTNER_ID) {
                 $categoriesInheritanceRoot[$category->getId()] = $category->getId();
             } else {
                 //if category inheris members - change filter to -> inherited from parent id = category->getIheritedParent
                 $categoriesInheritanceRoot[$category->getInheritedParentId()] = $category->getInheritedParentId();
             }
         } else {
             $categoriesInheritanceRoot[$category->getId()] = $category->getId();
         }
     }
     $this->categoryDirectMembers = null;
     $this->categoryIdEqual = null;
     $this->categoryIdIn = implode(',', $categoriesInheritanceRoot);
     //if filter had categories that doesn't exists or not entitled - should return 0 objects.
     if (count($categories) && !count($categoriesInheritanceRoot)) {
         $response = new KalturaCategoryUserListResponse();
         $response->totalCount = 0;
         return $response;
     }
     $categoryKuserFilter = $this->toObject();
     $c = KalturaCriteria::create(categoryKuserPeer::OM_CLASS);
     $categoryKuserFilter->attachToCriteria($c);
     $pager->attachToCriteria($c);
     $c->applyFilters();
     $list = categoryKuserPeer::doSelect($c);
     $totalCount = $c->getRecordsCount();
     $newList = KalturaCategoryUserArray::fromDbArray($list, $responseProfile);
     $response = new KalturaCategoryUserListResponse();
     $response->objects = $newList;
     $response->totalCount = $totalCount;
     return $response;
 }
 public static function copyEntry(entry $entry, Partner $toPartner = null, $dontCopyUsers = false)
 {
     KalturaLog::log("copyEntry - Copying entry [" . $entry->getId() . "] to partner [" . $toPartner->getId() . "]");
     $newEntry = $entry->copy();
     $newEntry->setIntId(null);
     if ($toPartner instanceof Partner) {
         $newEntry->setPartnerId($toPartner->getId());
         $newEntry->setSubpId($toPartner->getId() * 100);
         $newEntry->setAccessControlId($toPartner->getDefaultAccessControlId());
         $flavorParamsStr = $entry->getFlavorParamsIds();
         $flavorParams = explode(',', $flavorParamsStr);
         $newFlavorParams = array();
         foreach ($flavorParams as $flavorParamsId) {
             $newFlavorParamsId = kObjectCopyHandler::getMappedId('flavorParams', $flavorParamsId);
             if (is_null($newFlavorParamsId)) {
                 $newFlavorParamsId = $flavorParamsId;
             }
             $newFlavorParams[] = $newFlavorParamsId;
         }
         $newEntry->setFlavorParamsIds(implode(',', $newFlavorParams));
     }
     $newKuser = null;
     if (!$dontCopyUsers) {
         // copy the kuser (if the same puser id exists its kuser will be used)
         kuserPeer::setUseCriteriaFilter(false);
         $kuser = $entry->getKuser();
         $newKuser = kuserPeer::createKuserForPartner($newEntry->getPartnerId(), $kuser->getPuserId());
         $newEntry->setKuserId($newKuser->getId());
         kuserPeer::setUseCriteriaFilter(true);
     }
     // copy the kshow
     kshowPeer::setUseCriteriaFilter(false);
     $kshow = $entry->getKshow();
     if ($kshow) {
         $newKshow = $kshow->copy();
         $newKshow->setIntId(null);
         $newKshow->setPartnerId($toPartner->getId());
         $newKshow->setSubpId($toPartner->getId() * 100);
         if ($newKuser) {
             $newKshow->setProducerId($newKuser->getId());
         }
         $newKshow->save();
         $newEntry->setKshowId($newKshow->getId());
     }
     kshowPeer::setUseCriteriaFilter(true);
     // reset the statistics
     myEntryUtils::resetEntryStatistics($newEntry);
     // set the new partner id into the default category criteria filter
     $defaultCategoryFilter = categoryPeer::getCriteriaFilter()->getFilter();
     $oldPartnerId = $defaultCategoryFilter->get(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     // save the entry
     $newEntry->save();
     // restore the original partner id in the default category criteria filter
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $oldPartnerId);
     KalturaLog::log("copyEntry - New entry [" . $newEntry->getId() . "] was created");
     // for any type that does not require assets:
     $shouldCopyDataForNonClip = $entry->getType() != entryType::MEDIA_CLIP;
     $shouldCopyDataForClip = false;
     // only images get their data copied
     if ($entry->getType() == entryType::MEDIA_CLIP) {
         if ($entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_VIDEO && $entry->getMediaType() != entry::ENTRY_MEDIA_TYPE_AUDIO) {
             $shouldCopyDataForClip = true;
         }
     }
     if ($shouldCopyDataForNonClip || $shouldCopyDataForClip) {
         // copy the data
         $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         // replaced__getDataPath
         KalturaLog::log("copyEntriesByType - copying entry data [" . $from . "] to [" . $to . "]");
         kFileSyncUtils::softCopy($from, $to);
     }
     $ismFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
     if (kFileSyncUtils::fileSync_exists($ismFrom)) {
         $ismTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
         KalturaLog::log("copying entry ism [" . $ismFrom . "] to [" . $ismTo . "]");
         kFileSyncUtils::softCopy($ismFrom, $ismTo);
     }
     $ismcFrom = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($ismcFrom)) {
         $ismcTo = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
         KalturaLog::log("copying entry ism [" . $ismcFrom . "] to [" . $ismcTo . "]");
         kFileSyncUtils::softCopy($ismcFrom, $ismcTo);
     }
     $from = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
     // replaced__getThumbnailPath
     $considerCopyThumb = true;
     // if entry is image - data is thumbnail, and it was copied
     if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
         $considerCopyThumb = false;
     }
     // if entry is not clip, and there is no file in both DCs - nothing to copy
     if ($entry->getType() != entryType::MEDIA_CLIP && !kFileSyncUtils::file_exists($from, true)) {
         $considerCopyThumb = false;
     }
     if ($considerCopyThumb) {
         $skipThumb = false;
         // don't attempt to copy a thumbnail for images - it's the same as the data which was just created
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_AUDIO) {
             // check if audio entry has real thumb, if not - don't copy thumb.
             $originalFileSync = kFileSyncUtils::getOriginFileSyncForKey($from, false);
             if (!$originalFileSync) {
                 $skipThumb = true;
             }
         }
         if (!$skipThumb) {
             $to = $newEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
             // replaced__getThumbnailPath
             KalturaLog::log("copyEntriesByType - copying entry thumbnail [" . $from . "] to [" . $to . "]");
             kFileSyncUtils::softCopy($from, $to);
         }
     }
     // added by Tan-Tan 12/01/2010 to support falvors copy
     $sourceFlavorAssets = flavorAssetPeer::retrieveByEntryId($entry->getId());
     foreach ($sourceFlavorAssets as $sourceFlavorAsset) {
         $sourceFlavorAsset->copyToEntry($newEntry->getId(), $newEntry->getPartnerId());
     }
 }
 /**
  * add KalturaMediaEntry from email ingestion
  *
  * @action addMediaEntry
  * @param KalturaMediaEntry $mediaEntry Media entry metadata
  * @param string $uploadTokenId Upload token id
  * @param int $emailProfId
  * @param string $fromAddress
  * @param string $emailMsgId
  *
  * @return KalturaMediaEntry
  *
  * @throws KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN
  * @throws KalturaErrors::EMAIL_INGESTION_PROFILE_NOT_FOUND
  *
  */
 function addMediaEntryAction(KalturaMediaEntry $mediaEntry, $uploadTokenId, $emailProfId, $fromAddress, $emailMsgId)
 {
     try {
         // check that the uploaded file exists
         $entryFullPath = kUploadTokenMgr::getFullPathByUploadTokenId($uploadTokenId);
         if (!file_exists($entryFullPath)) {
             throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN);
         }
         // get the email profile by the given id
         $existingEIP = EmailIngestionProfilePeer::retrieveByPK($emailProfId);
         if (!$existingEIP) {
             throw new KalturaAPIException(KalturaErrors::EMAIL_INGESTION_PROFILE_NOT_FOUND, $emailProfId);
         }
         $emailIP = new KalturaEmailIngestionProfile();
         $emailIP->fromObject($existingEIP, $this->getResponseProfile());
         // handle defaults for media entry metadata
         $this->changeIfNull($mediaEntry->tags, $emailIP->defaultTags);
         $this->changeIfNull($mediaEntry->adminTags, $emailIP->defaultAdminTags);
         $this->changeIfNull($mediaEntry->conversionProfileId, $emailIP->conversionProfile2Id);
         $this->changeIfNull($mediaEntry->userId, $emailIP->defaultUserId);
         if (is_null($mediaEntry->categories) || is_null(categoryPeer::getByFullNameExactMatch($mediaEntry->categories))) {
             $mediaEntry->categories = $emailIP->defaultCategory;
         }
         // validate the input object
         //$entry->validatePropertyMinLength("name", 1);
         if (!$mediaEntry->name) {
             $mediaEntry->name = $this->getPartnerId() . '_' . time();
         }
         // first copy all the properties to the db entry, then we'll check for security stuff
         $dbEntry = $mediaEntry->toObject(new entry());
         if ($emailIP->moderationStatus == KalturaEntryModerationStatus::PENDING_MODERATION) {
             $dbEntry->setModerate(true);
         }
         $dbEntry->setType(KalturaEntryType::MEDIA_CLIP);
         $dbEntry->setMediaType(entry::ENTRY_MEDIA_TYPE_AUTOMATIC);
         $this->checkAndSetValidUserInsert($mediaEntry, $dbEntry);
         $this->checkAdminOnlyInsertProperties($mediaEntry);
         $this->validateAccessControlId($mediaEntry);
         $this->validateEntryScheduleDates($mediaEntry, $dbEntry);
         $dbEntry->setPartnerId($this->getPartnerId());
         $dbEntry->setSubpId($this->getPartnerId() * 100);
         $dbEntry->setSourceId($uploadTokenId);
         $dbEntry->setSourceLink($entryFullPath);
         $dbEntry->setDefaultModerationStatus();
         $dbEntry->save();
         $te = new TrackEntry();
         $te->setEntryId($dbEntry->getId());
         $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_ADD_ENTRY);
         $te->setDescription(__METHOD__ . ":" . __LINE__ . "::ENTRY_MEDIA_SOURCE_EMAIL_INGESTION");
         $te->setParam1Str($fromAddress);
         $te->setParam2Str($emailMsgId);
         $te->setParam3Str($emailProfId . '::' . $emailIP->emailAddress . '::' . $emailIP->mailboxId);
         TrackEntry::addTrackEntry($te);
         $kshow = $this->createDummyKShow();
         $kshowId = $kshow->getId();
         myEntryUtils::setEntryTypeAndMediaTypeFromFile($dbEntry, $entryFullPath);
         // setup the needed params for my insert entry helper
         $paramsArray = array("entry_media_source" => KalturaSourceType::FILE, "entry_media_type" => $dbEntry->getMediaType(), "entry_full_path" => $entryFullPath, "entry_license" => $dbEntry->getLicenseType(), "entry_credit" => $dbEntry->getCredit(), "entry_source_link" => $dbEntry->getSourceLink(), "entry_tags" => $dbEntry->getTags());
         $token = $this->getKsUniqueString();
         $insert_entry_helper = new myInsertEntryHelper(null, $dbEntry->getKuserId(), $kshowId, $paramsArray);
         $insert_entry_helper->setPartnerId($this->getPartnerId(), $this->getPartnerId() * 100);
         $insert_entry_helper->insertEntry($token, $dbEntry->getType(), $dbEntry->getId(), $dbEntry->getName(), $dbEntry->getTags(), $dbEntry);
         $dbEntry = $insert_entry_helper->getEntry();
         kUploadTokenMgr::closeUploadTokenById($uploadTokenId);
         myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_ADD, $dbEntry);
         $mediaEntry->fromObject($dbEntry, $this->getResponseProfile());
         return $mediaEntry;
     } catch (kCoreException $ex) {
         if ($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_INVALID_STATUS) {
         }
         throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_INVALID_STATUS_FOR_ADD_ENTRY);
         throw $ex;
     }
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(categoryPeer::DATABASE_NAME);
         $criteria->add(categoryPeer::ID, $pks, Criteria::IN);
         $objs = categoryPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * update privacy context from the category
  * 
  * @action syncPrivacyContext
  * @param string $entryId
  * @param int $categoryId
  * @throws KalturaErrors::INVALID_ENTRY_ID
  * @throws KalturaErrors::CATEGORY_NOT_FOUND
  * @throws KalturaErrors::ENTRY_IS_NOT_ASSIGNED_TO_CATEGORY
  */
 function syncPrivacyContextAction($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);
     }
     $dbCategoryEntry->setPrivacyContext($category->getPrivacyContexts());
     $dbCategoryEntry->save();
 }
 /**
  * Throws an error if trying to update admin only properties with normal user session
  *
  * @param KalturaBaseEntry $entry
  */
 protected function checkAdminOnlyInsertProperties(KalturaBaseEntry $entry)
 {
     if ($entry->adminTags !== null) {
         $this->validateAdminSession("adminTags");
     }
     if ($entry->categories !== null) {
         $cats = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->categories);
         foreach ($cats as $cat) {
             if (!categoryPeer::getByFullNameExactMatch($cat)) {
                 $this->validateAdminSession("categories");
             }
         }
     }
     if ($entry->startDate !== null) {
         $this->validateAdminSession("startDate");
     }
     if ($entry->endDate !== null) {
         $this->validateAdminSession("endDate");
     }
     if ($entry->accessControlId !== null) {
         $this->validateAdminSession("accessControlId");
     }
 }
Exemple #22
0
 /**
  * @return BaseObject
  */
 public function getObject()
 {
     switch ($this->getObjectType()) {
         case BatchJobObjectType::ENTRY:
             entryPeer::setUseCriteriaFilter(false);
             $object = entryPeer::retrieveByPK($this->getObjectId());
             entryPeer::setUseCriteriaFilter(true);
             return $object;
         case BatchJobObjectType::ASSET:
             assetPeer::setUseCriteriaFilter(false);
             $object = assetPeer::retrieveById($this->getObjectId());
             assetPeer::setUseCriteriaFilter(true);
             return $object;
         case BatchJobObjectType::CATEGORY:
             categoryPeer::setUseCriteriaFilter(false);
             $object = categoryPeer::retrieveByPK($this->getObjectId());
             categoryPeer::setUseCriteriaFilter(true);
             return $object;
         case BatchJobObjectType::FILE_SYNC:
             FileSyncPeer::setUseCriteriaFilter(false);
             $object = FileSyncPeer::retrieveByPK($this->getObjectId());
             FileSyncPeer::setUseCriteriaFilter(true);
             return $object;
         default:
             // TODO implement IBatchable in relevant plugins
             return KalturaPluginManager::loadObject('IBatchable', $this->getObjectId());
     }
     return $this->aRootJob;
 }
 /**
  * Convert the categories to categories ids
  * to make search query shorter and to solve search problem when category tree is big.
  *
  *	let's say entry belong to 2 categories with these full_ids
  * 	111>222>333
  *	111>444
  * Old categories fields was: 
  *	333,444
  * 
  * New categories filed:
  * pc111,p111,pc222,p222,pc333,c333,pc444,c444
  * 
  * so why do we need pc111?
  * If baseEntry->list with filter categoriesMatchOr= "111" you need to search for match pc111
  * 
  * so why do we need p111?
  * If baseEntry->list with filter categoriesMatchOr= "111>" you need to search for match p111
  * 	  
  * @param string $cats Categories full names
  * @param string $statuses comma seperated
  * @return string Categogories indexes ids
  */
 public static function categoryFullNamesToIdsParsed($cats, $statuses = null)
 {
     if ($cats === "") {
         $cats = array();
     } else {
         $cats = explode(",", $cats);
     }
     kArray::trim($cats);
     if ($statuses == null || trim($statuses) == '') {
         $statuses = CategoryEntryStatus::ACTIVE;
     }
     $statuses = explode(',', trim($statuses));
     $categoryFullNamesToIds = array();
     foreach ($cats as $cat) {
         if (substr($cat, -1) == '>') {
             //entries that doesn't belog directly to this category - but only to the sub categories.
             $categorySearchPrefix = entry::CATEGORY_PARENT_SEARCH_PERFIX;
             $cat = substr($cat, 0, strlen($cat) - 1);
         } else {
             //entries that belog directly to this category or to a sub categories.
             $categorySearchPrefix = entry::CATEGORY_OR_PARENT_SEARCH_PERFIX;
         }
         $category = categoryPeer::getByFullNameExactMatch($cat);
         $categoryId = null;
         if (!$category) {
             $categoryId = category::CATEGORY_ID_THAT_DOES_NOT_EXIST;
         } else {
             $categoryId = $category->getId();
         }
         foreach ($statuses as $status) {
             $categoryFullNamesToIds[] = $categorySearchPrefix . $categoryId . entry::CATEGORY_SEARCH_STATUS . $status;
         }
     }
     return implode(",", $categoryFullNamesToIds);
 }
 public function hasPeerFieldName($fieldName)
 {
     if (strpos($fieldName, '.') === false) {
         $fieldName = strtoupper($fieldName);
         $fieldName = "category.{$fieldName}";
     }
     $categoryFields = categoryPeer::getFieldNames(BasePeer::TYPE_COLNAME);
     return in_array($fieldName, $categoryFields);
 }
 /**
  * Copy all memeber from parent category
  * 
  * @action copyFromCategory
  * @param int $categoryId
  */
 public function copyFromCategoryAction($categoryId)
 {
     if (kEntitlementUtils::getEntitlementEnforcement()) {
         throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_USER);
     }
     $categoryDb = categoryPeer::retrieveByPK($categoryId);
     if (!$categoryDb) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $categoryId);
     }
     if ($categoryDb->getParentId() == null) {
         throw new KalturaAPIException(KalturaErrors::CATEGORY_DOES_NOT_HAVE_PARENT_CATEGORY);
     }
     $categoryDb->copyCategoryUsersFromParent($categoryDb->getParentId());
 }
Exemple #26
0
 public static function setDefaultCriteriaFilter()
 {
     if (self::$s_criteria_filter == null) {
         self::$s_criteria_filter = new criteriaFilter();
     }
     $c = KalturaCriteria::create(entryPeer::OM_CLASS);
     $c->addAnd(entryPeer::STATUS, entryStatus::DELETED, Criteria::NOT_EQUAL);
     $critEntitled = null;
     $ks = ks::fromSecureString(kCurrentContext::$ks);
     //when entitlement is enable and admin session or user session with list:* privilege
     if (kEntitlementUtils::getEntitlementEnforcement() && (kCurrentContext::$is_admin_session || !self::$userContentOnly)) {
         $privacyContexts = kEntitlementUtils::getPrivacyContextSearch();
         $critEntitled = $c->getNewCriterion(self::PRIVACY_BY_CONTEXTS, $privacyContexts, KalturaCriteria::IN_LIKE);
         $critEntitled->addTag(KalturaCriterion::TAG_ENTITLEMENT_ENTRY);
         if (kCurrentContext::getCurrentKsKuserId()) {
             //ENTITLED_KUSERS field includes $this->entitledUserEdit, $this->entitledUserEdit, and users on work groups categories.
             $entitledKuserByPrivacyContext = kEntitlementUtils::getEntitledKuserByPrivacyContext();
             $critEntitledKusers = $c->getNewCriterion(self::ENTITLED_KUSERS, $entitledKuserByPrivacyContext, KalturaCriteria::IN_LIKE);
             $critEntitledKusers->addTag(KalturaCriterion::TAG_ENTITLEMENT_ENTRY);
             $categoriesIds = array();
             $categoriesIds = categoryPeer::retrieveEntitledAndNonIndexedByKuser(kCurrentContext::getCurrentKsKuserId(), kConf::get('category_search_limit'));
             if (count($categoriesIds) >= kConf::get('category_search_limit')) {
                 self::$kuserBlongToMoreThanMaxCategoriesForSearch = true;
             }
             if (count($categoriesIds)) {
                 $critCategories = $c->getNewCriterion(self::CATEGORIES_IDS, $categoriesIds, KalturaCriteria::IN_LIKE);
                 $critCategories->addTag(KalturaCriterion::TAG_ENTITLEMENT_ENTRY);
                 $critEntitled->addOr($critCategories);
             }
             $critEntitled->addOr($critEntitledKusers);
         }
         //user should be able to get all entries s\he uploaded - outside the privacy context
         $kuser = kCurrentContext::getCurrentKsKuserId();
         if ($kuser !== 0) {
             $critKuser = $c->getNewCriterion(entryPeer::KUSER_ID, $kuser, Criteria::EQUAL);
             $critKuser->addTag(KalturaCriterion::TAG_ENTITLEMENT_ENTRY);
             $critEntitled->addOr($critKuser);
         }
     } elseif (self::$userContentOnly) {
         $critEntitled = $c->getNewCriterion(entryPeer::KUSER_ID, kCurrentContext::getCurrentKsKuserId(), Criteria::EQUAL);
         $critEntitled->addTag(KalturaCriterion::TAG_WIDGET_SESSION);
     }
     if ($ks && count($ks->getDisableEntitlementForEntry())) {
         $entryCrit = $c->getNewCriterion(entryPeer::ENTRY_ID, $ks->getDisableEntitlementForEntry(), Criteria::IN);
         $entryCrit->addTag(KalturaCriterion::TAG_ENTITLEMENT_ENTRY);
         if ($critEntitled) {
             $critEntitled->addOr($entryCrit);
         } else {
             $critEntitled = $entryCrit;
         }
     }
     if ($critEntitled) {
         $c->addAnd($critEntitled);
     }
     self::$s_criteria_filter->setFilter($c);
 }
Exemple #27
0
ini_set("memory_limit", "256M");
require_once __DIR__ . '/bootstrap.php';
if (!count($argv)) {
    die("No partner_id passed to script!");
}
$partnerId = $argv[1];
var_dump($partnerId);
if (!PartnerPeer::retrieveByPK($partnerId)) {
    die("Please enter a valid partner Id!");
}
$criteria = new Criteria();
$criteria->add(categoryPeer::PARTNER_ID, $partnerId, Criteria::EQUAL);
$criteria->setLimit(1000);
$allCats = categoryPeer::doSelect($criteria);
while (count($allCats)) {
    foreach ($allCats as $categoryDb) {
        /* @var $categoryDb category */
        $categoryDb->reSetEntriesCount();
        $categoryDb->reSetDirectSubCategoriesCount();
        $categoryDb->reSetDirectEntriesCount();
        $categoryDb->reSetPendingEntriesCount();
        $categoryDb->reSetPendingMembersCount();
        $categoryDb->save();
    }
    $criteria->setOffset($criteria->getOffset() + count($allCats));
    kMemoryManager::clearMemory();
    usleep(200);
    $allCats = categoryPeer::doSelect($criteria);
}
KalturaLog::log('Done.');
 public static function copyEntry(entry $entry, Partner $toPartner = null, $dontCopyUsers = false)
 {
     KalturaLog::log("copyEntry - Copying entry [" . $entry->getId() . "] to partner [" . $toPartner->getId() . "]");
     $newEntry = $entry->copy();
     $newEntry->setIntId(null);
     $newEntry->setCategories(null);
     $newEntry->setCategoriesIds(null);
     if ($toPartner instanceof Partner) {
         $newEntry->setPartnerId($toPartner->getId());
         $newEntry->setSubpId($toPartner->getId() * 100);
         $newEntry->setAccessControlId($toPartner->getDefaultAccessControlId());
     }
     $newKuser = null;
     if (!$dontCopyUsers) {
         // copy the kuser (if the same puser id exists its kuser will be used)
         kuserPeer::setUseCriteriaFilter(false);
         $kuser = $entry->getKuser();
         $newKuser = kuserPeer::createKuserForPartner($newEntry->getPartnerId(), $kuser->getPuserId());
         $newEntry->setKuserId($newKuser->getId());
         $newEntry->setCreatorKuserId($newKuser->getId());
         kuserPeer::setUseCriteriaFilter(true);
     }
     // copy the kshow
     kshowPeer::setUseCriteriaFilter(false);
     $kshow = $entry->getKshow();
     if ($kshow) {
         $newKshow = $kshow->copy();
         $newKshow->setIntId(null);
         $newKshow->setPartnerId($toPartner->getId());
         $newKshow->setSubpId($toPartner->getId() * 100);
         if ($newKuser) {
             $newKshow->setProducerId($newKuser->getId());
         }
         $newKshow->save();
         $newEntry->setKshowId($newKshow->getId());
     }
     kshowPeer::setUseCriteriaFilter(true);
     // reset the statistics
     myEntryUtils::resetEntryStatistics($newEntry);
     // set the new partner id into the default category criteria filter
     $defaultCategoryFilter = categoryPeer::getCriteriaFilter()->getFilter();
     $oldPartnerId = $defaultCategoryFilter->get(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     // save the entry
     $newEntry->save();
     // restore the original partner id in the default category criteria filter
     $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID);
     $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $oldPartnerId);
     KalturaLog::log("copyEntry - New entry [" . $newEntry->getId() . "] was created");
     if ($entry->getStatus() != entryStatus::READY) {
         $clonePendingEntries = $entry->getClonePendingEntries();
         $clonePendingEntries[] = $newEntry->getId();
         $entry->setClonePendingEntries($clonePendingEntries);
         $entry->save();
     } else {
         self::copyEntryData($entry, $newEntry);
     }
     //if entry is a static playlist, link between it and its new child entries
     if ($entry->getType() == entryType::PLAYLIST) {
         switch ($entry->getMediaType()) {
             case entry::ENTRY_MEDIA_TYPE_TEXT:
                 $from = $entry->getDataContent();
                 KalturaLog::debug("Entries to copy from source static playlist: [{$from}]");
                 $fromEntryIds = explode(",", $from);
                 $toEntryIds = array();
                 foreach ($fromEntryIds as $fromEntryId) {
                     $toEntryIds[] = kObjectCopyHandler::getMappedId(entryPeer::OM_CLASS, $fromEntryId);
                 }
                 $newEntry->setDataContent(implode(",", $toEntryIds));
                 break;
             case entry::ENTRY_MEDIA_TYPE_XML:
                 list($totalResults, $fromFiltersList) = myPlaylistUtils::getPlaylistFilterListStruct($entry->getDataContent());
                 $toPlaylistXml = new SimpleXMLElement("<playlist/>");
                 $toPlaylistXml->addChild("total_results", $totalResults);
                 $toFiltersXml = $toPlaylistXml->addChild("filters");
                 foreach ($fromFiltersList as $filterXML) {
                     $entryFilter = new entryFilter();
                     $entryFilter->fillObjectFromXml($filterXML, "_");
                     if (isset($entryFilter->fields["_matchand_categories_ids"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_matchand_categories_ids"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_matchand_categories_ids"] = implode(",", $newCategoriesIds);
                     }
                     if (isset($entryFilter->fields["_matchor_categories_ids"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_matchor_categories_ids"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_matchor_categories_ids"] = implode(",", $newCategoriesIds);
                     }
                     if (isset($entryFilter->fields["_in_category_ancestor_id"])) {
                         $categoriesIds = explode(",", $entryFilter->fields["_in_category_ancestor_id"]);
                         $newCategoriesIds = array();
                         foreach ($categoriesIds as $categoryId) {
                             $newCategoriesIds[] = kObjectCopyHandler::getMappedId(categoryPeer::OM_CLASS, $categoryId);
                         }
                         $entryFilter->fields["_in_category_ancestor_id"] = implode(",", $newCategoriesIds);
                     }
                     $toEntryFilterXML = $toFiltersXml->addChild("filter");
                     $toEntryFilterXML = $entryFilter->toXml($toEntryFilterXML);
                 }
                 $newEntry->setDataContent($toPlaylistXml->asXML());
                 break;
         }
     }
     // copy relationships to categories
     KalturaLog::debug('Copy relationships to categories from entry [' . $entry->getId() . '] to entry [' . $newEntry->getId() . ']');
     $c = KalturaCriteria::create(categoryEntryPeer::OM_CLASS);
     $c->addAnd(categoryEntryPeer::ENTRY_ID, $entry->getId());
     $c->addAnd(categoryEntryPeer::STATUS, CategoryEntryStatus::ACTIVE, Criteria::EQUAL);
     $c->addAnd(categoryEntryPeer::PARTNER_ID, $entry->getPartnerId());
     categoryEntryPeer::setUseCriteriaFilter(false);
     $categoryEntries = categoryEntryPeer::doSelect($c);
     categoryEntryPeer::setUseCriteriaFilter(true);
     // Create srcCategoryIdToDstCategoryIdMap - a map of source partner category ids -> dst. partner category ids
     //
     // Build src category IDs set
     $srcCategoryIdSet = array();
     foreach ($categoryEntries as $categoryEntry) {
         $srcCategoryIdSet[] = $categoryEntry->getCategoryId();
     }
     $illegalCategoryStatus = array(CategoryStatus::DELETED, CategoryStatus::PURGED);
     // Get src category objects
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::ID, $srcCategoryIdSet, Criteria::IN);
     $c->addAnd(categoryPeer::PARTNER_ID, $entry->getPartnerId());
     $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN);
     categoryPeer::setUseCriteriaFilter(false);
     $srcCategories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     // Map the category names to their IDs
     $fullNamesToSrcCategoryIdMap = array();
     foreach ($srcCategories as $category) {
         $fullNamesToSrcCategoryIdMap[$category->getFullName()] = $category->getId();
     }
     // Get dst. partner categories based on src. category full-names
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::FULL_NAME, array_keys($fullNamesToSrcCategoryIdMap), KalturaCriteria::IN);
     $c->addAnd(categoryPeer::PARTNER_ID, $newEntry->getPartnerId());
     $c->addAnd(categoryPeer::STATUS, $illegalCategoryStatus, Criteria::NOT_IN);
     categoryPeer::setUseCriteriaFilter(false);
     $dstCategories = categoryPeer::doSelect($c);
     categoryPeer::setUseCriteriaFilter(true);
     $srcCategoryIdToDstCategoryIdMap = array();
     foreach ($dstCategories as $dstCategory) {
         $fullName = $dstCategory->getFullName();
         if (array_key_exists($fullName, $fullNamesToSrcCategoryIdMap)) {
             $srcCategoryId = $fullNamesToSrcCategoryIdMap[$fullName];
             $srcCategoryIdToDstCategoryIdMap[$srcCategoryId] = $dstCategory->getId();
         }
     }
     foreach ($categoryEntries as $categoryEntry) {
         /* @var $categoryEntry categoryEntry */
         $newCategoryEntry = $categoryEntry->copy();
         $newCategoryEntry->setPartnerId($newEntry->getPartnerId());
         $newCategoryEntry->setEntryId($newEntry->getId());
         $srcCategoryId = $categoryEntry->getCategoryId();
         if (!array_key_exists($srcCategoryId, $srcCategoryIdToDstCategoryIdMap)) {
             continue;
             // Skip the category_entry's creation
         }
         $dstCategoryId = $srcCategoryIdToDstCategoryIdMap[$srcCategoryId];
         $newCategoryEntry->setCategoryId($dstCategoryId);
         categoryPeer::setUseCriteriaFilter(false);
         entryPeer::setUseCriteriaFilter(false);
         $newCategoryEntry->save();
         entryPeer::setUseCriteriaFilter(true);
         categoryPeer::setUseCriteriaFilter(true);
     }
     return $newEntry;
 }
Exemple #29
0
 public function getEntitledKusers()
 {
     $entitledKusersPublish = explode(',', $this->getEntitledKusersPublish());
     $entitledKusersEdit = explode(',', $this->getEntitledKusersEdit());
     $entitledKusersNoPrivacyContext = array_merge($entitledKusersPublish, $entitledKusersEdit);
     $entitledKusersNoPrivacyContext[] = $this->getKuserId();
     foreach ($entitledKusersNoPrivacyContext as $key => $value) {
         if (!$value) {
             unset($entitledKusersNoPrivacyContext[$key]);
         }
     }
     $entitledKusers = array();
     if (count(array_unique($entitledKusersNoPrivacyContext))) {
         $entitledKusers[kEntitlementUtils::ENTRY_PRIVACY_CONTEXT] = array_unique($entitledKusersNoPrivacyContext);
     }
     $allCategoriesIds = $this->getAllCategoriesIds(true);
     if (!count($allCategoriesIds)) {
         return kEntitlementUtils::ENTRY_PRIVACY_CONTEXT . '_' . implode(' ' . kEntitlementUtils::ENTRY_PRIVACY_CONTEXT . '_', $entitledKusersNoPrivacyContext);
     }
     $categoryGroupSize = kConf::get('max_number_of_memebrs_to_be_indexed_on_entry');
     $partner = $this->getPartner();
     if ($partner && $partner->getCategoryGroupSize()) {
         $categoryGroupSize = $partner->getCategoryGroupSize();
     }
     //get categories for this entry that have small amount of members.
     $c = KalturaCriteria::create(categoryPeer::OM_CLASS);
     $c->add(categoryPeer::ID, $allCategoriesIds, Criteria::IN);
     $c->add(categoryPeer::MEMBERS_COUNT, $categoryGroupSize, Criteria::LESS_EQUAL);
     $c->add(categoryPeer::ENTRIES_COUNT, kConf::get('category_entries_count_limit_to_be_indexed'), Criteria::LESS_EQUAL);
     $c->dontCount();
     KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     $categories = categoryPeer::doSelect($c);
     KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     //get all memebrs
     foreach ($categories as $category) {
         if (!count($category->getMembers())) {
             continue;
         }
         $privacyContexts = explode(',', $category->getPrivacyContexts());
         if (!count($privacyContexts)) {
             $privacyContexts = array(kEntitlementUtils::DEFAULT_CONTEXT . $this->getPartnerId());
         }
         foreach ($privacyContexts as $privacyContext) {
             $privacyContext = trim($privacyContext);
             if (isset($entitledKusers[$privacyContext])) {
                 $entitledKusers[$privacyContext] = array_merge($entitledKusers[$privacyContext], $category->getMembers());
             } else {
                 $entitledKusers[$privacyContext] = $category->getMembers();
             }
         }
     }
     $entitledKusersByContexts = array();
     foreach ($entitledKusers as $privacyContext => $kusers) {
         $entitledKusersByContexts[] = $privacyContext . '_' . implode(' ' . $privacyContext . '_', $kusers);
     }
     return implode(' ', $entitledKusersByContexts);
 }
Exemple #30
0
 /**
  * Convert the categories to categories ids
  * to make search query shorter and to solve search problem when category tree is big.
  *
  *	let's say entry belong to 2 categories with these full_ids
  * 	111>222>333
  *	111>444
  * Old categories fields was: 
  *	333,444
  * 
  * New categories filed:
  * pc111,p111,pc222,p222,pc333,c333,pc444,c444
  * 
  * so why do we need pc111?
  * If baseEntry->list with filter categoriesMatchOr= "111" you need to search for match pc111
  * 
  * so why do we need p111?
  * If baseEntry->list with filter categoriesMatchOr= "111>" you need to search for match p111
  * 	  
  * @param string $cats Categories full names
  * @param string $statuses comma seperated statuses.null = no status filtering (default criteria still applies)
  * @return string Categogories indexes ids
  */
 public static function categoryFullNamesToIdsParsed($cats, $commaSeparatedStatuses = null)
 {
     if ($cats === "") {
         $cats = array();
     } else {
         $cats = explode(",", $cats);
     }
     kArray::trim($cats);
     $commaSeparatedStatuses = trim($commaSeparatedStatuses);
     if (empty($commaSeparatedStatuses)) {
         $statuses = null;
     } else {
         $statuses = explode(",", $commaSeparatedStatuses);
     }
     $categoryFullNamesToIds = array();
     foreach ($cats as $cat) {
         if (substr($cat, -1) == '>') {
             //entries that doesn't belog directly to this category - but only to the sub categories.
             $categorySearchPrefix = entry::CATEGORY_PARENT_SEARCH_PERFIX;
             $cat = substr($cat, 0, strlen($cat) - 1);
         } else {
             //entries that belog directly to this category or to a sub categories.
             $categorySearchPrefix = entry::CATEGORY_OR_PARENT_SEARCH_PERFIX;
         }
         $category = categoryPeer::getByFullNameExactMatch($cat);
         $categoryId = null;
         if (!$category) {
             $categoryId = category::CATEGORY_ID_THAT_DOES_NOT_EXIST;
         } else {
             $categoryId = $category->getId();
         }
         if ($statuses) {
             foreach ($statuses as $status) {
                 $categoryFullNamesToIds[] = $categorySearchPrefix . $categoryId . entry::CATEGORY_SEARCH_STATUS . $status;
             }
         } else {
             $categoryFullNamesToIds[] = $categoryId;
             // The cat. id AS-IS, no status filtering applied
         }
     }
     return implode(",", $categoryFullNamesToIds);
 }