/** * Looks for the time that is stored under ks privilege as reference time. * If not found, returns time(). * * @param bool $notifyApiCache * @return int */ public static function getTime($notifyApiCache = true) { if (kCurrentContext::$ks_object) { $referenceTime = kCurrentContext::$ks_object->getPrivilegeValue(ks::PRIVILEGE_REFERENCE_TIME); if ($referenceTime) { return (int) $referenceTime; } } if ($notifyApiCache) { return kApiCache::getTime(); } else { return time(); } }
private static function addSchedulingToCriteria(Criteria $c) { $startDateCriterion = $c->getNewCriterion(entryPeer::START_DATE, kApiCache::getTime(), Criteria::LESS_EQUAL); $startDateCriterion->addOr($c->getNewCriterion(entryPeer::START_DATE, null)); $endDateCriterion = $c->getNewCriterion(entryPeer::END_DATE, kApiCache::getTime(), Criteria::GREATER_EQUAL); $endDateCriterion->addOr($c->getNewCriterion(entryPeer::END_DATE, null)); $c->addAnd($startDateCriterion); $c->addAnd($endDateCriterion); }
public function unsetMediaServer($index, $hostname) { $server = $this->getFromCustomData("server-{$index}", LiveEntry::CUSTOM_DATA_NAMESPACE_MEDIA_SERVERS); if ($server && $server->getHostname() == $hostname) { $server = $this->removeFromCustomData("server-{$index}", LiveEntry::CUSTOM_DATA_NAMESPACE_MEDIA_SERVERS); $this->setLastBroadcastEndTime(kApiCache::getTime()); } if (!$this->hasMediaServer()) { $this->setLiveStatus(LiveEntryStatus::STOPPED); } }
private static function addSchedulingToCriteria(Criteria $c, entryFilter $filter = null) { $min = 0; $max = kApiCache::getTime(); $allowNull = true; if ($filter) { if ($filter->is_set('_lteornull_start_date')) { $max = min($max, $filter->get('_lteornull_start_date')); $filter->unsetByName('_lteornull_start_date'); } if ($filter->is_set('_gteornull_start_date')) { $min = max($min, $filter->get('_gteornull_start_date')); $filter->unsetByName('_gteornull_start_date'); } if ($filter->is_set('_lte_start_date')) { $max = min($max, $filter->get('_lte_start_date')); $allowNull = false; $filter->unsetByName('_lte_start_date'); } if ($filter->is_set('_gte_start_date')) { $min = max($min, $filter->get('_gte_start_date')); $allowNull = false; $filter->unsetByName('_gte_start_date'); } } self::addSchedulingCriterion($c, entryPeer::START_DATE, $min, $max, $allowNull); $min = kApiCache::getTime(); $max = 0; $allowNull = true; if ($filter) { if ($filter->is_set('_lteornull_end_date')) { $max = min($max, $filter->get('_lteornull_end_date')); $filter->unsetByName('_lteornull_end_date'); } if ($filter->is_set('_gteornull_end_date')) { $min = max($min, $filter->get('_gteornull_end_date')); $filter->unsetByName('_gteornull_end_date'); } if ($filter->is_set('_lte_end_date')) { $max = min($max, $filter->get('_lte_end_date')); $allowNull = false; $filter->unsetByName('_lte_end_date'); } if ($filter->is_set('_gte_end_date')) { $min = max($min, $filter->get('_gte_end_date')); $allowNull = false; $filter->unsetByName('_gte_end_date'); } } self::addSchedulingCriterion($c, entryPeer::END_DATE, $min, $max, $allowNull); }
/** * @return int $time */ public function getTime() { if (is_null($this->time)) { return kApiCache::getTime(); } return $this->time; }
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", kApiCache::getTime()); //$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); }
public static function createKSessionNoValidations($partner_id, $puser_id, &$ks_str, $desired_expiry_in_seconds = 86400, $admin = false, $partner_key = "", $privileges = "") { $ks_max_expiry_in_seconds = myPartnerUtils::getExpiry($partner_id); if ($ks_max_expiry_in_seconds && $ks_max_expiry_in_seconds < $desired_expiry_in_seconds) { $desired_expiry_in_seconds = $ks_max_expiry_in_seconds; } $ks = new ks(); $ks->valid_until = kApiCache::getTime() + $desired_expiry_in_seconds; // store in milliseconds to make comparison easier at validation time // $ks->type = $admin ? ks::TYPE_KAS : ks::TYPE_KS; if ($admin == false) { $ks->type = ks::TYPE_KS; } else { $ks->type = $admin; } // if the admin > 1 - use it rather than automatially setting it to be 2 $ks->partner_id = $partner_id; $ks->partner_pattern = $partner_id; $ks->error = 0; $ks->rand = microtime(true); $ks->user = $puser_id; $ks->privileges = $privileges; $ks_str = $ks->toSecureString(); return 0; }
public function unsetMediaServer($index, $hostname) { $server = $this->getFromCustomData("server-{$index}", LiveEntry::CUSTOM_DATA_NAMESPACE_MEDIA_SERVERS); if ($server && $server->getHostname() == $hostname) { $server = $this->removeFromCustomData("server-{$index}", LiveEntry::CUSTOM_DATA_NAMESPACE_MEDIA_SERVERS); $this->setLastBroadcastEndTime(kApiCache::getTime()); } // Set media server with index #index to be stopped // the entry->liveStatus() is calculated from the state of both servers $this->setLiveStatus(LiveEntryStatus::STOPPED, $index); }