/** * updates entry distribution sun status in the search engine * * @action updateSunStatus */ function updateSunStatusAction() { $updatedEntries = array(); // serach all records that their sun status changed to after sunset $criteria = KalturaCriteria::create(EntryDistributionPeer::OM_CLASS); $criteria->add(EntryDistributionPeer::STATUS, EntryDistributionStatus::READY); $criteria->add(EntryDistributionPeer::SUN_STATUS, EntryDistributionSunStatus::AFTER_SUNSET, Criteria::NOT_EQUAL); $crit1 = $criteria->getNewCriterion(EntryDistributionPeer::SUNSET, time(), Criteria::LESS_THAN); $criteria->add($crit1); $entryDistributions = EntryDistributionPeer::doSelect($criteria); foreach ($entryDistributions as $entryDistribution) { /* @var $entryDistribution EntryDistribution */ $entryId = $entryDistribution->getEntryId(); if (isset($updatedEntries[$entryId])) { continue; } $updatedEntries[$entryId] = true; kEventsManager::raiseEvent(new kObjectUpdatedEvent($entryDistribution)); // raise the updated events to trigger index in search engine (sphinx) kEventsManager::flushEvents(); // save entry changes to sphinx kMemoryManager::clearMemory(); } $updatedEntries = array(); // serach all records that their sun status changed to after sunrise $criteria = KalturaCriteria::create(EntryDistributionPeer::OM_CLASS); $criteria->add(EntryDistributionPeer::STATUS, EntryDistributionStatus::QUEUED); $criteria->add(EntryDistributionPeer::SUN_STATUS, EntryDistributionSunStatus::BEFORE_SUNRISE); $criteria->add(EntryDistributionPeer::SUNRISE, time(), Criteria::LESS_THAN); $entryDistributions = EntryDistributionPeer::doSelect($criteria); foreach ($entryDistributions as $entryDistribution) { /* @var $entryDistribution EntryDistribution */ $entryId = $entryDistribution->getEntryId(); if (isset($updatedEntries[$entryId])) { continue; } $updatedEntries[$entryId] = true; kEventsManager::raiseEvent(new kObjectUpdatedEvent($entryDistribution)); // raise the updated events to trigger index in search engine (sphinx) kEventsManager::flushEvents(); // save entry changes to sphinx kMemoryManager::clearMemory(); } }
/** * Parse content of caption asset and index it * * @action parse * @param string $captionAssetId * @throws KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND */ function parseAction($captionAssetId) { $captionAsset = assetPeer::retrieveById($captionAssetId); if (!$captionAsset) { throw new KalturaAPIException(KalturaCaptionErrors::CAPTION_ASSET_ID_NOT_FOUND, $captionAssetId); } $captionAssetItems = CaptionAssetItemPeer::retrieveByAssetId($captionAssetId); foreach ($captionAssetItems as $captionAssetItem) { /* @var $captionAssetItem CaptionAssetItem */ $captionAssetItem->delete(); } // make sure that all old items are deleted from the sphinx before creating the new ones kEventsManager::flushEvents(); $syncKey = $captionAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $content = kFileSyncUtils::file_get_contents($syncKey, true, false); if (!$content) { return; } $captionsContentManager = kCaptionsContentManager::getCoreContentManager($captionAsset->getContainerFormat()); if (!$captionsContentManager) { return; } $itemsData = $captionsContentManager->parse($content); foreach ($itemsData as $itemData) { $item = new CaptionAssetItem(); $item->setCaptionAssetId($captionAsset->getId()); $item->setEntryId($captionAsset->getEntryId()); $item->setPartnerId($captionAsset->getPartnerId()); $item->setStartTime($itemData['startTime']); $item->setEndTime($itemData['endTime']); $content = ''; foreach ($itemData['content'] as $curChunk) { $content .= $curChunk['text']; } //Make sure there are no invalid chars in the caption asset items to avoid braking the search request by providing invalid XML $content = kString::stripUtf8InvalidChars($content); $content = kXml::stripXMLInvalidChars($content); $item->setContent($content); $item->save(); } }
public function execute() { // can't read using $_REQUEST because the 'myaction' paramter is created in a routing.yml rule $service_name = $this->getRequestParameter("myaction"); // remove all '_' and set to lowercase $myaction_name = trim(strtolower(str_replace("_", "", $service_name))); $clazz_name = $myaction_name . "Action"; // echo "[$myaction_name] [$clazz_name]<br>"; // $clazz = get_class ( $clazz_name ); //$multi_request = $this->getRequestParameter( "multirequest" , null ); $multi_request = $myaction_name == "multirequest"; if ($multi_request) { $multi_request = new myMultiRequest($_REQUEST, $this); $response = $multi_request->execute(); } else { $include_result = @(include_once "{$clazz_name}.class.php"); if ($include_result) { $myaction = new $clazz_name($this); $myaction->setInputParams($_REQUEST); $response = $myaction->execute(); kEventsManager::flushEvents(); } else { $format = $this->getP("format"); $response = "Error: Invalid service [{$service_name}]"; } } $format = $this->getP("format"); if ($format == kalturaWebserviceRenderer::RESPONSE_TYPE_PHP_ARRAY || $format == kalturaWebserviceRenderer::RESPONSE_TYPE_PHP_OBJECT) { //$this->setHttpHeader ( "Content-Type" , "text/html; charset=utf-8" ); $response = "<pre>" . print_r($response, true) . "</pre>"; } // uncomment in order to cache api responses if (kConf::get('enable_cache')) { $this->cacheResponse($response); } $ret = $this->renderText($response); KExternalErrors::terminateDispatch(); return $ret; }
public function objectReplaced(BaseObject $object, BaseObject $replacingObject, BatchJob $raisedJob = null) { //replacement as a result of convertLiveSegmentFinished if (!$replacingObject->getIsTemporary()) { return true; } $c = new Criteria(); $c->add(CuePointPeer::ENTRY_ID, $object->getId()); if (CuePointPeer::doCount($c) > self::MAX_CUE_POINTS_TO_COPY_TO_CLIP) { KalturaLog::alert("Can't handle cuePoints after replacement for entry [{$object->getId()}] because cuePoints count exceeded max limit of [" . self::MAX_CUE_POINTS_TO_COPY_TO_CLIP . "]"); return true; } $clipAttributes = self::getClipAttributesFromEntry($replacingObject); //replacement as a result of trimming if (!is_null($clipAttributes)) { kEventsManager::setForceDeferredEvents(true); $this->deleteCuePoints($c); //copy cuepoints from replacement entry $replacementCuePoints = CuePointPeer::retrieveByEntryId($replacingObject->getId()); foreach ($replacementCuePoints as $cuePoint) { $newCuePoint = $cuePoint->copyToEntry($object); $newCuePoint->save(); } kEventsManager::flushEvents(); } else { if (PermissionPeer::isValidForPartner(CuePointPermissionName::REMOVE_CUE_POINTS_WHEN_REPLACING_MEDIA, $object->getPartnerId())) { $this->deleteCuePoints($c); } } return true; }
public static function syncEntriesCategories(entry $entry, $isCategoriesModified) { self::$skipEntrySave = true; if ($entry->getNewCategories() != null && $entry->getNewCategories() !== "") { $newCats = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getNewCategories()); } else { $newCats = array(); } if (!$isCategoriesModified) { if ($entry->getNewCategoriesIds() != null && $entry->getNewCategoriesIds() !== "") { $newCatsIds = explode(entry::ENTRY_CATEGORY_SEPARATOR, $entry->getNewCategoriesIds()); } else { $newCatsIds = array(); } KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $dbCategories = categoryPeer::retrieveByPKs($newCatsIds); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); foreach ($dbCategories as $dbCategory) { //skip categoy with privacy contexts. if ($dbCategory->getPrivacyContexts() != null && $dbCategory->getPrivacyContexts() != '') { continue; } $newCats[] = $dbCategory->getFullName(); } } $newCats = array_unique($newCats); $allIds = array(); $allCats = array(); $allIdsWithParents = array(); $addedCats = array(); $removedCats = array(); $remainingCats = array(); $oldCats = array(); $oldCatsIds = array(); $dbOldCategoriesEntry = categoryEntryPeer::selectByEntryId($entry->getId()); foreach ($dbOldCategoriesEntry as $dbOldCategoryEntry) { $oldCatsIds[] = $dbOldCategoryEntry->getCategoryId(); } $oldCategoris = categoryPeer::retrieveByPKsNoFilter($oldCatsIds); foreach ($oldCategoris as $category) { if ($category->getPrivacyContexts() != '' && $category->getPrivacyContexts() != null) { continue; } $oldCats[] = $category->getFullName(); } foreach ($oldCats as $cat) { if (array_search($cat, $newCats) === false) { $removedCats[] = $cat; } } foreach ($newCats as $cat) { if (array_search($cat, $oldCats) === false) { $addedCats[] = $cat; } else { $remainingCats[] = $cat; } } foreach ($remainingCats as $cat) { KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $category = categoryPeer::getByFullNameExactMatch($cat); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if ($category) { if ($category->getPrivacyContext() == '' || $category->getPrivacyContext() == null) { $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } $allIdsWithParents[] = $category->getId(); $allIdsWithParents = array_merge($allIdsWithParents, $category->getAllParentsIds()); } } $alreadyAddedCatIds = $allIdsWithParents; foreach ($addedCats as $cat) { $category = categoryPeer::getByFullNameExactMatch($cat); if (!$category) { KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $unentitedCategory = categoryPeer::getByFullNameExactMatch($cat); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if (!$unentitedCategory) { $category = category::createByPartnerAndFullName($entry->getPartnerId(), $cat); //it is possible to add on an entry a few new categories on the same new parent - //and we need to sync sphinx once we add so the category will not be duplicated kEventsManager::flushEvents(); } } else { $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($category->getId(), kCurrentContext::$ks_kuser_id); if (kEntitlementUtils::getEntitlementEnforcement() && $category->getContributionPolicy() != ContributionPolicyType::ALL && (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER)) { //user is not entitled to add entry to this category $category = null; } } if (!$category) { continue; } //when use caetgoryEntry->add categoryEntry object was alreay created - and no need to create it. //when using baseEntry->categories = 'my category' will need to add the new category. $categoryEntry = categoryEntryPeer::retrieveByCategoryIdAndEntryId($category->getId(), $entry->getId()); if (!$categoryEntry) { $categoryEntry = new categoryEntry(); $categoryEntry->setEntryId($entry->getId()); $categoryEntry->setCategoryId($category->getId()); $categoryEntry->setEntryCategoriesAddedIds($alreadyAddedCatIds); $categoryEntry->setPartnerId($entry->getPartnerId()); $categoryEntry->setStatus(CategoryEntryStatus::ACTIVE); $categoryEntry->save(); } if ($category->getPrivacyContext() == '' || $category->getPrivacyContext() == null) { // only categories with no context should be set on entry->categories and entry->categoriesIds $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } $alreadyAddedCatIds[] = $category->getId(); $alreadyAddedCatIds = array_merge($alreadyAddedCatIds, $category->getAllParentsIds()); } $alreadyRemovedCatIds = $allIdsWithParents; foreach ($removedCats as $cat) { $category = categoryPeer::getByFullNameExactMatch($cat); if ($category) { $categoryEntryToDelete = categoryEntryPeer::retrieveByCategoryIdAndEntryId($category->getId(), $entry->getId()); if ($categoryEntryToDelete) { $categoryKuser = categoryKuserPeer::retrieveByCategoryIdAndActiveKuserId($categoryEntryToDelete->getCategoryId(), kCurrentContext::$ks_kuser_id); if ($category->getPrivacyContexts() && (!$categoryKuser || $categoryKuser->getPermissionLevel() == CategoryKuserPermissionLevel::MEMBER)) { //not entiteld to delete - should be set back on the entry. $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } else { $categoryEntryToDelete->setEntryCategoriesRemovedIds($alreadyRemovedCatIds); $categoryEntryToDelete->setStatus(CategoryEntryStatus::DELETED); $categoryEntryToDelete->save(); } } $alreadyRemovedCatIds[] = $category->getId(); $alreadyRemovedCatIds = array_merge($alreadyRemovedCatIds, $category->getAllParentsIds()); } else { //category was not found - it could be that user is not entitled to remove it KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); $category = categoryPeer::getByFullNameExactMatch($cat); KalturaCriterion::restoreTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY); if ($category) { $allCats[] = $category->getFullName(); $allIds[] = $category->getId(); } } } self::$skipEntrySave = false; $entry->parentSetCategories(implode(",", $allCats)); $entry->parentSetCategoriesIds(implode(',', $allIds)); }
public function dispatch($service, $action, $params = array()) { $start = microtime(true); // prevent impersonate to partner zero $p = isset($params["p"]) && $params["p"] ? $params["p"] : null; if (!$p) { $p = isset($params["partnerId"]) && $params["partnerId"] ? $params["partnerId"] : null; } $GLOBALS["partnerId"] = $p; // set for logger $userId = ""; $ksStr = isset($params["ks"]) ? $params["ks"] : null; if (!$service) { throw new KalturaAPIException(KalturaErrors::SERVICE_NOT_SPECIFIED); } //strtolower on service - map is indexed according to lower-case service IDs $service = strtolower($service); $serviceActionItem = KalturaServicesMap::retrieveServiceActionItem($service, $action); $action = strtolower($action); if (!isset($serviceActionItem->actionMap[$action])) { KalturaLog::crit("Action does not exist!"); throw new KalturaAPIException(KalturaErrors::ACTION_DOES_NOT_EXISTS, $action, $service); } try { $actionReflector = new KalturaActionReflector($service, $action, $serviceActionItem->actionMap[$action]); } catch (Exception $e) { throw new Exception("Could not create action reflector for service [{$service}], action [{$action}]. Received error: " . $e->getMessage()); } $actionParams = $actionReflector->getActionParams(); $actionInfo = $actionReflector->getActionInfo(); // services.ct - check if partner is allowed to access service ... kCurrentContext::$host = isset($_SERVER["HOSTNAME"]) ? $_SERVER["HOSTNAME"] : gethostname(); kCurrentContext::$user_ip = requestUtils::getRemoteAddress(); kCurrentContext::$ps_vesion = "ps3"; kCurrentContext::$service = $serviceActionItem->serviceInfo->serviceName; kCurrentContext::$action = $action; kCurrentContext::$client_lang = isset($params['clientTag']) ? $params['clientTag'] : null; kCurrentContext::initKsPartnerUser($ksStr, $p, $userId); // validate it's ok to access this service $deserializer = new KalturaRequestDeserializer($params); $this->arguments = $deserializer->buildActionArguments($actionParams); KalturaLog::debug("Dispatching service [" . $service . "], action [" . $action . "], reqIndex [" . kCurrentContext::$multiRequest_index . "] with params " . print_r($this->arguments, true)); $responseProfile = $deserializer->getResponseProfile(); if ($responseProfile) { KalturaLog::debug("Response profile: " . print_r($responseProfile, true)); } kPermissionManager::init(kConf::get('enable_cache')); kEntitlementUtils::initEntitlementEnforcement(); $disableTags = $actionInfo->disableTags; if ($disableTags && is_array($disableTags) && count($disableTags)) { foreach ($disableTags as $disableTag) { KalturaCriterion::disableTag($disableTag); } } if ($actionInfo->validateUserObjectClass && $actionInfo->validateUserIdParamName && isset($actionParams[$actionInfo->validateUserIdParamName])) { // // TODO maybe if missing should throw something, maybe a bone? // if(!isset($actionParams[$actionInfo->validateUserIdParamName])) // throw new KalturaAPIException(KalturaErrors::MISSING_MANDATORY_PARAMETER, $actionInfo->validateUserIdParamName); KalturaLog::debug("validateUserIdParamName: " . $actionInfo->validateUserIdParamName); $objectId = $params[$actionInfo->validateUserIdParamName]; $this->validateUser($actionInfo->validateUserObjectClass, $objectId, $actionInfo->validateUserPrivilege, $actionInfo->validateOptions); } // initialize the service before invoking the action on it // action reflector will init the service to maintain the pluginable action transparency $actionReflector->initService($responseProfile); $invokeStart = microtime(true); KalturaLog::debug("Invoke start"); try { $res = $actionReflector->invoke($this->arguments); } catch (KalturaAPIException $e) { if ($actionInfo->returnType != 'file') { throw $e; } KalturaResponseCacher::adjustApiCacheForException($e); $res = new kRendererDieError($e->getCode(), $e->getMessage()); } kEventsManager::flushEvents(); KalturaLog::debug("Invoke took - " . (microtime(true) - $invokeStart) . " seconds"); KalturaLog::debug("Dispatch took - " . (microtime(true) - $start) . " seconds, memory: " . memory_get_peak_usage(true)); return $res; }
public function execute($add_extra_debug_data = true) { date_default_timezone_set(kConf::get("date_default_timezone")); // TODO - remove for production - use some configuration to determine kConfigTable::$should_use_cache = false; $start_impl = $end_impl = 0; $nocache = false; if ($this->getP("nocache")) { $nocache = true; $this->logMessage("Not using cache!"); objectWrapperBase::useCache(false); } $add_benchmarks = $this->getP("add_benchmarks", false); // while testing our system - will match each service agains its description // $this->matchInDescription(); $this->msg = array(); $this->error = array(); $this->debug = array(); $start_time = microtime(true); $start = microtime(true); $this->benchmarkStart("beforeImpl"); $this->response_type = $this->getP("format", self::DEFAULT_FORMAT); // /* $should_debug = $this->getP ( "should_debug" , true ); if ( $should_debug == "false" ) $this->should_debug = false; */ if ($this->should_debug && $add_extra_debug_data) { $this->benchmarkStart("signature"); $sig_type = $this->getP("sigtype", self::SIG_TYPE_POST); $signature_params = self::getParamsFromSigType($sig_type); $signatura_valid = self::validateSignature($signature_params); $this->benchmarkEnd("signature"); $this->addDebug("sigtype", $sig_type); $this->addDebug("validateSignature", $signatura_valid); $this->addDebug("signature", self::signature($signature_params)); // $this->addDebug( "rawsignature" , self::signature( $signature_params , false ) ); } $partner_id = $this->getP("partner_id"); if (!$partner_id) { $partner_id = $this->getP("partnerId"); } $subp_id = $this->getP("subp_id"); if (!$subp_id) { $subp_id = $this->getP("subpId"); } $puser_id = $this->getP("uid"); $ks_str = $this->getP("ks"); if ($ks_str == "{ks}") { $ks_str = ""; } // if the client DIDN'T replace the dynamic ks - ignore it // the $execution_cache_key can be used by services to cache the results depending on the inpu parameters // if the $execution_cache_key is not null, the rendere will search for the result of the rendering depending on the $execution_cache_key // if it doesn't find it - it will create it (per format) and store it for next time $execution_cache_key = null; // moved the renderer here to see if has the $execution_cache_key and if so - skip the implementation $renderer = new kalturaWebserviceRenderer($this->response_context); $private_partner_data = false; try { try { $arr = list($partner_id, $subp_id, $uid, $private_partner_data) = $this->validateTicketSetPartner($partner_id, $subp_id, $puser_id, $ks_str); } catch (Exception $ex) { KalturaLog::log('validateTicketSetPartner failed - not caching response'); defPartnerservices2baseAction::disableCache(); throw $ex; } // if PS2 permission validation is enabled for the current partner, only the actions defined in kConf's parameter "ps2_actions_not_blocked_by_permissions" will be allowed $currentPartner = $this->getPartner(); if ($currentPartner && $currentPartner->getEnabledService(PermissionName::FEATURE_PS2_PERMISSIONS_VALIDATION)) { if (!in_array(strtolower(get_class($this)), kConf::get('ps2_actions_not_blocked_by_permissions'))) { KalturaLog::log('PS2 action ' . get_class($this) . ' is being blocked for partner ' . $currentPartner->getId() . ' defined with FEATURE_PS2_PERMISSIONS_VALIDATION enabled'); $this->addException(APIErrors::SERVICE_FORBIDDEN, get_class($this)); } } $this->private_partner_data = $private_partner_data; //print_r ( $arr ); // TODO - validate the matchIp is ok with the user's IP $this->validateIp(); // most services should not attempt to cache the results - for them this will return null $execution_cache_key = $this->getExecutionCacheKeyWrapper($partner_id, $subp_id, $puser_id); // if the key is not null - it will be used in the renderer for using the cotent from the cache if ($nocache) { $renderer->deleteCacheKey($execution_cache_key, $this->response_type); } else { $renderer->setCacheKey($execution_cache_key); } if (!$renderer->hasContentForCacheKey($this->response_type)) { $this->benchmarkStart("applyPartnerFilters"); //init entitlement before set the default criteire by myPartnerUtils::applyPartnerFilters kEntitlementUtils::initEntitlementEnforcement(); // apply filters for Criteria so there will be no chance of exposure of date from other partners ! // TODO - add the parameter for allowing kaltura network myPartnerUtils::applyPartnerFilters($partner_id, $private_partner_data, $this->partnerGroup2(), $this->kalturaNetwork2()); $this->benchmarkEnd("applyPartnerFilters"); $this->benchmarkStart("puserKuser"); list($partner_id, $subp_id, $puser_id, $partner_prefix) = $this->preparePartnerPuserDetails($partner_id, $subp_id, $puser_id); $puser_kuser = $this->getPuserKuser($partner_id, $subp_id, $puser_id); $this->benchmarkEnd("puserKuser"); $this->benchmarkEnd("beforeImpl"); // ----------------------------- impl -------------------------- $start_impl = microtime(true); $result = $this->executeImpl($partner_id, $subp_id, $puser_id, $partner_prefix, $puser_kuser); $end_impl = microtime(true); kEventsManager::flushEvents(); } else { /// the renderer claims to have the desired result ! just flow down the code ... ;) } // ----------------------------- impl -------------------------- } catch (APIException $api_ex) { $message = $api_ex->getMessage(); if ($this->should_debug && $message) { $this->addError(APIErrors::SERVERL_ERROR, "[{$message}]"); } elseif ($api_ex->api_code) { call_user_func_array(array(&$this, 'addError'), $api_ex->extra_data); // $this->addError ( $api_ex->api_code ,$api_ex->extra_data ); } } catch (PropelException $pex) { KalturaLog::alert($pex->getMessage()); $this->addError(APIErrors::INTERNAL_DATABASE_ERROR); } catch (Exception $ex) { $this->addError(APIErrors::INTERNAL_SERVERL_ERROR, $ex->getMessage()); KalturaLog::err($ex->getMessage()); } $execute_impl_end_time = microtime(true); // render according to the format_type $res = array(); $this->addMsg("serverTime", time()); $res['result'] = $this->msg; $res['error'] = $this->error; if ($this->should_debug) { // this specific debug line should be used $this->addDebug("execute_impl_time", $end_impl - $start_impl); $this->addDebug("execute_time", $execute_impl_end_time - $start_time); // will be used as a place holder and will be replaced after the rendering. if ($add_extra_debug_data) { $this->addDebug("total_time", self::__TOTAL_TIME__); } if ($add_benchmarks && count($this->benchmarks) > 0) { $this->addDebug("host", @$_ENV["HOSTNAME"]); $this->addDebug("benchmarks", $this->getBenchmarks()); } $res['debug'] = $this->debug; } // ignore all the errors and debug - the first msg is the only html used if ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_HTML) { $res = "<html>"; foreach ($this->msg as $html_bit) { $res .= $html_bit; } $res .= "</html>"; } if ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_MRSS) { // in case of mRss - render only the result not the errors ot the debug list($response, $content_type) = $renderer->renderDataInRequestedFormat($res['result'], $this->response_type, true, self::$escape_text); } else { list($response, $content_type) = $renderer->renderDataInRequestedFormat($res, $this->response_type, true, self::$escape_text); } $end_time = microtime(true); if (is_string($response)) { $this->logMessage("Rendereing took: [" . ($end_time - $start_time) . "] seconds. Response size [" . strlen($response) . "]", SF_LOG_WARNING); $this->logMessage($response, SF_LOG_WARNING); } else { $this->logMessage("Rendereing took: [" . ($end_time - $start_time) . "]"); } if ($this->should_debug && $add_extra_debug_data) { // fix the total time including the render time $str_time = (string) ($end_time - $start_time); if ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_PHP) { // replcate the placehoder with the real execution time // this is a nasty hack - we replace the serialized PHP value - the length of the placeholder is 14 characters // the length of the str_time can be less - replace the whole string phrase $replace_string = 's:' . strlen($str_time) . ':"' . $str_time; $response = str_replace('s:14:"' . self::__TOTAL_TIME__, $replace_string, $response); } elseif ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_PHP_ARRAY || $this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_PHP_OBJECT) { // the $response is not a string - we can't just replace it $res["debug"]["total_time"] = $str_time; } elseif ($this->response_type == kalturaWebserviceRenderer::RESPONSE_TYPE_MRSS) { // do nothing to the result } else { $response = str_replace(self::__TOTAL_TIME__, $str_time, $response); } } header("Access-Control-Allow-Origin:*"); // avoid html5 xss issues $this->setContentType($content_type); // while testing our system - will match each service agains its description // $this->matchOutDescription(); return $response; }
/** * @param entry $entry * @param entry $tempEntry */ public static function replaceEntry(entry $entry, entry $tempEntry = null) { if (!$tempEntry) { $tempEntry = entryPeer::retrieveByPK($entry->getReplacingEntryId()); } if (!$tempEntry) { KalturaLog::err("Temp entry id [" . $entry->getReplacingEntryId() . "] not found"); return; } //Extract all assets of the temp entry $tempAssets = assetPeer::retrieveByEntryId($tempEntry->getId()); //Extract all assets of the existing entry $oldAssets = assetPeer::retrieveByEntryId($entry->getId()); $newAssets = array(); //Loop which creates a mapping between the new assets' paramsId and their type to the asset itself foreach ($tempAssets as $newAsset) { if ($newAsset->getStatus() != asset::FLAVOR_ASSET_STATUS_READY) { KalturaLog::info("Do not add new asset [" . $newAsset->getId() . "] to flavor [" . $newAsset->getFlavorParamsId() . "] status [" . $newAsset->getStatus() . "]"); continue; } //If doesn't exist - create a new array for the current asset's type. if (!isset($newAssets[$newAsset->getType()])) { $newAssets[$newAsset->getType()] = array(); } if ($newAsset->getFlavorParamsId() || $newAsset instanceof flavorAsset) { $newAssets[$newAsset->getType()][$newAsset->getFlavorParamsId()] = $newAsset; KalturaLog::info("Added new asset [" . $newAsset->getId() . "] for asset params [" . $newAsset->getFlavorParamsId() . "]"); } else { $newAssets[$newAsset->getType()]['asset_' . count($newAssets[$newAsset->getType()])] = $newAsset; KalturaLog::info("Added new asset [" . $newAsset->getId() . "] with no asset params"); } } $defaultThumbAssetNew = null; $defaultThumbAssetOld = null; foreach ($oldAssets as $oldAsset) { /* @var $oldAsset asset */ //If the newAssets map contains an asset of the same type and paramsId as the current old asset, // re-link the old asset to the new asset. if (isset($newAssets[$oldAsset->getType()]) && isset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()])) { $newAsset = $newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()]; if ($oldAsset->hasTag(assetParams::TAG_RECORDING_ANCHOR)) { $newAsset->addTags(array(assetParams::TAG_RECORDING_ANCHOR)); } /* @var $newAsset asset */ KalturaLog::info("Create link from new asset [" . $newAsset->getId() . "] to old asset [" . $oldAsset->getId() . "] for flavor [" . $oldAsset->getFlavorParamsId() . "]"); $oldAsset->linkFromAsset($newAsset); $oldAsset->save(); self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_ISM); self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_ISMC); self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_MPD); $newFlavorMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($newAsset->getId()); if ($newFlavorMediaInfo) { $oldFlavorNewMediaInfo = $newFlavorMediaInfo->copy(); $oldFlavorNewMediaInfo->setFlavorAssetId($oldAsset->getId()); $oldFlavorNewMediaInfo->setFlavorAssetVersion($oldAsset->getVersion()); $oldFlavorNewMediaInfo->save(); } unset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()]); if ($oldAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { $defaultThumbAssetNew = $oldAsset; KalturaLog::info("Nominating ThumbAsset [" . $oldAsset->getId() . "] as the default ThumbAsset after replacent"); } } elseif ($oldAsset instanceof flavorAsset || $oldAsset instanceof thumbAsset) { if ($oldAsset instanceof thumbAsset && $oldAsset->keepOnEntryReplacement()) { KalturaLog::info("KeepManualThumbnails ind is set, manual thumbnail is not deleted [" . $oldAsset->getId() . "]"); if ($oldAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { $defaultThumbAssetOld = $oldAsset; } } else { KalturaLog::info("Delete old asset [" . $oldAsset->getId() . "] for paramsId [" . $oldAsset->getFlavorParamsId() . "]"); $oldAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED); $oldAsset->setDeletedAt(time()); $oldAsset->save(); } } } foreach ($newAssets as $newAssetsByTypes) { foreach ($newAssetsByTypes as $newAsset) { $createdAsset = $newAsset->copyToEntry($entry->getId(), $entry->getPartnerId()); KalturaLog::info("Copied from new asset [" . $newAsset->getId() . "] to copied asset [" . $createdAsset->getId() . "] for flavor [" . $newAsset->getFlavorParamsId() . "]"); if ($createdAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { $defaultThumbAssetNew = $newAsset; KalturaLog::info("Nominating ThumbAsset [" . $newAsset->getId() . "] as the default ThumbAsset after replacent"); } } } if ($defaultThumbAssetOld) { KalturaLog::info("Kepping ThumbAsset [" . $defaultThumbAssetOld->getId() . "] as the default ThumbAsset"); } elseif ($defaultThumbAssetNew) { kBusinessConvertDL::setAsDefaultThumbAsset($defaultThumbAssetNew); KalturaLog::info("Setting ThumbAsset [" . $defaultThumbAssetNew->getId() . "] as the default ThumbAsset"); } else { KalturaLog::info("No default ThumbAsset found for replacing entry [" . $tempEntry->getId() . "]"); $entry->setThumbnail(".jpg"); // thumbnailversion++ $entry->save(); $tempEntrySyncKey = $tempEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); $realEntrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); kFileSyncUtils::createSyncFileLinkForKey($realEntrySyncKey, $tempEntrySyncKey); } self::createIsmManifestFileSyncLinkFromReplacingEntry($tempEntry, $entry); $entry->setDimensions($tempEntry->getWidth(), $tempEntry->getHeight()); $entry->setLengthInMsecs($tempEntry->getLengthInMsecs()); $entry->setConversionProfileId($tempEntry->getConversionProfileId()); $entry->setConversionQuality($tempEntry->getConversionQuality()); $entry->setReplacingEntryId(null); $entry->setReplacementStatus(entryReplacementStatus::NONE); $entry->setReplacementOptions(null); $entry->setStatus($tempEntry->getStatus()); $entry->save(); //flush deffered events to re-index sphinx before temp entry deletion kEventsManager::flushEvents(); kBusinessConvertDL::checkForPendingLiveClips($entry); kEventsManager::raiseEvent(new kObjectReplacedEvent($entry, $tempEntry)); myEntryUtils::deleteEntry($tempEntry, null, true); $te = new TrackEntry(); $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_REPLACED_ENTRY); $te->setEntryId($entry->getId()); $te->setParam1Str($tempEntry->getId()); $te->setDescription(__METHOD__ . "[" . __LINE__ . "]"); TrackEntry::addTrackEntry($te); }
/** * Restore deleted entry. * * @action restoreDeletedEntry * @param string $entryId * @return KalturaBaseEntry The restored entry */ public function restoreDeletedEntryAction($entryId) { $deletedEntry = entryPeer::retrieveByPKNoFilter($entryId); if (!$deletedEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $fileSyncKeys = array(); foreach (self::$fileSyncKeysToRestore as $key) { $fileSyncKeys[] = $deletedEntry->getSyncKey($key); } $c = new Criteria(); $c->add(assetPeer::ENTRY_ID, $entryId, Criteria::EQUAL); assetPeer::setUseCriteriaFilter(false); $deletedAssets = assetPeer::doSelect($c); assetPeer::setUseCriteriaFilter(true); foreach ($deletedAssets as $deletedAsset) { array_push($fileSyncKeys, $deletedAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET), $deletedAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_CONVERT_LOG)); } $fileSyncs = array(); FileSyncPeer::setUseCriteriaFilter(false); foreach ($fileSyncKeys as $fileSyncKey) { $fileSyncs = array_merge($fileSyncs, FileSyncPeer::retrieveAllByFileSyncKey($fileSyncKey)); } FileSyncPeer::setUseCriteriaFilter(true); if (!$this->validateEntryForRestoreDelete($deletedEntry, $fileSyncs, $deletedAssets)) { throw new KalturaAPIException(KalturaAdminConsoleErrors::ENTRY_ASSETS_WRONG_STATUS_FOR_RESTORE, $entryId); } $this->restoreFileSyncs($fileSyncs); //restore assets foreach ($deletedAssets as $deletedAsset) { $deletedAsset->setStatus(asset::ASSET_STATUS_READY); $deletedAsset->save(); } //restore entry $deletedEntry->setStatusReady(); $deletedEntry->setThumbnail($deletedEntry->getFromCustomData("deleted_original_thumb"), true); $deletedEntry->setData($deletedEntry->getFromCustomData("deleted_original_data"), true); //data should be resotred even if it's NULL $deletedEntry->save(); kEventsManager::flushEvents(); kMemoryManager::clearMemory(); $entry = KalturaEntryFactory::getInstanceByType($deletedEntry->getType(), true); $entry->fromObject($deletedEntry, $this->getResponseProfile()); return $entry; }
public function postInsert(PropelPDO $con = null) { parent::postInsert($con); if ($this->getFullIds() == null) { $this->reSetFullIds(); parent::save(); } if (!$this->alreadyInSave) { kEventsManager::raiseEvent(new kObjectAddedEvent($this)); } kEventsManager::flushEvents(); if ($this->getParentCategory()) { $parentCategory = $this->getParentCategory(); if ($parentCategory) { $parentCategory->reSetDirectSubCategoriesCount(); $parentCategory->save(); } } }
$updatedAt = time() - $daysOld * 24 * 60 * 60; chdir(dirname(__FILE__)); require_once dirname(__FILE__) . '/../bootstrap.php'; $typesToDelete = array(); $dbConf = kConf::getDB(); DbManager::setConfig($dbConf); DbManager::initialize(); $c = new Criteria(); $c->add(entryPeer::PARTNER_ID, 100, Criteria::GREATER_THAN); $c->add(entryPeer::UPDATED_AT, $updatedAt, Criteria::LESS_THAN); if (count($typesToDelete)) { $c->add(entryPeer::TYPE, $typesToDelete, Criteria::IN); } $count = 0; $entries = entryPeer::doSelect($c); while ($entries) { $count += count($entries); foreach ($entries as $entry) { kCurrentContext::$ks_partner_id = $entry->getPartnerId(); kCurrentContext::$partner_id = $entry->getPartnerId(); kCurrentContext::$master_partner_id = $entry->getPartnerId(); KalturaLog::debug("Deletes entry [" . $entry->getId() . "]"); KalturaStatement::setDryRun($dryRun); myEntryUtils::deleteEntry($entry, $entry->getPartnerId()); KalturaStatement::setDryRun(false); } kEventsManager::flushEvents(); kMemoryManager::clearMemory(); $entries = entryPeer::doSelect($c); } KalturaLog::debug("Deleted [{$count}] entries");
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); }
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()); $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()); $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(); //we must flush events to sync categories to sphinx. if categories are not synced - then they might be duplicated, if 2 entries are assign to the same category. kEventsManager::flushEvents(); // 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()); $categoryEntries = categoryEntryPeer::doSelect($c); foreach ($categoryEntries as $categoryEntry) { /* @var $categoryEntry categoryEntry */ $newCategoryEntry = $categoryEntry->copy(); $newCategoryEntry->setPartnerId($newEntry->getPartnerId()); $newCategoryEntry->setEntryId($newEntry->getId()); $categoryId = kObjectCopyHandler::getMappedId('category', $newCategoryEntry->getCategoryId()); if ($categoryId) { $newCategoryEntry->setCategoryId($categoryId); } categoryPeer::setUseCriteriaFilter(false); entryPeer::setUseCriteriaFilter(false); $newCategoryEntry->save(); entryPeer::setUseCriteriaFilter(true); categoryPeer::setUseCriteriaFilter(true); } }