protected function applyFilterFields(baseObjectFilter $filter) { /* @var $filter cuePointFilter */ // Reduce the cache expiry when fetching live stream cuepoints $entryId = $filter->get('_in_entry_id'); if ($entryId && strpos($entryId, ',') === false) { $entry = entryPeer::retrieveByPK($entryId); if ($entry && $entry->getType() == entryType::LIVE_STREAM) { kApiCache::setExpiry(self::LIVE_ENTRY_CUE_POINT_CACHE_EXPIRY_SECONDS); } } if ($filter->get('_free_text')) { $this->sphinxSkipped = false; $freeTexts = $filter->get('_free_text'); KalturaLog::debug("Attach free text [{$freeTexts}]"); $this->addFreeTextToMatchClauseByMatchFields($freeTexts, CuePointFilter::FREE_TEXT_FIELDS); } $filter->unsetByName('_free_text'); if ($filter->get('_eq_is_public')) { $this->sphinxSkipped = false; $isPublic = $filter->get('_eq_is_public'); $this->addCondition('is_public' . " = " . $isPublic); } $filter->unsetByName('_eq_is_public'); return parent::applyFilterFields($filter); }
public function apply() { if ($this->_cacheStatus == self::CACHE_STATUS_DISABLED) { kApiCache::disableCache(); return; } // common cache fields foreach ($this->_extraFields as $extraField) { call_user_func_array(array('kApiCache', 'addExtraField'), $extraField); } // anonymous cache fields if ($this->_expiry) { kApiCache::setExpiry($this->_expiry); } if ($this->_cacheStatus == self::CACHE_STATUS_ANONYMOUS_ONLY) { kApiCache::disableConditionalCache(); return; } // conditional cache fields if ($this->_conditionalCacheExpiry) { kApiCache::setConditionalCacheExpiry($this->_conditionalCacheExpiry); } kApiCache::addInvalidationKeys(array_keys($this->_invalidationKeys), $this->_invalidationTime); kApiCache::addSqlQueryConditions($this->_sqlConditions); }
public function isScheduledNow($time = null) { if (is_null($time)) { $time = time(); // entry scheduling status changes within 24H if ($this->getStartDate() && abs($this->getStartDate(null) - time()) <= 86400 || $this->getEndDate() && abs($this->getEndDate(null) - time()) <= 86400) { kApiCache::setConditionalCacheExpiry(600); } // entry scheduling status changes within 10 min if ($this->getStartDate() && abs($this->getStartDate(null) - time()) <= 600 || $this->getEndDate() && abs($this->getEndDate(null) - time()) <= 600) { kApiCache::setExpiry(60); kApiCache::setConditionalCacheExpiry(60); } } $startDateCheck = !$this->getStartDate() || $this->getStartDate(null) <= $time; $endDateCheck = !$this->getEndDate() || $this->getEndDate(null) >= $time; return $startDateCheck && $endDateCheck; }
private function serveLiveEntry() { if (in_array($this->entry->getSource(), LiveEntry::$kalturaLiveSourceTypes)) { if (!$this->entry->hasMediaServer()) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_LIVE, "Entry [{$this->entryId}] is not broadcasting"); } kApiCache::setExpiry(120); } list($baseUrl, $backupUrl) = $this->getLiveEntryBaseUrls(); $cdnHost = parse_url($baseUrl, PHP_URL_HOST); if ($this->deliveryAttributes->getFormat() == PlaybackProtocol::MULTICAST_SL) { $this->deliveryAttributes->setFormat(PlaybackProtocol::HDS); } $this->deliveryProfile = DeliveryProfilePeer::getLiveDeliveryProfileByHostName($cdnHost, $this->deliveryAttributes); if (!$this->deliveryProfile) { return null; } $this->deliveryProfile->setDynamicAttributes($this->deliveryAttributes); return $this->deliveryProfile->serve($baseUrl, $backupUrl); }
protected function applyFilterFields(baseObjectFilter $filter) { /* @var $filter entryFilter */ if ($filter->is_set('_eq_redirect_from_entry_id')) { $partnerGroup = array(kCurrentContext::getCurrentPartnerId(), PartnerPeer::GLOBAL_PARTNER); $criteriaFilter = entryPeer::getCriteriaFilter(); $defaultCriteria = $criteriaFilter->getFilter(); $defaultCriteria->remove(entryPeer::PARTNER_ID); $defaultCriteria->add(entryPeer::PARTNER_ID, $partnerGroup, Criteria::IN); $origEntryId = $filter->get('_eq_redirect_from_entry_id'); $origEntry = entryPeer::retrieveByPK($origEntryId); if (!empty($origEntry)) { if ($origEntry->getType() == entryType::LIVE_STREAM) { // Set a relatively short expiry value in order to reduce the wait-time // until the cache is refreshed and a redirection kicks-in. kApiCache::setExpiry(kApiCache::REDIRECT_ENTRY_CACHE_EXPIRY); } // Get the id of the entry id that is being redirected from the original entry $redirectEntryId = $origEntry->getRedirectEntryId(); if (is_null($redirectEntryId)) { $filter->set('_eq_id', $origEntryId); // Continue with original entry id } else { // Get the redirected entry and check if it exists and is ready $redirectedEntry = entryPeer::retrieveByPK($redirectEntryId); if (!empty($redirectedEntry) && $redirectedEntry->getStatus() == entryStatus::READY) { // Redirected entry is ready. // Set it as the replacement of the original one $filter->set('_eq_id', $redirectEntryId); } else { // Can't redirect? --> Fallback to the original entry $filter->set('_eq_id', $origEntryId); } } } else { throw new kCoreException("Invalid entry id [\"{$origEntryId}\"]", kCoreException::INVALID_ENTRY_ID, $origEntryId); } $filter->unsetByName('_eq_redirect_from_entry_id'); } $categoriesAncestorParsed = null; $categories = $filter->get("_in_category_ancestor_id"); if ($categories !== null) { //if the category exist or the category name is an empty string $categoriesAncestorParsed = $filter->categoryIdsToAllSubCategoriesIdsParsed($categories); if (!($categoriesAncestorParsed !== '' || $categories == '')) { $categoriesAncestorParsed = category::CATEGORY_ID_THAT_DOES_NOT_EXIST; } } $filter->unsetByName('_in_category_ancestor_id'); $categories = $filter->get("_matchor_categories_ids"); if ($categories !== null) { //if the category exist or the category name is an empty string if (is_null($categoriesAncestorParsed)) { $categoriesParsed = $filter->categoryIdsToIdsParsed($categories); } else { $categoriesParsed = $categoriesAncestorParsed; } if ($categoriesParsed !== '' || $categories == '') { $filter->set("_matchor_categories_ids", $categoriesParsed); } else { $filter->set("_matchor_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } } else { $filter->set("_matchor_categories_ids", $categoriesAncestorParsed); } $categories = $filter->get("_matchand_categories_ids"); if ($categories !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryIdsToIdsParsed($categories); if ($categoriesParsed !== '' || $categories == '') { $filter->set("_matchand_categories_ids", $categoriesParsed); } else { $filter->set("_matchand_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } } $categoriesIds = $filter->get("_notcontains_categories_ids"); if ($categoriesIds !== null) { $categoriesParsed = $filter->categoryIdsToAllSubCategoriesIdsParsed($categoriesIds, CategoryEntryStatus::ACTIVE . ',' . CategoryEntryStatus::PENDING . ',' . CategoryEntryStatus::REJECTED); if ($categoriesParsed !== '' || $categoriesIds == '') { $filter->set("_notcontains_categories_ids", $categoriesParsed); } else { $filter->set("_notcontains_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } } $matchAndCats = $filter->get("_matchand_categories"); if ($matchAndCats !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryFullNamesToIdsParsed($matchAndCats, CategoryEntryStatus::ACTIVE); if ($categoriesParsed !== '' || $matchAndCats == '') { $filter->set("_matchand_categories_ids", $categoriesParsed); } else { $filter->set("_matchand_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } $filter->unsetByName('_matchand_categories'); } $matchOrCats = $filter->get("_matchor_categories"); if ($matchOrCats !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryFullNamesToIdsParsed($matchOrCats, CategoryEntryStatus::ACTIVE); if ($categoriesParsed !== '' || $matchOrCats == '') { $filter->set("_matchor_categories_ids", $categoriesParsed); } else { $filter->set("_matchor_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } $filter->unsetByName('_matchor_categories'); } $notContainsCats = $filter->get("_notcontains_categories"); if ($notContainsCats !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryFullNamesToIdsParsed($notContainsCats, CategoryEntryStatus::ACTIVE . ',' . CategoryEntryStatus::PENDING . ',' . CategoryEntryStatus::REJECTED); if ($categoriesParsed !== '' || $notContainsCats == '') { $filter->set("_notcontains_categories_ids", $categoriesParsed); } else { $filter->set("_notcontains_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } $filter->unsetByName('_notcontains_categories'); } // match categories by full name $CatFullNameIn = $filter->get("_in_categories_full_name"); if ($CatFullNameIn !== null) { //if the category exist or the category name is an empty string $categoriesParsed = $filter->categoryFullNamesToIdsParsed($CatFullNameIn, CategoryEntryStatus::ACTIVE); if ($categoriesParsed !== '' || $CatFullNameIn == '') { $filter->set("_matchor_categories_ids", $categoriesParsed); } else { $filter->set("_matchor_categories_ids", category::CATEGORY_ID_THAT_DOES_NOT_EXIST); } $filter->unsetByName('_in_categories_full_name'); } if ($filter->is_set('_is_live')) { $this->addCondition(entryIndex::DYNAMIC_ATTRIBUTES . '.' . LiveEntry::IS_LIVE . ' = ' . ($filter->get('_is_live') == '1' ? '1' : '0')); $filter->unsetByName('_is_live'); } if ($filter->is_set('_is_recorded_entry_id_empty')) { $fieldName = entryIndex::DYNAMIC_ATTRIBUTES . '.' . LiveEntry::RECORDED_ENTRY_ID; $this->addWhere("{$fieldName} " . ($filter->get('_is_recorded_entry_id_empty') ? "IS" : "IS NOT") . " NULL"); $filter->unsetByName('_is_recorded_entry_id_empty'); } $matchOrRoots = array(); if ($filter->is_set('_eq_root_entry_id')) { $matchOrRoots[] = entry::ROOTS_FIELD_ENTRY_PREFIX . ' ' . $filter->get('_eq_root_entry_id'); $filter->unsetByName('_eq_root_entry_id'); } if ($filter->is_set('_in_root_entry_id')) { $roots = explode(baseObjectFilter::IN_SEPARATOR, $filter->get('_in_root_entry_id')); foreach ($roots as $root) { $matchOrRoots[] = entry::ROOTS_FIELD_ENTRY_PREFIX . " {$root}"; } $filter->unsetByName('_in_root_entry_id'); } //When setting parent entry ID we also set the root entry id so the entry should be indexed with the root entry prefix if ($filter->is_set('_eq_parent_entry_id')) { $matchOrRoots[] = entry::ROOTS_FIELD_PARENT_ENTRY_PREFIX . '_' . $filter->get('_eq_parent_entry_id'); $filter->unsetByName('_eq_parent_entry_id'); } if ($filter->is_set('_is_root')) { if ($filter->get('_is_root')) { $filter->set('_notin_roots', entry::ROOTS_FIELD_ENTRY_PREFIX); } else { $matchOrRoots[] = entry::ROOTS_FIELD_ENTRY_PREFIX; } $filter->unsetByName('_is_root'); } if (count($matchOrRoots)) { $filter->set('_matchand_roots', $matchOrRoots); } // if ($filter->get("_matchor_duration_type") !== null) // $filter->set("_matchor_duration_type", $filter->durationTypesToIndexedStrings($filter->get("_matchor_duration_type"))); if ($filter->get(baseObjectFilter::ORDER) === "recent" || $filter->get(baseObjectFilter::ORDER) === "-recent") { $filter->set("_lte_available_from", time()); //$filter->set("_gteornull_end_date", time()); // schedule not finished $filter->set(baseObjectFilter::ORDER, "-available_from"); } if ($filter->get(baseObjectFilter::ORDER) === "+recent") { $filter->set(baseObjectFilter::ORDER, "+available_from"); } if ($filter->get(baseObjectFilter::ORDER) === "-first_broadcast") { $this->addOrderBy(entryIndex::DYNAMIC_ATTRIBUTES . '.' . LiveEntry::FIRST_BROADCAST, Criteria::DESC); $filter->set(baseObjectFilter::ORDER, null); } if ($filter->get(baseObjectFilter::ORDER) === "+first_broadcast") { $this->addOrderBy(entryIndex::DYNAMIC_ATTRIBUTES . '.' . LiveEntry::FIRST_BROADCAST, Criteria::ASC); $filter->set(baseObjectFilter::ORDER, null); } if ($filter->get('_free_text')) { $freeTexts = $filter->get('_free_text'); KalturaLog::debug("Attach free text [{$freeTexts}]"); $additionalConditions = array(); $advancedSearch = $filter->getAdvancedSearch(); if ($advancedSearch) { $additionalConditions = $advancedSearch->getFreeTextConditions($filter->getPartnerSearchScope(), $freeTexts); } $this->addFreeTextToMatchClauseByMatchFields($freeTexts, entryFilter::FREE_TEXT_FIELDS, $additionalConditions); } $filter->unsetByName('_free_text'); return parent::applyFilterFields($filter); }
private function serveLiveEntry() { if (in_array($this->entry->getSource(), LiveEntry::$kalturaLiveSourceTypes)) { if (!$this->entry->hasMediaServer()) { KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_LIVE, "Entry [{$this->entryId}] is not broadcasting"); } kApiCache::setExpiry(120); } $liveStreamConfig = $this->getLiveEntryStreamConfig(); if (!$liveStreamConfig) { KExternalErrors::dieError(KExternalErrors::LIVE_STREAM_CONFIG_NOT_FOUND, "Live stream playbck configuration not found for entry [{$this->entryId}]"); } $cdnHost = parse_url($liveStreamConfig->getUrl(), PHP_URL_HOST); if ($this->deliveryAttributes->getFormat() == PlaybackProtocol::MULTICAST_SL) { $this->deliveryAttributes->setFormat(PlaybackProtocol::HDS); } $this->deliveryProfile = DeliveryProfilePeer::getLiveDeliveryProfileByHostName($cdnHost, $this->deliveryAttributes); if (!$this->deliveryProfile) { return null; } $this->deliveryProfile->setDynamicAttributes($this->deliveryAttributes); return $this->deliveryProfile->serve($liveStreamConfig); }
/** * This action delivers entry-related data, based on the user's context: access control, restriction, playback format and storage information. * @action getContextData * @param string $entryId * @param KalturaEntryContextDataParams $contextDataParams * @return KalturaEntryContextDataResult */ public function getContextData($entryId, KalturaEntryContextDataParams $contextDataParams) { $dbEntry = entryPeer::retrieveByPK($entryId); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } if ($dbEntry->getStatus() != entryStatus::READY) { // the purpose of this is to solve a case in which a player attempts to play a non-ready entry, // and the request becomes cached for a long time, preventing playback even after the entry // becomes ready kApiCache::setExpiry(60); } $asset = null; if ($contextDataParams->flavorAssetId) { $asset = assetPeer::retrieveById($contextDataParams->flavorAssetId); if (!$asset) { throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $contextDataParams->flavorAssetId); } } $contextDataHelper = new kContextDataHelper($dbEntry, $this->getPartner(), $asset); if ($dbEntry->getAccessControl() && $dbEntry->getAccessControl()->hasRules()) { $accessControlScope = $dbEntry->getAccessControl()->getScope(); } else { $accessControlScope = new accessControlScope(); } $contextDataParams->toObject($accessControlScope); $contextDataHelper->buildContextDataResult($accessControlScope, $contextDataParams->flavorTags, $contextDataParams->streamerType, $contextDataParams->mediaProtocol); if ($contextDataHelper->getDisableCache()) { KalturaResponseCacher::disableCache(); } $result = new KalturaEntryContextDataResult(); $result->fromObject($contextDataHelper->getContextDataResult()); $result->flavorAssets = KalturaFlavorAssetArray::fromDbArray($contextDataHelper->getAllowedFlavorAssets()); $result->streamerType = $contextDataHelper->getStreamerType(); $result->mediaProtocol = $contextDataHelper->getMediaProtocol(); $result->storageProfilesXML = $contextDataHelper->getStorageProfilesXML(); $result->isAdmin = $contextDataHelper->getIsAdmin(); $parentEntryId = $dbEntry->getParentEntryId(); if ($parentEntryId) { $dbEntry = $dbEntry->getParentEntry(); if (!$dbEntry) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $parentEntryId); } } $result->isScheduledNow = $dbEntry->isScheduledNow($contextDataParams->time); if (!$result->isScheduledNow && $this->getKs()) { // in case the sview is defined in the ks simulate schedule now true to allow player to pass verification if ($this->getKs()->verifyPrivileges(ks::PRIVILEGE_VIEW, ks::PRIVILEGE_WILDCARD) || $this->getKs()->verifyPrivileges(ks::PRIVILEGE_VIEW, $entryId)) { $result->isScheduledNow = true; } } $result->pluginData = new KalturaPluginDataArray(); $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaEntryContextDataContributor'); foreach ($pluginInstances as $pluginInstance) { $pluginInstance->contributeToEntryContextDataResult($dbEntry, $contextDataParams, $result); } return $result; }