public static function fromSyndicationFeedArray($arr)
 {
     $newArr = new KalturaBaseSyndicationFeedArray();
     if ($arr == null) {
         return $newArr;
     }
     foreach ($arr as $obj) {
         $nObj = KalturaSyndicationFeedFactory::getInstanceByType($obj->getType());
         $nObj->fromObject($obj);
         $newArr[] = $nObj;
     }
     return $newArr;
 }
 public static function fromDbArray(array $arr, KalturaDetachedResponseProfile $responseProfile = null)
 {
     $newArr = new KalturaBaseSyndicationFeedArray();
     if ($arr == null) {
         return $newArr;
     }
     foreach ($arr as $obj) {
         $nObj = KalturaSyndicationFeedFactory::getInstanceByType($obj->getType());
         $nObj->fromObject($obj, $responseProfile);
         $newArr[] = $nObj;
     }
     return $newArr;
 }
 public function __construct($feedId)
 {
     myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL3;
     $microTimeStart = microtime(true);
     KalturaLog::info("syndicationFeedRenderer- initialize ");
     // initialize the database for all services
     DbManager::setConfig(kConf::getDB());
     DbManager::initialize();
     $syndicationFeedDB = syndicationFeedPeer::retrieveByPK($feedId);
     if (!$syndicationFeedDB) {
         throw new Exception("Feed Id not found");
     }
     $tmpSyndicationFeed = KalturaSyndicationFeedFactory::getInstanceByType($syndicationFeedDB->getType());
     $tmpSyndicationFeed->fromObject($syndicationFeedDB);
     $this->syndicationFeed = $tmpSyndicationFeed;
     // add partner to default criteria
     categoryPeer::addPartnerToCriteria($this->syndicationFeed->partnerId, true);
     flavorAssetPeer::addPartnerToCriteria($this->syndicationFeed->partnerId, true);
     $this->baseCriteria = KalturaCriteria::create(entryPeer::OM_CLASS);
     $startDateCriterion = $this->baseCriteria->getNewCriterion(entryPeer::START_DATE, time(), Criteria::LESS_EQUAL);
     $startDateCriterion->addOr($this->baseCriteria->getNewCriterion(entryPeer::START_DATE, null));
     $this->baseCriteria->addAnd($startDateCriterion);
     $endDateCriterion = $this->baseCriteria->getNewCriterion(entryPeer::END_DATE, time(), Criteria::GREATER_EQUAL);
     $endDateCriterion->addOr($this->baseCriteria->getNewCriterion(entryPeer::END_DATE, null));
     $this->baseCriteria->addAnd($endDateCriterion);
     $entryFilter = new entryFilter();
     $entryFilter->setPartnerSearchScope($this->syndicationFeed->partnerId);
     $entryFilter->setStatusEquel(entryStatus::READY);
     $entryFilter->setTypeIn(array(entryType::MEDIA_CLIP, entryType::MIX));
     $entryFilter->setModerationStatusNot(entry::ENTRY_MODERATION_STATUS_REJECTED);
     $entryFilter->setDurationGreaterThan(0);
     $entryFilter->attachToCriteria($this->baseCriteria);
     if ($this->syndicationFeed->playlistId) {
         $this->entryFilters = myPlaylistUtils::getPlaylistFiltersById($this->syndicationFeed->playlistId);
     } else {
         $this->entryFilters = array();
     }
     $microTimeEnd = microtime(true);
     KalturaLog::info("syndicationFeedRenderer- initialization done [" . ($microTimeEnd - $microTimeStart) . "]");
 }
예제 #4
0
 /**
  * Update Syndication Feed by ID
  * 
  * @action update
  * @param string $id
  * @param KalturaBaseSyndicationFeed $syndicationFeed
  * @return KalturaBaseSyndicationFeed
  */
 public function updateAction($id, KalturaBaseSyndicationFeed $syndicationFeed)
 {
     $syndicationFeedDB = syndicationFeedPeer::retrieveByPK($id);
     if (!$syndicationFeedDB) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $id);
     }
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed && $syndicationFeed->xslt != null) {
         $syndicationFeed->validateXslt();
         $syndicationFeedDB->incrementVersion();
         $syndicationFeedDB->save();
     }
     $syndicationFeed->type = null;
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed && $syndicationFeed->xslt != null) {
         $key = $syndicationFeedDB->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
         kFileSyncUtils::file_put_contents($key, $syndicationFeed->xslt);
     }
     $syndicationFeed = $syndicationFeed->toUpdatableObject($syndicationFeedDB, array('type'));
     $syndicationFeedDB->save();
     $syndicationFeed = KalturaSyndicationFeedFactory::getInstanceByType($syndicationFeedDB->getType());
     $syndicationFeed->fromObject($syndicationFeedDB);
     return $syndicationFeed;
 }
