public static function setDefaultCriteriaFilter() { if (self::$s_criteria_filter == null) { self::$s_criteria_filter = new criteriaFilter(); } $c = KalturaCriteria::create(CuePointPeer::OM_CLASS); $c->addAnd(CuePointPeer::STATUS, CuePointStatus::DELETED, Criteria::NOT_EQUAL); if (self::$userContentOnly) { $puserId = kCurrentContext::$ks_uid; $partnerId = kCurrentContext::$ks_partner_id; if ($puserId && $partnerId) { $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $puserId); if (!$kuser) { $kuser = kuserPeer::createKuserForPartner($partnerId, $puserId); } // Temporarily change user filter to (user==kuser OR cuepoint of type THUMB/CODE). Long term fix will be accomplished // by adding a public property on the cuepoint object and checking (user==kuser OR is public) //$c->addAnd(CuePointPeer::KUSER_ID, $kuser->getId()); $criterionUserOrPublic = $c->getNewCriterion(CuePointPeer::KUSER_ID, $kuser->getId()); $criterionUserOrPublic->addOr($c->getNewCriterion(self::IS_PUBLIC, true, Criteria::EQUAL)); $criterionUserOrPublic->addTag(KalturaCriterion::TAG_USER_SESSION); $criterionUserOrPublic->addOr($c->getNewCriterion(CuePointPeer::TYPE, array(ThumbCuePointPlugin::getCuePointTypeCoreValue(ThumbCuePointType::THUMB), CodeCuePointPlugin::getCuePointTypeCoreValue(CodeCuePointType::CODE), AdCuePointPlugin::getCuePointTypeCoreValue(AdCuePointType::AD)), Criteria::IN)); $c->addAnd($criterionUserOrPublic); } } self::$s_criteria_filter->setFilter($c); }
/** * @param string $v puser id * @param bool $isAdmin * @return CuePoint */ public function setPuserId($puserId) { if (!$this->getPartnerId()) { throw new Exception("Partner id must be set in order to load puser [{$puserId}]"); } $kuser = kuserPeer::getKuserByPartnerAndUid($this->getPartnerId(), $puserId, true); if (!$kuser) { $kuser = kuserPeer::createKuserForPartner($this->getPartnerId(), $puserId); } $this->setKuserId($kuser->getId()); }
/** * Set the puser id and the kuser id * If the kuser doesn't exist it will be created * @param string $puserId */ public function setPuserId($puserId) { if (!$this->getPartnerId()) { throw new Exception("Partner id must be set in order to load puser [{$puserId}]"); } $this->puserId = $puserId; $kuser = kuserPeer::getKuserByPartnerAndUid($this->getPartnerId(), $puserId, true); if (!$kuser) { $isAdmin = kCurrentContext::$is_admin_session; $kuser = kuserPeer::createKuserForPartner($this->getPartnerId(), $puserId, $isAdmin); } $this->setKuserId($kuser->getId()); }
public static function setDefaultCriteriaFilterByKuser() { if (self::$s_criteria_filter == null) { self::$s_criteria_filter = new criteriaFilter(); } $c = self::$s_criteria_filter->getFilter(); if (!$c) { $c = new Criteria(); } $puserId = kCurrentContext::$ks_uid; $partnerId = kCurrentContext::$ks_partner_id; if ($puserId && $partnerId) { $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $puserId); if (!$kuser) { $kuser = kuserPeer::createKuserForPartner($partnerId, $puserId); } $c->addAnd(CuePointPeer::KUSER_ID, $kuser->getId()); } self::$s_criteria_filter->setFilter($c); }
/** * Allows you to add a metadata object and metadata content associated with Kaltura object * * @action add * @param int $metadataProfileId * @param KalturaMetadataObjectType $objectType * @param string $objectId * @param string $xmlData XML metadata * @return KalturaMetadata * @throws MetadataErrors::METADATA_PROFILE_NOT_FOUND * @throws MetadataErrors::INCOMPATIBLE_METADATA_PROFILE_OBJECT_TYPE * @throws MetadataErrors::METADATA_ALREADY_EXISTS * @throws MetadataErrors::INVALID_METADATA_DATA */ function addAction($metadataProfileId, $objectType, $objectId, $xmlData) { $metadataProfile = MetadataProfilePeer::retrieveByPK($metadataProfileId); if (!$metadataProfile) { throw new KalturaAPIException(MetadataErrors::METADATA_PROFILE_NOT_FOUND, $metadataProfileId); } if ($metadataProfile->getObjectType() != kPluginableEnumsManager::apiToCore('MetadataObjectType', $objectType)) { throw new KalturaAPIException(MetadataErrors::INCOMPATIBLE_METADATA_PROFILE_OBJECT_TYPE, $metadataProfile->getObjectType(), $objectType); } if ($objectType == KalturaMetadataObjectType::USER) { $kuser = kuserPeer::createKuserForPartner($this->getPartnerId(), $objectId); if ($kuser) { $objectId = $kuser->getId(); } } $objectType = kPluginableEnumsManager::apiToCore('MetadataObjectType', $objectType); $check = MetadataPeer::retrieveByObject($metadataProfileId, $objectType, $objectId); if ($check) { throw new KalturaAPIException(MetadataErrors::METADATA_ALREADY_EXISTS, $check->getId()); } // if a metadata xslt is defined on the metadata profile - transform the given metadata $xmlDataTransformed = $this->transformMetadata($metadataProfileId, $xmlData); if ($xmlDataTransformed) { $xmlData = $xmlDataTransformed; } $errorMessage = ''; if (!kMetadataManager::validateMetadata($metadataProfileId, $xmlData, $errorMessage)) { throw new KalturaAPIException(MetadataErrors::INVALID_METADATA_DATA, $errorMessage); } $dbMetadata = $this->addMetadata($metadataProfileId, $objectType, $objectId); $key = $dbMetadata->getSyncKey(Metadata::FILE_SYNC_METADATA_DATA); kFileSyncUtils::file_put_contents($key, $xmlData); $this->deleteOldVersions($dbMetadata); kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbMetadata)); $metadata = new KalturaMetadata(); $metadata->fromObject($dbMetadata, $this->getResponseProfile()); return $metadata; }
/** * Returns Kuser (New kuser will be created if it doesn't exists) * * @return kuser */ public function getKuser() { if (!$this->kuser) { // if no ks, puser id will be null if ($this->ks) { $puserId = $this->ks->user; } else { $puserId = null; } $kuser = kuserPeer::createKuserForPartner($this->getPartnerId(), $puserId); if ($kuser->getStatus() !== KalturaUserStatus::ACTIVE) { throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID); } $this->kuser = $kuser; } return $this->kuser; }
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()); } }
public function isValid($partner_id, $puser_id, $type = false) { if (!$this->valid_string) { return self::INVALID_STR; } if (!$this->matchPartner($partner_id)) { return self::INVALID_PARTNER; } if (!$this->matchUser($puser_id)) { return self::INVALID_USER; } if ($type !== false) { // do not check ks type if (!$this->type == $type) { return self::INVALID_TYPE; } } if ($this->expired()) { return self::EXPIRED; } $allowedIPRestriction = $this->isSetIPRestriction(); if ($allowedIPRestriction && $allowedIPRestriction != kCurrentContext::$user_ip) { KalturaLog::err("ipRestriction: EXCEEDED_RESTRICTED_IP"); return self::EXCEEDED_RESTRICTED_IP; } if ($this->original_str && $partner_id != Partner::BATCH_PARTNER_ID && !$this->isWidgetSession() && $this->isKSInvalidated() !== false) { $criteria = new Criteria(); $criteria->add(invalidSessionPeer::KS, $this->getHash()); $dbKs = invalidSessionPeer::doSelectOne($criteria); if ($dbKs) { $currentActionLimit = $dbKs->getActionsLimit(); if (is_null($currentActionLimit)) { return self::LOGOUT; } elseif ($currentActionLimit <= 0) { return self::EXCEEDED_ACTIONS_LIMIT; } $dbKs->setActionsLimit($currentActionLimit - 1); $dbKs->save(); } else { $limit = $this->isSetLimitAction(); if ($limit) { invalidSessionPeer::actionsLimitKs($this, $limit - 1); } } } // creates the kuser if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_END_USER_REPORTS, $partner_id)) { $kuser = kuserPeer::createKuserForPartner($partner_id, $puser_id); if (!$puser_id) { $kuser->setScreenName('Unknown'); $kuser->save(); } } return self::OK; }
/** * validate category fields * 1. category that inherit memebers cannot set values to inherited fields. * 2. validate the owner id exists as kuser * * @param category $sourceObject */ private function validateCategory(category $sourceObject = null) { if ($this->privacyContext != null && kEntitlementUtils::getEntitlementEnforcement()) { throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_PRIVACY_CONTEXT); } if (!$this->privacyContext && (!$sourceObject || !$sourceObject->getPrivacyContexts())) { $isInheritedPrivacyContext = true; if ($this->parentId != null) { $parentCategory = categoryPeer::retrieveByPK($this->parentId); if (!$parentCategory) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->parentId); } if ($parentCategory->getPrivacyContexts() == '') { $isInheritedPrivacyContext = false; } } else { $isInheritedPrivacyContext = false; } if (!$isInheritedPrivacyContext) { if ($this->appearInList != KalturaAppearInListType::PARTNER_ONLY && !$this->isNull('appearInList')) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_APPEAR_IN_LIST_FIELD_WITH_NO_PRIVACY_CONTEXT); } if ($this->inheritanceType != KalturaInheritanceType::MANUAL && !$this->isNull('inheritanceType')) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_INHERITANCE_TYPE_FIELD_WITH_NO_PRIVACY_CONTEXT); } if ($this->privacy != KalturaPrivacyType::ALL && !$this->isNull('privacy')) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_PRIVACY_FIELD_WITH_NO_PRIVACY_CONTEXT); } if (!$this->isNull('owner')) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_FIELD_WITH_NO_PRIVACY_CONTEXT); } if ($this->userJoinPolicy != KalturaUserJoinPolicyType::NOT_ALLOWED && !$this->isNull('userJoinPolicy')) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_USER_JOIN_POLICY_FIELD_WITH_NO_PRIVACY_CONTEXT); } if ($this->contributionPolicy != KalturaContributionPolicyType::ALL && !$this->isNull('contributionPolicy')) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_CONTIRUBUTION_POLICY_FIELD_WITH_NO_PRIVACY_CONTEXT); } if ($this->defaultPermissionLevel != KalturaCategoryUserPermissionLevel::MEMBER && !$this->isNull('defaultPermissionLevel')) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_DEFAULT_PERMISSION_LEVEL_FIELD_WITH_NO_PRIVACY_CONTEXT); } } } if ($this->inheritanceType != KalturaInheritanceType::MANUAL && $this->inheritanceType != null || $this->inheritanceType == null && $sourceObject && $sourceObject->getInheritanceType() != KalturaInheritanceType::MANUAL) { if ($this->owner != null) { if (!$sourceObject) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_WHEN_CATEGORY_INHERIT_MEMBERS); } elseif ($this->owner != $sourceObject->getKuserId()) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_WHEN_CATEGORY_INHERIT_MEMBERS); } } if ($this->userJoinPolicy != null) { if (!$sourceObject) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_USER_JOIN_POLICY_WHEN_CATEGORY_INHERIT_MEMBERS); } elseif ($this->userJoinPolicy != $sourceObject->getUserJoinPolicy()) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_USER_JOIN_POLICY_WHEN_CATEGORY_INHERIT_MEMBERS); } } if ($this->defaultPermissionLevel != null) { if (!$sourceObject) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_DEFAULT_PERMISSION_LEVEL_WHEN_CATEGORY_INHERIT_MEMBERS); } elseif ($this->defaultPermissionLevel != $sourceObject->getDefaultPermissionLevel()) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_DEFAULT_PERMISSION_LEVEL_WHEN_CATEGORY_INHERIT_MEMBERS); } } } if (!is_null($sourceObject)) { $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner || $partner->getFeaturesStatusByType(IndexObjectType::LOCK_CATEGORY)) { throw new KalturaAPIException(KalturaErrors::CATEGORIES_LOCKED); } } if ($this->owner && $this->owner != '' && !$this->owner instanceof KalturaNullField) { if (!preg_match(kuser::PUSER_ID_REGEXP, $this->owner)) { throw new KalturaAPIException(KalturaErrors::CANNOT_SET_OWNER_FIELD_WITH_USER_ID, $this->owner); } $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; kuserPeer::createKuserForPartner($partnerId, $this->owner); } }
/** * validate category fields * 1. category that inherit memebers canno set values to inherited fields. * 2. validate the owner id exists as kuser * * @param category $sourceObject */ private function validateCategory(category $sourceObject = null) { if ($this->privacyContext != null && kEntitlementUtils::getEntitlementEnforcement()) { throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_PRIVACY_CONTEXT); } if (!$this->privacyContext && (!$sourceObject || !$sourceObject->getPrivacyContexts())) { if ($this->appearInList != KalturaAppearInListType::PARTNER_ONLY && $this->appearInList != null || $this->moderation != KalturaNullableBoolean::FALSE_VALUE && $this->moderation != null || $this->inheritanceType != KalturaInheritanceType::MANUAL && $this->inheritanceType != null || $this->privacy != KalturaPrivacyType::ALL && $this->privacy != null || $this->owner != null || $this->userJoinPolicy != KalturaUserJoinPolicyType::NOT_ALLOWED && $this->userJoinPolicy != null || $this->contributionPolicy != KalturaContributionPolicyType::ALL && $this->contributionPolicy != null || $this->defaultPermissionLevel != KalturaCategoryUserPermissionLevel::MEMBER && $this->defaultPermissionLevel !== null) { if ($this->parentId != null) { $parentCategory = categoryPeer::retrieveByPK($this->parentId); if (!$parentCategory) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->parentId); } if ($parentCategory->getPrivacyContexts() == '') { throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_ENTITLEMENT_FIELDS_WITH_NO_PRIVACY_CONTEXT); } } else { throw new KalturaAPIException(KalturaErrors::CANNOT_UPDATE_CATEGORY_ENTITLEMENT_FIELDS_WITH_NO_PRIVACY_CONTEXT); } } } if ($this->inheritanceType != KalturaInheritanceType::MANUAL && $this->inheritanceType != null || $this->inheritanceType == null && $sourceObject && $sourceObject->getInheritanceType() != KalturaInheritanceType::MANUAL) { if (!$sourceObject && $this->owner != null || $sourceObject && $this->owner != null && $this->owner != $sourceObject->getKuserId() || !$sourceObject && $this->userJoinPolicy != null || $sourceObject && $this->userJoinPolicy != null && $this->userJoinPolicy != $sourceObject->getUserJoinPolicy() || !$sourceObject && $this->defaultPermissionLevel != null || $sourceObject && $this->defaultPermissionLevel != null && $this->defaultPermissionLevel != $sourceObject->getDefaultPermissionLevel()) { throw new KalturaAPIException(KalturaErrors::CATEGORY_INHERIT_MEMBERS_CANNOT_UPDATE_INHERITED_ATTRIBUTES); } } if (!is_null($sourceObject)) { $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; $partner = PartnerPeer::retrieveByPK($partnerId); if (!$partner || $partner->getFeaturesStatusByType(IndexObjectType::LOCK_CATEGORY)) { throw new KalturaAPIException(KalturaErrors::CATEGORIES_LOCKED); } } if ($this->owner && $this->owner != '' && !$this->owner instanceof KalturaNullField) { if (!preg_match(kuser::PUSER_ID_REGEXP, $this->owner)) { throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'owner'); } $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; kuserPeer::createKuserForPartner($partnerId, $this->owner); } }
public function setPuserId($v) { $this->puserId = $v; kuserPeer::setUseCriteriaFilter(false); $kuser = kuserPeer::getKuserByPartnerAndUid($this->getPartnerId(), $this->puserId, true); kuserPeer::setUseCriteriaFilter(true); if (!$kuser) { // Associate new kuser for the specified partner $kuser = kuserPeer::createKuserForPartner($this->getPartnerId(), $v); } if ($kuser) { return $this->setKuserId($kuser->getId()); } }
public function isValid($partner_id, $puser_id, $type = false) { if (!$this->valid_string) { return self::INVALID_STR; } if (!$this->matchPartner($partner_id)) { return self::INVALID_PARTNER; } if (!$this->matchUser($puser_id)) { return self::INVALID_USER; } if ($type !== false) { // do not check ks type if (!$this->type == $type) { return self::INVALID_TYPE; } } if ($this->expired()) { return self::EXPIRED; } if (!$this->isUserIPAllowed()) { return self::EXCEEDED_RESTRICTED_IP; } if ($this->original_str && $partner_id != Partner::BATCH_PARTNER_ID && !$this->isWidgetSession() && $this->isKSInvalidated() !== false) { $criteria = new Criteria(); $ksCriterion = $criteria->getNewCriterion(invalidSessionPeer::TYPE, invalidSession::INVALID_SESSION_TYPE_KS); $ksCriterion->addAnd($criteria->getNewCriterion(invalidSessionPeer::KS, $this->getHash())); $sessionId = $this->getSessionIdHash(); if ($sessionId) { $invalidSession = $criteria->getNewCriterion(invalidSessionPeer::KS, $sessionId); $invalidSession->addAnd($criteria->getNewCriterion(invalidSessionPeer::TYPE, invalidSession::INVALID_SESSION_TYPE_SESSION_ID)); $ksCriterion->addOr($invalidSession); } $criteria->add($ksCriterion); $dbKs = invalidSessionPeer::doSelectOne($criteria); if ($dbKs) { $currentActionLimit = $dbKs->getActionsLimit(); if (is_null($currentActionLimit)) { return self::LOGOUT; } elseif ($currentActionLimit <= 0) { return self::EXCEEDED_ACTIONS_LIMIT; } $dbKs->setActionsLimit($currentActionLimit - 1); $dbKs->save(); } else { $limit = $this->isSetLimitAction(); if ($limit) { invalidSessionPeer::actionsLimitKs($this, $limit - 1); } } } // creates the kuser if ($partner_id != Partner::BATCH_PARTNER_ID && PermissionPeer::isValidForPartner(PermissionName::FEATURE_END_USER_REPORTS, $partner_id)) { $this->kuser = kuserPeer::createKuserForPartner($partner_id, $puser_id); if (!$puser_id && $this->kuser->getScreenName() != 'Unknown') { $this->kuser->setScreenName('Unknown'); $this->kuser->save(); } } return self::OK; }
public function validateForInsert($propertiesToSkip = array()) { $category = categoryPeer::retrieveByPK($this->categoryId); if (!$category) { throw new KalturaAPIException(KalturaErrors::CATEGORY_NOT_FOUND, $this->categoryId); } if ($category->getInheritanceType() == InheritanceType::INHERIT) { throw new KalturaAPIException(KalturaErrors::CATEGORY_INHERIT_MEMBERS, $this->categoryId); } $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; $kuser = kuserPeer::getKuserByPartnerAndUid($partnerId, $this->userId); if ($kuser) { $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndKuserId($this->categoryId, $kuser->getId()); if ($categoryKuser) { throw new KalturaAPIException(KalturaErrors::CATEGORY_USER_ALREADY_EXISTS); } } $currentKuserCategoryKuser = categoryKuserPeer::retrievePermittedKuserInCategory($this->categoryId, kCurrentContext::getCurrentKsKuserId()); if ((!$currentKuserCategoryKuser || $currentKuserCategoryKuser->getPermissionLevel() != CategoryKuserPermissionLevel::MANAGER) && $category->getUserJoinPolicy() == UserJoinPolicyType::NOT_ALLOWED && kEntitlementUtils::getEntitlementEnforcement()) { throw new KalturaAPIException(KalturaErrors::CATEGORY_USER_JOIN_NOT_ALLOWED, $this->categoryId); } //if user doesn't exists - create it if (!$kuser) { if (!preg_match(kuser::PUSER_ID_REGEXP, $this->userId)) { throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'userId'); } kuserPeer::createKuserForPartner($partnerId, $this->userId); } return parent::validateForInsert($propertiesToSkip); }
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; }
/** * Sets the valid user for the entry * Throws an error if the session user is trying to update entry to another user and not using an admin session * * @param KalturaBaseEntry $entry * @param entry $dbEntry */ protected function checkAndSetValidUserUpdate(KalturaBaseEntry $entry, entry $dbEntry) { KalturaLog::debug("DB puser id [" . $dbEntry->getPuserId() . "] kuser id [" . $dbEntry->getKuserId() . "]"); // user id not being changed if ($entry->userId === null) { KalturaLog::log("entry->userId is null, not changing user"); return; } if (!$this->getKs() || !$this->getKs()->isAdmin()) { $entryPuserId = $dbEntry->getPuserId(); // non admin cannot change the owner of an existing entry if (strtolower($entry->userId) != strtolower($entryPuserId)) { KalturaLog::debug('API entry userId [' . $entry->userId . '], DB entry userId [' . $entryPuserId . '] - change required but KS is not admin'); throw new KalturaAPIException(KalturaErrors::INVALID_KS, "", ks::INVALID_TYPE, ks::getErrorStr(ks::INVALID_TYPE)); } } // need to create kuser if this is an admin changing the owner of the entry to a different user $kuser = kuserPeer::createKuserForPartner($dbEntry->getPartnerId(), $entry->userId); KalturaLog::debug("Set kuser id [" . $kuser->getId() . "] line [" . __LINE__ . "]"); $dbEntry->setKuserId($kuser->getId()); }
public function validateUsers() { $partnerId = kCurrentContext::$partner_id ? kCurrentContext::$partner_id : kCurrentContext::$ks_partner_id; if (!$this->isNull('entitledUsersEdit')) { $entitledUsersEdit = explode(',', $this->entitledUsersEdit); foreach ($entitledUsersEdit as $puserId) { $puserId = trim($puserId); kuserPeer::createKuserForPartner($partnerId, $puserId); } } if (!$this->isNull('entitledUsersPublish')) { $entitledPusersPublish = explode(',', $this->entitledUsersPublish); foreach ($entitledPusersPublish as $puserId) { $puserId = trim($puserId); kuserPeer::createKuserForPartner($partnerId, $puserId); } } }
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; }