public function syncCategoryEntries(entry $vodEntry, LiveEntry $liveEntry) { $liveCategoryEntryArray = categoryEntryPeer::selectByEntryId($liveEntry->getId()); if (!count($liveCategoryEntryArray)) { return; } foreach ($liveCategoryEntryArray as $categoryEntry) { /* @var $categoryEntry categoryEntry */ $vodCategoryEntry = $categoryEntry->copy(); $vodCategoryEntry->setEntryId($vodEntry->getId()); $vodCategoryEntry->save(); } }
/** * 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::retrieveByCategoryIdAndActiveKuserId($categoryId, kCurrentContext::$ks_kuser_id); 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(); }
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; }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = new Criteria(categoryEntryPeer::DATABASE_NAME); $criteria->add(categoryEntryPeer::ID, $this->id); if ($this->alreadyInSave) { if ($this->isColumnModified(categoryEntryPeer::CUSTOM_DATA)) { if (!is_null($this->custom_data_md5)) { $criteria->add(categoryEntryPeer::CUSTOM_DATA, "MD5(cast(" . categoryEntryPeer::CUSTOM_DATA . " as char character set latin1)) = '{$this->custom_data_md5}'", Criteria::CUSTOM); } else { $criteria->add(categoryEntryPeer::CUSTOM_DATA, NULL, Criteria::ISNULL); } } if (count($this->modifiedColumns) == 2 && $this->isColumnModified(categoryEntryPeer::UPDATED_AT)) { $theModifiedColumn = null; foreach ($this->modifiedColumns as $modifiedColumn) { if ($modifiedColumn != categoryEntryPeer::UPDATED_AT) { $theModifiedColumn = $modifiedColumn; } } $atomicColumns = categoryEntryPeer::getAtomicColumns(); if (in_array($theModifiedColumn, $atomicColumns)) { $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL); } } } return $criteria; }
public function getFieldNameFromPeer($field_name) { $res = categoryEntryPeer::translateFieldName($field_name, $this->field_name_translation_type, BasePeer::TYPE_COLNAME); return $res; }
/** * @param entry $entry */ protected function entryDeleted(entry $entry) { $this->syncableDeleted($entry->getId(), FileSyncObjectType::ENTRY); // delete flavor assets $c = new Criteria(); $c->add(assetPeer::ENTRY_ID, $entry->getId()); $c->add(assetPeer::STATUS, asset::FLAVOR_ASSET_STATUS_DELETED, Criteria::NOT_EQUAL); $c->add(assetPeer::DELETED_AT, null, Criteria::ISNULL); $assets = assetPeer::doSelect($c); foreach ($assets as $asset) { $asset->setStatus(asset::FLAVOR_ASSET_STATUS_DELETED); $asset->setDeletedAt(time()); $asset->save(); } $c = new Criteria(); $c->add(assetParamsOutputPeer::ENTRY_ID, $entry->getId()); $c->add(assetParamsOutputPeer::DELETED_AT, null, Criteria::ISNULL); $flavorParamsOutputs = assetParamsOutputPeer::doSelect($c); foreach ($flavorParamsOutputs as $flavorParamsOutput) { $flavorParamsOutput->setDeletedAt(time()); $flavorParamsOutput->save(); } $filter = new categoryEntryFilter(); $filter->setEntryIdEqual($entry->getId()); $c = new Criteria(); $c->add(categoryEntryPeer::ENTRY_ID, $entry->getId()); if (!categoryEntryPeer::doSelectOne($c)) { return; } kJobsManager::addDeleteJob($entry->getPartnerId(), DeleteObjectType::CATEGORY_ENTRY, $filter); }
public static function copyTemplateContent(Partner $fromPartner, Partner $toPartner, $dontCopyUsers = false) { kEventsManager::enableDeferredEvents(false); $partnerCustomDataArray = $fromPartner->getCustomDataObj()->toArray(); $excludeCustomDataFields = kConf::get('template_partner_custom_data_exclude_fields'); foreach ($partnerCustomDataArray as $customDataName => $customDataValue) { if (!in_array($customDataName, $excludeCustomDataFields)) { $toPartner->putInCustomData($customDataName, $customDataValue); } } $toPartner->save(); // copy permssions before trying to copy additional objects such as distribution profiles which are not enabled yet for the partner self::copyPermissions($fromPartner, $toPartner); self::copyUserRoles($fromPartner, $toPartner); kEventsManager::raiseEvent(new kObjectCopiedEvent($fromPartner, $toPartner)); self::copyAccessControls($fromPartner, $toPartner); self::copyFlavorParams($fromPartner, $toPartner); self::copyConversionProfiles($fromPartner, $toPartner); categoryEntryPeer::setUseCriteriaFilter(false); self::copyCategories($fromPartner, $toPartner); self::copyEntriesByType($fromPartner, $toPartner, entryType::MEDIA_CLIP, $dontCopyUsers); self::copyEntriesByType($fromPartner, $toPartner, entryType::PLAYLIST, $dontCopyUsers); categoryEntryPeer::setUseCriteriaFilter(true); self::copyUiConfsByType($fromPartner, $toPartner, uiConf::UI_CONF_TYPE_WIDGET); self::copyUiConfsByType($fromPartner, $toPartner, uiConf::UI_CONF_TYPE_KDP3); kEventsManager::enableDeferredEvents(true); }
/** * Clone an entry with optional attributes to apply to the clone * * @action clone * @param string $entryId Id of entry to clone * @param KalturaBaseEntry $updateEntry [optional] Attributes from these entry will be updated into the cloned entry * @return KalturaBaseEntry The cloned entry * @throws KalturaErrors::ENTRY_ID_NOT_FOUND */ function cloneAction($entryId) { // Reset criteria filters such that it will be entryPeer::setUseCriteriaFilter(false); categoryEntryPeer::setUseCriteriaFilter(false); // Get the entry $coreEntry = entryPeer::retrieveByPK($entryId); if (!$coreEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } // Copy the entry into a new one based on the given partner data. $clonedEntry = myEntryUtils::copyEntry($coreEntry, $this->getPartner()); return $this->getEntry($clonedEntry->getId()); }
public function objectCopied(BaseObject $fromObject, BaseObject $toObject) { if ($fromObject instanceof asset) { self::mapIds('asset', $fromObject->getId(), $toObject->getId()); $flavorParamsId = self::getMappedId('assetParams', $fromObject->getFlavorParamsId()); if ($flavorParamsId) { $toObject->setFlavorParamsId($flavorParamsId); $toObject->save(); } } elseif ($fromObject instanceof assetParams) { self::mapIds('assetParams', $fromObject->getId(), $toObject->getId()); } elseif ($fromObject instanceof assetParamsOutput) { self::mapIds('assetParamsOutput', $fromObject->getId(), $toObject->getId()); $flavorParamsId = self::getMappedId('assetParams', $fromObject->getFlavorParamsId()); if ($flavorParamsId) { $toObject->setFlavorParamsId($flavorParamsId); $toObject->save(); } } else { self::mapIds(get_class($fromObject), $fromObject->getId(), $toObject->getId()); } if ($fromObject instanceof uiConf) { $this->uiConfCopied($fromObject, $toObject); } if ($fromObject instanceof category && $fromObject->getParentId()) { $parentId = self::getMappedId('category', $fromObject->getParentId()); if ($parentId) { $toObject->setParentId($parentId); $toObject->save(); } } if ($fromObject instanceof entry) { $conversionProfileId = self::getMappedId('conversionProfile2', $fromObject->getConversionProfileId()); if ($conversionProfileId) { $toObject->setConversionProfileId($conversionProfileId); $toObject->save(); } $accessControlId = self::getMappedId('accessControl', $fromObject->getAccessControlId()); if ($accessControlId) { $toObject->setAccessControlId($accessControlId); $toObject->save(); } if ($toObject->getPartnerId() == $fromObject->getPartnerId()) { $categoryEntriesObjects = categoryEntryPeer::retrieveActiveByEntryId($fromObject->getId()); $categoryIds = array(); foreach ($categoryEntriesObjects as $categoryEntryObject) { /* @var $categoryEntry categoryEntry */ $categoryIds[] = $categoryEntryObject->getCategoryId(); } if (count($categoryIds)) { $categories = categoryPeer::retrieveByPKs($categoryIds); //which will return only the entiteled ones foreach ($categories as $category) { /* @var $category category */ $categoryEntry = new categoryEntry(); $categoryEntry->setEntryId($toObject->getId()); $categoryEntry->setCategoryId($category->getId()); $categoryEntry->setStatus(CategoryEntryStatus::ACTIVE); $categoryEntry->setPartnerId($toObject->getPartnerId()); $categoryEntry->save(); } } } } return true; }
private static function getPrivacyContextsByCategoryEntries(entry $entry) { $defaultPrivacyContext = self::DEFAULT_CONTEXT . $entry->getPartnerId(); $privacyContexts = array(); $categoriesIds = array(); //get category entries that have privacy context $categoryEntries = categoryEntryPeer::retrieveByEntryIdStatusPrivacyContextExistance($entry->getId(), null, true); foreach ($categoryEntries as $categoryEntry) { $categoriesIds[] = $categoryEntry->getCategoryId(); } $categories = self::getCategoriesByIds($categoriesIds); foreach ($categories as $category) { $categoryPrivacy = $category->getPrivacy(); $categoryPrivacyContext = $category->getPrivacyContexts(); if (!isset($privacyContexts[$categoryPrivacyContext]) || $privacyContexts[$categoryPrivacyContext] > $categoryPrivacy) { $privacyContexts[trim($categoryPrivacyContext)] = $categoryPrivacy; } } $noPrivacyContextCategory = categoryEntryPeer::retrieveOneByEntryIdStatusPrivacyContextExistance($entry->getId()); if ($noPrivacyContextCategory) { $privacyContexts[$defaultPrivacyContext] = PrivacyType::ALL; } return $privacyContexts; }
public function objectChanged(BaseObject $object, array $modifiedColumns) { $privacyContexts = null; if ($object instanceof entry) { $criteria = new Criteria(); $criteria->add(categoryEntryPeer::ENTRY_ID, $object->getId()); $categoryEntries = categoryEntryPeer::doSelect($criteria); $privacyContexts = array(self::NULL_PC); if (count($categoryEntries)) { foreach ($categoryEntries as $categoryEntry) { /* @var $categoryEntry categoryEntry */ if ($categoryEntry->getPrivacyContext() != "") { $privacyContexts = array_merge($privacyContexts, self::trimObjectTags($categoryEntry->getPrivacyContext())); } else { $privacyContexts[] = kEntitlementUtils::DEFAULT_CONTEXT; } } $privacyContexts = array_unique($privacyContexts); } } $oldTags = $object->getColumnsOldValue(self::getClassConstValue(get_class($object->getPeer()), self::TAGS_FIELD_NAME)); $newTags = $object->getTags(); $tagsForDelete = implode(',', array_diff(explode(',', $oldTags), explode(',', $newTags))); $tagsForUpdate = implode(',', array_diff(explode(',', $newTags), explode(',', $oldTags))); if ($oldTags && $oldTags != "") { self::decrementExistingTagsInstanceCount($tagsForDelete, $object->getPartnerId(), get_class($object), $privacyContexts); } self::addOrIncrementTags($tagsForUpdate, $object->getPartnerId(), get_class($object), $privacyContexts); }
/** * Clone an entry with optional attributes to apply to the clone * * @action clone * @param string $entryId Id of entry to clone * @param KalturaBaseEntryCloneOptionsArray $cloneOptions * @param KalturaBaseEntry $updateEntry [optional] Attributes from these entry will be updated into the cloned entry * @return KalturaBaseEntry The cloned entry * @throws KalturaErrors::ENTRY_ID_NOT_FOUND */ public function cloneAction($entryId, $cloneOptions = null) { // Reset criteria filters such that it will be entryPeer::setUseCriteriaFilter(false); categoryEntryPeer::setUseCriteriaFilter(false); // Get the entry $coreEntry = entryPeer::retrieveByPK($entryId); if (!$coreEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } // $coreClonedOptionsArray = array(); // foreach ($cloneOptions as $item) // { // $coreClonedOptionsArray[] = $item->toObject(); // } $coreClonedOptionsArray = $cloneOptions->toObjectsArray(); // Copy the entry into a new one based on the given partner data. $clonedEntry = myEntryUtils::copyEntry($coreEntry, $this->getPartner(), $coreClonedOptionsArray); return $this->getEntry($clonedEntry->getId()); }
public function getObject() { //TODO: check how to get deleted return categoryEntryPeer::retrieveByPK($this->getObjectId()); }
private function setAllTemplateEntriesToAdminKuser($partnerId, $kuserId) { $c = new Criteria(); $c->addAnd(entryPeer::PARTNER_ID, $partnerId, Criteria::EQUAL); entryPeer::setUseCriteriaFilter(false); $allEntries = entryPeer::doSelect($c); entryPeer::setUseCriteriaFilter(true); // set the new partner id into the default category criteria filter $defaultCategoryFilter = categoryPeer::getCriteriaFilter()->getFilter(); $oldPartnerIdCategory = $defaultCategoryFilter->get(categoryPeer::PARTNER_ID); $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID); $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $partnerId); // set the new partner id into the default category criteria filter $defaultCategoryEntryFilter = categoryEntryPeer::getCriteriaFilter()->getFilter(); $oldPartnerIdCategoryEntry = $defaultCategoryFilter->get(categoryEntryPeer::PARTNER_ID); $defaultCategoryEntryFilter->remove(categoryEntryPeer::PARTNER_ID); $defaultCategoryEntryFilter->addAnd(categoryEntryPeer::PARTNER_ID, $partnerId); foreach ($allEntries as $entry) { $entry->setKuserId($kuserId); $entry->setCreatorKuserId($kuserId); $entry->save(); } kEventsManager::flushEvents(); // restore the original partner id in the default category criteria filter $defaultCategoryFilter->remove(categoryPeer::PARTNER_ID); $defaultCategoryFilter->addAnd(categoryPeer::PARTNER_ID, $oldPartnerIdCategory); $defaultCategoryEntryFilter->remove(categoryEntryPeer::PARTNER_ID); $defaultCategoryEntryFilter->addAnd(categoryEntryPeer::PARTNER_ID, $oldPartnerIdCategoryEntry); }
/** * reset category's directEntriesCount by calculate it. */ public function reSetDirectEntriesCount() { $criteria = KalturaCriteria::create(categoryEntryPeer::OM_CLASS); $criteria->addAnd(categoryEntryPeer::CATEGORY_ID, $this->getId()); $count = categoryEntryPeer::doCount($criteria); $this->setDirectEntriesCount($count); }
/** * reset category's pendingEntriesCount by calculate it. */ public function reSetPendingEntriesCount() { $criteria = new Criteria(); $criteria->add(categoryEntryPeer::CATEGORY_ID, $this->getId()); $criteria->add(categoryEntryPeer::STATUS, CategoryEntryStatus::PENDING); $count = categoryEntryPeer::doCount($criteria); $this->setPendingEntriesCount($count); }
private function setEntryOnCategory(category $category, $entry = null) { $category->incrementEntriesCount($this->getEntryId()); $category->incrementDirectEntriesCount($this->getEntryId()); //if was pending - decrease pending entries count! if ($this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) { $category->decrementPendingEntriesCount(); } $category->save(); //only categories with no context are saved on entry - this is only for Backward compatible if ($entry && !categoryEntryPeer::getSkipSave() && (trim($category->getPrivacyContexts()) == '' || $category->getPrivacyContexts() == null)) { $categories = array(); if (trim($entry->getCategories()) != '') { $categories = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategories()); } $categories[] = $category->getFullName(); $categoriesIds = array(); if (trim($entry->getCategoriesIds()) != '') { $categoriesIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategoriesIds()); } $categoriesIds[] = $category->getId(); $entry->parentSetCategories(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categories)); $entry->parentSetCategoriesIds(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categoriesIds)); $entry->justSave(); } return $entry; }
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"); // for any type that does not require assets: $shouldCopyDataForNonClip = true; if ($entry->getType() == entryType::MEDIA_CLIP) { $shouldCopyDataForNonClip = false; } if ($entry->getType() == entryType::PLAYLIST) { $shouldCopyDataForNonClip = false; } $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 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; } } 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 $sourceAssets = assetPeer::retrieveByEntryId($entry->getId()); foreach ($sourceAssets as $sourceAsset) { $sourceAsset->copyToEntry($newEntry->getId(), $newEntry->getPartnerId()); } // 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; }
/** * @action indexCategoryEntryTags * * @param int $categoryId * @param string $pcToDecrement * @param string $pcToIncrement */ public function indexCategoryEntryTagsAction($categoryId, $pcToDecrement, $pcToIncrement) { $pcToDecrementArray = explode(',', $pcToDecrement); $c = KalturaCriteria::create(TagPeer::OM_CLASS); $c->add(TagPeer::PARTNER_ID, kCurrentContext::getCurrentPartnerId()); $c->add(TagPeer::PRIVACY_CONTEXT, $pcToDecrementArray, KalturaCriteria::IN); TagPeer::setUseCriteriaFilter(false); $tagsToDecrement = TagPeer::doSelect($c); TagPeer::setUseCriteriaFilter(true); foreach ($tagsToDecrement as $tag) { /* @var $tag Tag */ $tag->decrementInstanceCount(); } $pcToIncrementArray = explode(',', $pcToIncrement); $tagsToIncrement = array(); $c = new Criteria(); $c->add(categoryEntryPeer::CATEGORY_ID, $categoryId); $catEntries = categoryEntryPeer::doSelect($c); foreach ($catEntries as $catEntry) { /* @var $catEntry categoryEntry */ $entry = entryPeer::retrieveByPK($catEntry->getEntryId()); if ($entry) { $tagsToIncrement = array_merge($tagsToIncrement, explode(',', $entry->getTags())); } } $tagsToIncrement = array_unique($tagsToIncrement); kTagFlowManager::addOrIncrementTags(implode(",", $tagsToIncrement), kCurrentContext::getCurrentPartnerId(), "entry", $pcToIncrementArray); }
/** * @param entry $entry * @param SimpleXMLElement $mrss * @param kMrssParameters $mrssParams * @params string $features * @return SimpleXMLElement */ public static function getEntryMrssXml(entry $entry, SimpleXMLElement $mrss = null, kMrssParameters $mrssParams = null, $features = null) { $instanceKey = self::generateInstanceKey($entry->getId(), $mrssParams, $features); if (is_null($mrss)) { $mrss = self::getInstanceFromPool($instanceKey); if ($mrss) { return $mrss; } $encoding = 'UTF-8'; if ($mrssParams && !is_null($mrssParams->getEncoding())) { $encoding = $mrssParams->getEncoding(); } if ($encoding) { $mrss = new SimpleXMLElement('<?xml version="1.0" encoding="' . $encoding . '"?><item/>'); } else { $mrss = new SimpleXMLElement('<item/>'); } } $mrss->addChild('entryId', $entry->getId()); if ($entry->getReferenceID()) { $mrss->addChild('referenceID', self::stringToSafeXml($entry->getReferenceID())); } $mrss->addChild('createdAt', $entry->getCreatedAt(null)); $mrss->addChild('updatedAt', $entry->getUpdatedAt(null)); $mrss->addChild('title', self::stringToSafeXml($entry->getName())); if ($mrssParams && !is_null($mrssParams->getLink())) { $mrss->addChild('link', $mrssParams->getLink() . $entry->getId()); } $mrss->addChild('type', $entry->getType()); $mrss->addChild('licenseType', $entry->getLicenseType()); $mrss->addChild('userId', $entry->getPuserId()); $mrss->addChild('name', self::stringToSafeXml($entry->getName())); $mrss->addChild('status', self::stringToSafeXml($entry->getStatus())); $mrss->addChild('description', self::stringToSafeXml($entry->getDescription())); $thumbnailUrl = $mrss->addChild('thumbnailUrl'); $thumbnailUrl->addAttribute('url', $entry->getThumbnailUrl()); if (trim($entry->getTags(), " \r\n\t")) { $tags = $mrss->addChild('tags'); foreach (explode(',', $entry->getTags()) as $tag) { $tags->addChild('tag', self::stringToSafeXml($tag)); } } $categories = explode(',', $entry->getCategories()); if (count($features) && in_array(ObjectFeatureType::CATEGORY_ENTRIES, $features)) { $partner = PartnerPeer::retrieveByPK(kCurrentContext::getCurrentPartnerId()); $partnerEntitlement = $partner->getDefaultEntitlementEnforcement(); kEntitlementUtils::initEntitlementEnforcement($partner->getId(), false); $categories = array(); $categoryEntries = categoryEntryPeer::retrieveActiveByEntryId($entry->getId()); $categoryIds = array(); foreach ($categoryEntries as $categoryEntry) { $categoryIds[] = $categoryEntry->getCategoryId(); } $entryCats = categoryPeer::retrieveByPKs($categoryIds); foreach ($entryCats as $entryCat) { $categories[] = $entryCat->getFullName(); } if ($partnerEntitlement) { kEntitlementUtils::initEntitlementEnforcement($partner->getId(), true); } $keyToDelete = array_search(ObjectFeatureType::CATEGORY_ENTRIES, $features); unset($features[$keyToDelete]); } foreach ($categories as $category) { $category = trim($category); if ($category) { $categoryNode = $mrss->addChild('category', self::stringToSafeXml($category)); if (strrpos($category, '>') > 0) { $categoryNode->addAttribute('name', self::stringToSafeXml(substr($category, strrpos($category, '>') + 1))); } else { $categoryNode->addAttribute('name', self::stringToSafeXml($category)); } } } $mrss->addChild('partnerData', self::stringToSafeXml($entry->getPartnerData())); if ($entry->getAccessControlId()) { $mrss->addChild('accessControlId', $entry->getAccessControlId()); } if ($entry->getConversionProfileId()) { $mrss->addChild('conversionProfileId', $entry->getConversionProfileId()); } if ($entry->getStartDate(null)) { $mrss->addChild('startDate', $entry->getStartDate(null)); } if ($entry->getEndDate(null)) { $mrss->addChild('endDate', $entry->getEndDate(null)); } switch ($entry->getType()) { case entryType::MEDIA_CLIP: self::appendMediaEntryMrss($entry, $mrss); break; case entryType::MIX: self::appendMixEntryMrss($entry, $mrss); break; case entryType::PLAYLIST: self::appendPlaylistEntryMrss($entry, $mrss); break; case entryType::DATA: self::appendDataEntryMrss($entry, $mrss); break; case entryType::LIVE_STREAM: self::appendLiveStreamEntryMrss($entry, $mrss); break; default: break; } $assetsStatuses = array(asset::ASSET_STATUS_READY); if ($mrssParams && $mrssParams->getStatuses()) { $assetsStatuses = $mrssParams->getStatuses(); } $assets = assetPeer::retrieveReadyByEntryId($entry->getId(), null, $assetsStatuses); foreach ($assets as $asset) { if ($mrssParams && !is_null($mrssParams->getFilterByFlavorParams()) && $asset->getFlavorParamsId() != $mrssParams->getFilterByFlavorParams()) { continue; } if ($asset instanceof flavorAsset) { self::appendFlavorAssetMrss($asset, $mrss, $mrssParams); } if ($asset instanceof thumbAsset) { self::appendThumbAssetMrss($asset, $mrss); } } $mrssContributors = self::getMrssContributors(); if (count($mrssContributors)) { foreach ($mrssContributors as $mrssContributor) { try { if (!count($features) || in_array($mrssContributor->getObjectFeatureType(), $features)) { $mrssContributor->contribute($entry, $mrss, $mrssParams); } } catch (kCoreException $ex) { KalturaLog::err("Unable to add MRSS element for contributor [" . get_class($mrssContributor) . "] message [" . $ex->getMessage() . "]"); } } } if ($mrssParams && $mrssParams->getIncludePlayerTag()) { $uiconfId = !is_null($mrssParams->getPlayerUiconfId()) ? '/ui_conf_id/' . $mrssParams->getPlayerUiconfId() : ''; $playerUrl = kConf::get('apphome_url') . '/kwidget/wid/_' . $entry->getPartnerId() . '/entry_id/' . $entry->getId() . '/ui_conf' . ($uiconfId ? "/{$uiconfId}" : ''); $player = $mrss->addChild('player'); $player->addAttribute('url', $playerUrl); } if ($mrssParams && $mrssParams->getItemXpathsToExtend()) { self::addExtendingItemsToMrss($mrss, $mrssParams); } self::addInstanceToPool($instanceKey, $mrss); return $mrss; }
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; }
private function setEntryOnCategory(category $category, $entry = null) { if (is_null($this->entryCategoriesAddedIds)) { $categoriesEntries = categoryEntryPeer::retrieveActiveByEntryId($this->getEntryId()); $categoriesIds = array(); foreach ($categoriesEntries as $categroyEntry) { //cannot get directly the full ids - since it might not be updated. if ($categroyEntry->getCategoryId() != $this->getCategoryId()) { $categoriesIds[] = $categroyEntry->getCategoryId(); } } $categoriesAdded = categoryPeer::retrieveByPKs($categoriesIds); $entryCategoriesAddedIds = array(); foreach ($categoriesAdded as $categoryAdded) { $fullIds = explode(categoryPeer::CATEGORY_SEPARATOR, $categoryAdded->getFullIds()); $entryCategoriesAddedIds = array_merge($entryCategoriesAddedIds, $fullIds); } $this->entryCategoriesAddedIds = $entryCategoriesAddedIds; } $category->incrementEntriesCount(1, $this->entryCategoriesAddedIds); $category->incrementDirectEntriesCount(); //if was pending - decrease pending entries count! if ($this->getColumnsOldValue(categoryEntryPeer::STATUS) == CategoryEntryStatus::PENDING) { $category->decrementPendingEntriesCount(); } $category->save(); //only categories with no context are saved on entry - this is only for Backward compatible if ($entry && !categoryEntryPeer::getSkipSave() && (trim($category->getPrivacyContexts()) == '' || $category->getPrivacyContexts() == null)) { $categories = array(); if (trim($entry->getCategories()) != '') { $categories = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategories()); } $categories[] = $category->getFullName(); $categoriesIds = array(); if (trim($entry->getCategoriesIds()) != '') { $categoriesIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getCategoriesIds()); } $categoriesIds[] = $category->getId(); $entry->parentSetCategories(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categories)); $entry->parentSetCategoriesIds(implode(entry::ENTRY_CATEGORY_SEPARATOR, $categoriesIds)); $entry->justSave(); } return $entry; }
$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); if (!count($categoryEntries)) { break; } foreach ($categoryEntries as $categoryEntry) { /* @var $categoryEntry categoryEntry */ try { $categoryEntry->setPrivacyContext($category->getPrivacyContexts()); $categoryEntry->save(); } catch (Exception $e) { KalturaLog::debug('failed to update category entry ' . $categoryEntry->getId()); } $lastCategoryEntryId = $categoryEntry->getId(); } } $lastCategoryId = $category->getId();
/** * Returns true if kuser or current kuser is entitled to entryId * @param entry $entry * @param int $kuser * @return bool */ public static function isEntryEntitled(entry $entry, $kuserId = null) { $ks = ks::fromSecureString(kCurrentContext::$ks); // entry is entitled when entitlement is disable // for actions with no ks - need to check if partner have default entitlement feature enable. if (!self::getEntitlementEnforcement() && $ks) { KalturaLog::debug('Entry entitled: entitlement disabled'); return true; } $partner = $entry->getPartner(); if (!$ks && !$partner->getDefaultEntitlementEnforcement()) { KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: no ks and default is with no enforcement'); return true; } if ($ks && $ks->isWidgetSession() && $ks->getDisableEntitlementForEntry() == $entry->getId()) { KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: widget session that disble entitlement for this entry'); return true; } $allCategoriesEntry = categoryEntryPeer::retrieveActiveAndPendingByEntryId($entry->getId()); $categories = array(); foreach ($allCategoriesEntry as $categoryEntry) { $categories[] = $categoryEntry->getCategoryId(); } //if entry doesn't belong to any category. $categories[] = category::CATEGORY_ID_THAT_DOES_NOT_EXIST; $c = KalturaCriteria::create(categoryPeer::OM_CLASS); $c->add(categoryPeer::ID, $categories, Criteria::IN); $privacy = array(PrivacyType::ALL); if ($ks && !$ks->isWidgetSession()) { $privacy[] = PrivacyType::AUTHENTICATED_USERS; } $crit = $c->getNewCriterion(categoryPeer::PRIVACY, $privacy, Criteria::IN); $ksPrivacyContexts = null; // entry that doesn't belong to any category is public //when ks is not provided - the entry is still public (for example - download action) $categoryEntries = categoryEntryPeer::retrieveActiveByEntryId($entry->getId()); if (!count($categoryEntries) && !$ks) { KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: entry does not belong to any category'); return true; } if ($ks) { $ksPrivacyContexts = $ks->getPrivacyContext(); if (!$ksPrivacyContexts || trim($ksPrivacyContexts) == '') { $ksPrivacyContexts = self::DEFAULT_CONTEXT . $partner->getId(); if (!count($allCategoriesEntry)) { // entry that doesn't belong to any category is public KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: entry does not belong to any category and privacy context on the ks is not set'); return true; } } $c->add(categoryPeer::PRIVACY_CONTEXTS, $ksPrivacyContexts, KalturaCriteria::IN_LIKE); if (!$kuserId) { $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, kCurrentContext::$ks_uid, true); if ($kuser) { $kuserId = $kuser->getId(); } } if ($kuserId) { // kuser is set on the entry as creator or uploader if ($kuserId != '' && $entry->getKuserId() == $kuserId) { KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks user is the same as entry->kuserId or entry->creatorKuserId [' . $kuserId . ']'); return true; } // kuser is set on the entry entitled users edit or publish $entitledKusers = array_merge(explode(',', $entry->getEntitledKusersEdit()), explode(',', $entry->getEntitledKusersPublish())); if (in_array($kuserId, $entitledKusers)) { KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks user is the same as entry->entitledKusersEdit or entry->entitledKusersPublish'); return true; } } // kuser is set on the category as member // this ugly code is temporery - since we have a bug in sphinxCriteria::getAllCriterionFields if ($kuserId) { $membersCrit = $c->getNewCriterion(categoryPeer::MEMBERS, $kuserId, Criteria::LIKE); $membersCrit->addOr($crit); $crit = $membersCrit; } } else { //no ks = set privacy context to default. $c->add(categoryPeer::PRIVACY_CONTEXTS, array(self::DEFAULT_CONTEXT . $partner->getId()), KalturaCriteria::IN_LIKE); } $c->addAnd($crit); //remove default FORCED criteria since categories that has display in search = public - doesn't mean that all of their entries are public KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $category = categoryPeer::doSelectOne($c); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if ($category) { KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] entitled: ks user is a member of this category or category privacy is set to public of authenticated'); return true; } KalturaLog::debug('Entry [' . print_r($entry->getId(), true) . '] not entitled'); return false; }
/** * 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(); }
$lastIntId = null; foreach ($entries as $entry) { /* @var $entry entry */ $categoriesCriteria = new Criteria(); $categoriesCriteria->add(categoryPeer::ID, $entry->getCategoriesIds(), Criteria::IN); $categories = categoryPeer::doSelect($categoriesCriteria); $categoryIds = array(); foreach ($categories as $category) { /* @var $category category */ $categoryIds[] = $category->getId(); } $categoryEntriesCriteria = new Criteria(); $categoryEntriesCriteria->addSelectColumn(categoryEntryPeer::CATEGORY_ID); $categoryEntriesCriteria->add(categoryEntryPeer::ENTRY_ID, $entry->getId()); $categoryEntriesCriteria->add(categoryEntryPeer::CATEGORY_ID, $categoryIds, Criteria::IN); $stmt = categoryEntryPeer::doSelectStmt($categoryEntriesCriteria); $categoryEntriesIds = $stmt->fetchAll(PDO::FETCH_COLUMN); KalturaStatement::setDryRun($dryRun); foreach ($categories as $category) { /* @var $category category */ $entryId = $entry->getId(); $categoryId = $category->getId(); if (in_array($categoryId, $categoryEntriesIds)) { KalturaLog::debug("CategoryEntry already exists for entry [{$entryId}] and category [{$categoryId}]"); continue; } $categoryEntry = new migrationCategoryEntry(); $categoryEntry->setEntryId($entryId); $categoryEntry->setCategoryId($categoryId); $categoryEntry->setPartnerId($entry->getPartnerId()); $categoryEntry->setCategoryFullIds($category->getFullIds());
public static function setDefaultCriteriaFilter() { if (self::$s_criteria_filter == null) { self::$s_criteria_filter = new criteriaFilter(); } $c = new Criteria(); $c->addAnd(categoryEntryPeer::STATUS, CategoryEntryStatus::DELETED, Criteria::NOT_EQUAL); self::$s_criteria_filter->setFilter($c); }
/** * 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(categoryEntryPeer::DATABASE_NAME); $criteria->add(categoryEntryPeer::ID, $pks, Criteria::IN); $objs = categoryEntryPeer::doSelect($criteria, $con); } return $objs; }
public function getAllCategoriesIds($includePending = false) { if (!$includePending) { $categoriesEntry = categoryEntryPeer::retrieveActiveByEntryId($this->getId()); } else { $categoriesEntry = categoryEntryPeer::retrieveActiveAndPendingByEntryId($this->getId()); } $categoriesIds = array(); foreach ($categoriesEntry as $categoryEntry) { $categoriesIds[] = $categoryEntry->getCategoryId(); } return $categoriesIds; }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = new Criteria(categoryEntryPeer::DATABASE_NAME); $criteria->add(categoryEntryPeer::ID, $this->id); if ($this->alreadyInSave && count($this->modifiedColumns) == 2 && $this->isColumnModified(categoryEntryPeer::UPDATED_AT)) { $theModifiedColumn = null; foreach ($this->modifiedColumns as $modifiedColumn) { if ($modifiedColumn != categoryEntryPeer::UPDATED_AT) { $theModifiedColumn = $modifiedColumn; } } $atomicColumns = categoryEntryPeer::getAtomicColumns(); if (in_array($theModifiedColumn, $atomicColumns)) { $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL); } } return $criteria; }