예제 #5
0
 /**
  * Update Syndication Feed by ID
  * 
  * @action update
  * @param string $id
  * @param KalturaBaseSyndicationFeed $syndicationFeed
  * @return KalturaBaseSyndicationFeed
  * @throws KalturaErrors::INVALID_FEED_ID
  */
 public function updateAction($id, KalturaBaseSyndicationFeed $syndicationFeed)
 {
     $syndicationFeedDB = syndicationFeedPeer::retrieveByPK($id);
     if (!$syndicationFeedDB) {
         throw new KalturaAPIException(KalturaErrors::INVALID_FEED_ID, $id);
     }
     $syndicationFeed->validateStorageId($this->getPartnerId());
     $syndicationFeed->toUpdatableObject($syndicationFeedDB, array('type'));
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed && $syndicationFeed->xslt != null) {
         if (!$syndicationFeedDB instanceof genericSyndicationFeed) {
             throw new KalturaAPIException(KalturaErrors::INVALID_FEED_TYPE, get_class($syndicationFeedDB));
         }
         $syndicationFeedDB->incrementVersion();
     }
     $syndicationFeedDB->save();
     if ($syndicationFeed instanceof KalturaGenericXsltSyndicationFeed && $syndicationFeed->xslt != null) {
         $key = $syndicationFeedDB->getSyncKey(genericSyndicationFeed::FILE_SYNC_SYNDICATION_FEED_XSLT);
         kFileSyncUtils::file_put_contents($key, $syndicationFeed->xslt);
     }
     $syndicationFeed->type = null;
     $syndicationFeed = KalturaSyndicationFeedFactory::getInstanceByType($syndicationFeedDB->getType());
     $syndicationFeed->fromObject($syndicationFeedDB, $this->getResponseProfile());
     return $syndicationFeed;
 }
 public function execute($limit = 0)
 {
     if ($this->executed) {
         return;
     }
     if ($limit) {
         $this->limit = $limit;
     }
     $microTimeStart = microtime(true);
     $renderer = KalturaSyndicationFeedFactory::getRendererByType($this->syndicationFeed->type);
     $renderer->init($this->syndicationFeed, $this->syndicationFeedDb, $this->mimeType);
     header($renderer->handleHttpHeader());
     echo $renderer->handleHeader();
     $cacheStore = null;
     if ($renderer->shouldEnableCache()) {
         $cacheStore = kCacheManager::getSingleLayerCache(kCacheManager::CACHE_TYPE_FEED_ENTRY);
     }
     $protocol = infraRequestUtils::getProtocol();
     $cachePrefix = "feed_{$this->syndicationFeed->id}/{$protocol}/entry_";
     $feedUpdatedAt = $this->syndicationFeedDb->getUpdatedAt(null);
     $e = null;
     $kalturaFeed = $this->syndicationFeed->type == KalturaSyndicationFeedType::KALTURA || $this->syndicationFeed->type == KalturaSyndicationFeedType::KALTURA_XSLT;
     $nextEntry = $this->getNextEntry();
     while ($nextEntry) {
         $this->enableApcProcessingFlag();
         $entry = $nextEntry;
         $nextEntry = $this->getNextEntry();
         // in case no video player is requested by user and the entry is mix, skip it
         if ($entry->getType() === entryType::MIX && !$this->syndicationFeed->allowEmbed) {
             continue;
         }
         $xml = false;
         // check cache
         $updatedAt = max($feedUpdatedAt, $entry->getUpdatedAt(null));
         if ($cacheStore) {
             $cacheKey = $cachePrefix . str_replace("_", "-", $entry->getId()) . self::CACHE_VERSION;
             // replace _ with - so cache folders will be created with random entry id and not 0_/1_
             $cacheTime = $cacheStore->get($cacheKey . self::CACHE_CREATION_TIME_SUFFIX);
             if ($cacheTime !== false && $cacheTime > $updatedAt + self::CACHE_CREATION_MARGIN) {
                 $xml = $cacheStore->get($cacheKey);
             }
         }
         if ($xml === false) {
             $e = null;
             if (!$kalturaFeed) {
                 $e = new KalturaMediaEntry();
                 $e->fromObject($entry);
             }
             $flavorAssetUrl = is_null($e) ? null : $this->getFlavorAssetUrl($e);
             if (!$kalturaFeed && $entry->getType() !== entryType::MIX && is_null($flavorAssetUrl)) {
                 $xml = "";
                 // cache empty result to avoid checking getFlavorAssetUrl next time
             } else {
                 $xml = $renderer->handleBody($entry, $e, $flavorAssetUrl);
             }
         }
         if ($cacheStore) {
             $cacheStore->set($cacheKey . self::CACHE_CREATION_TIME_SUFFIX, time(), self::CACHE_EXPIRY);
             $cacheStore->set($cacheKey, $xml, self::CACHE_EXPIRY);
         }
         echo $renderer->finalize($xml, $nextEntry !== false);
     }
     echo $renderer->handleFooter();
     if ($this->feedProcessingKey && function_exists('apc_delete')) {
         apc_delete($this->feedProcessingKey);
     }
     $microTimeEnd = microtime(true);
     KalturaLog::info("syndicationFeedRenderer- render time for ({$this->syndicationFeed->type}) is " . ($microTimeEnd - $microTimeStart));
 }
 public function __construct($feedId)
 {
     myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL3;
     $microTimeStart = microtime(true);
     KalturaLog::info("syndicationFeedRenderer- initialize ");
     // initialize the database for all services
     DbManager::setConfig(kConf::getDB());
     DbManager::initialize();
     $this->syndicationFeedDB = $syndicationFeedDB = syndicationFeedPeer::retrieveByPK($feedId);
     if (!$syndicationFeedDB) {
         throw new Exception("Feed Id not found");
     }
     kEntitlementUtils::initEntitlementEnforcement($syndicationFeedDB->getPartnerId(), $syndicationFeedDB->getEnforceEntitlement());
     if (!is_null($syndicationFeedDB->getPrivacyContext()) && $syndicationFeedDB->getPrivacyContext() != '') {
         kEntitlementUtils::setPrivacyContextSearch($syndicationFeedDB->getPrivacyContext());
     }
     $tmpSyndicationFeed = KalturaSyndicationFeedFactory::getInstanceByType($syndicationFeedDB->getType());
     $tmpSyndicationFeed->fromObject($syndicationFeedDB);
     $this->syndicationFeed = $tmpSyndicationFeed;
     // add partner to default criteria
     categoryPeer::addPartnerToCriteria($this->syndicationFeed->partnerId, true);
     assetPeer::addPartnerToCriteria($this->syndicationFeed->partnerId, true);
     entryPeer::setDefaultCriteriaFilter();
     $this->baseCriteria = entryPeer::getDefaultCriteriaFilter();
     $startDateCriterion = $this->baseCriteria->getNewCriterion(entryPeer::START_DATE, time(), Criteria::LESS_EQUAL);
     $startDateCriterion->addOr($this->baseCriteria->getNewCriterion(entryPeer::START_DATE, null));
     $this->baseCriteria->addAnd($startDateCriterion);
     $endDateCriterion = $this->baseCriteria->getNewCriterion(entryPeer::END_DATE, time(), Criteria::GREATER_EQUAL);
     $endDateCriterion->addOr($this->baseCriteria->getNewCriterion(entryPeer::END_DATE, null));
     $this->baseCriteria->addAnd($endDateCriterion);
     $entryFilter = new entryFilter();
     $entryFilter->setPartnerSearchScope($this->syndicationFeed->partnerId);
     $entryFilter->setStatusEquel(entryStatus::READY);
     $entryFilter->setTypeIn(array(entryType::MEDIA_CLIP, entryType::MIX));
     $entryFilter->setModerationStatusNotIn(array(entry::ENTRY_MODERATION_STATUS_REJECTED, entry::ENTRY_MODERATION_STATUS_PENDING_MODERATION));
     $entryFilter->attachToCriteria($this->baseCriteria);
     if ($this->syndicationFeed->playlistId) {
         $this->entryFilters = myPlaylistUtils::getPlaylistFiltersById($this->syndicationFeed->playlistId);
         foreach ($this->entryFilters as $entryFilter) {
             $entryFilter->setPartnerSearchScope(baseObjectFilter::MATCH_KALTURA_NETWORK_AND_PRIVATE);
             // partner scope already attached
         }
         $playlist = entryPeer::retrieveByPK($this->syndicationFeed->playlistId);
         if ($playlist) {
             if ($playlist->getMediaType() != entry::ENTRY_MEDIA_TYPE_XML) {
                 $this->staticPlaylist = true;
                 $this->staticPlaylistEntriesIdsOrder = explode(',', $playlist->getDataContent());
             }
         }
     } else {
         $this->entryFilters = array();
     }
     $microTimeEnd = microtime(true);
     KalturaLog::info("syndicationFeedRenderer- initialization done [" . ($microTimeEnd - $microTimeStart) . "]");
 }