Skip to content

Commit

Permalink
Merge pull request kaltura#9149 from kaltura/Orion-15.16.0-SUP-20392
Browse files Browse the repository at this point in the history
SUP-20392:make syndication feed with dynamic playlist work the same as playlist executeFromFilter
  • Loading branch information
ravitshalem authored Feb 9, 2020
2 parents 823a342 + 05962d4 commit 16da998
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 5 deletions.
157 changes: 153 additions & 4 deletions api_v3/lib/syndication/KalturaSyndicationFeedRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class KalturaSyndicationFeedRenderer
const CACHE_EXPIRY = 2592000; // 30 days

const PAGE_SIZE_MAX_VALUE = 500;

const DYNAMIC_TOTAL_RESULTS = 200;

/**
* Maximum number of items to list
Expand Down Expand Up @@ -88,6 +90,11 @@ class KalturaSyndicationFeedRenderer
* @var bool
*/
private $staticPlaylist = false;

/**
* @var bool
*/
private $dynamicPlaylist = false;

/**
* @var string
Expand All @@ -110,6 +117,12 @@ class KalturaSyndicationFeedRenderer
* @var bool
*/
private $addLinkForNextIteration = false;

/**
* Stores the handled entries in dynamic playlist
* @var array<entry>
*/
private $entryIdsHandled = null;

public function __construct($feedId, $feedProcessingKey = null, $ks = null, $state = null)
{
Expand Down Expand Up @@ -212,6 +225,10 @@ public function __construct($feedId, $feedProcessingKey = null, $ks = null, $sta
$this->staticPlaylist = true;
$this->staticPlaylistEntriesIdsOrder = explode(',', $playlist->getDataContent());
}
else
{
$this->dynamicPlaylist = true;
}
}
}
else
Expand Down Expand Up @@ -308,7 +325,11 @@ public function getEntriesCount()
$c->applyFilters();
return $c->getRecordsCount();
}


if ($this->dynamicPlaylist)
{
return $this->getEntriesCountFromDynamic();
}
$count = 0;
foreach($this->entryFilters as $entryFilter)
{
Expand All @@ -319,6 +340,21 @@ public function getEntriesCount()
}
return $count;
}

public function getEntriesCountFromDynamic()
{
$kalturaEntries = array();
foreach($this->entryFilters as $entryFilter)
{
list($mediaEntryFilterForPlaylist, $playlistService) = self::prepareParameters($entryFilter);
$entriesFromFilter = $this->getEntriesFromPlaylist($playlistService, $mediaEntryFilterForPlaylist);
foreach ($entriesFromFilter as $entry)
{
$kalturaEntries[$entry->id] = $entry->id;
}
}
return count($kalturaEntries);
}

public function getEntriesIds()
{
Expand Down Expand Up @@ -351,6 +387,58 @@ public function getEntriesIds()
}
return $entries;
}

public function getNextEntryByPlaylistType()
{
if ($this->dynamicPlaylist)
{
return $this->getNextEntryViaDynamic();
}
else
{
return $this->getNextEntry();
}
}

public function getNextEntryViaDynamic()
{
if(!$this->executed)
{
$this->entryIdsHandled = array();
$this->entriesCurrentPage = array();
}

$this->returnedEntriesCount++;
if ($this->returnedEntriesCount > $this->limit)
{
return false;
}

if (!$this->entriesCurrentPage)
{
$this->fetchNextEntriesAccordingToFilter();
}

while($this->entriesCurrentPage)
{
while (current($this->entriesCurrentPage) !== false)
{
$entry = entryPeer::retrieveByPK(current($this->entriesCurrentPage)->id);
if ($entry)
{
if (!array_key_exists($entry->getId(), $this->entryIdsHandled))
{
$this->entryIdsHandled[$entry->getId()] = $entry->getId();
next($this->entriesCurrentPage);
return $entry;
}
}
next($this->entriesCurrentPage);
}
$this->fetchNextEntriesAccordingToFilter();
}
return null;
}

public function getNextEntry()
{
Expand Down Expand Up @@ -466,7 +554,68 @@ private function fetchNextPage()
$this->entriesCurrentPage = $nextPage;
reset($this->entriesCurrentPage);
}


protected function fetchNextEntriesAccordingToFilter()
{
$this->entriesCurrentPage = null;
$currentFilter = $this->getNextFilter();
if (!$currentFilter)
{
return;
}

list($mediaEntryFilterForPlaylist, $playlistService) = self::prepareParameters($currentFilter);
$entriesFromFilter = self::getEntriesFromPlaylist($playlistService, $mediaEntryFilterForPlaylist);
if(!count($entriesFromFilter->toArray()))
{
return;
}
$this->entriesCurrentPage = $entriesFromFilter->toArray();
reset($this->entriesCurrentPage);
}

protected static function prepareParameters($currentFilter)
{
$mediaEntryFilterForPlaylist = new mediaEntryFilterForPlaylist();
$mediaEntryFilterForPlaylist->fields = $currentFilter->fields;
$mediaEntryFilterForPlaylist->fields['_name'] = null;

$playlistService = new PlaylistService();
return array($mediaEntryFilterForPlaylist, $playlistService);
}

protected function getEntriesFromPlaylist($playlistService, $mediaEntryFilterForPlaylist)
{
$kalturaMediaEntryFilterForPlaylist = new KalturaMediaEntryFilterForPlaylist();
$kalturaMediaEntryFilterForPlaylist->fromObject($mediaEntryFilterForPlaylist);

$kalturaMediaEntryFilterForPlaylistArray = new KalturaMediaEntryFilterForPlaylistArray();
$kalturaMediaEntryFilterForPlaylistArray->offsetSet(null, $kalturaMediaEntryFilterForPlaylist);

return $playlistService->executeFromFiltersAction($kalturaMediaEntryFilterForPlaylistArray, self::DYNAMIC_TOTAL_RESULTS);
}

protected function getNextFilter()
{
if(!$this->executed && count($this->entryFilters))
{
reset($this->entryFilters);
}
$this->executed = true;
if(!count($this->entryFilters))
{
return null;
}

$filter = current($this->entryFilters);
if($filter === false)
{
return null;
}
next($this->entryFilters);
return $filter;
}

/**
* @return KalturaCriteria
*/
Expand Down Expand Up @@ -549,7 +698,7 @@ public function execute($limit = 0)

$e = null;
$kalturaFeed = $this->syndicationFeed->type == KalturaSyndicationFeedType::KALTURA || in_array($this->syndicationFeed->type, array(KalturaSyndicationFeedType::KALTURA_XSLT, KalturaSyndicationFeedType::ROKU_DIRECT_PUBLISHER, KalturaSyndicationFeedType::OPERA_TV_SNAP));
$nextEntry = $this->getNextEntry();
$nextEntry = $this->getNextEntryByPlaylistType();

$lastCreatedAtVal = null;
$tempCreatedAtVal = null;
Expand All @@ -570,7 +719,7 @@ public function execute($limit = 0)
}
$this->enableApcProcessingFlag();
$entry = $nextEntry;
$nextEntry = $this->getNextEntry();
$nextEntry = $this->getNextEntryByPlaylistType();

if(is_null($this->lastEntryCreatedAt))
$lastCreatedAtVal = null;
Expand Down
3 changes: 2 additions & 1 deletion api_v3/services/PlaylistService.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,15 @@ function executeAction( $id , $detailed = false, KalturaContext $playlistContext
*/
function executeFromContentAction($playlistType, $playlistContent, $detailed = false, $pager = null)
{
$partnerId = $this->getPartnerId() ? $this->getPartnerId() : kCurrentContext::getCurrentPartnerId();
myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL3;
if ($this->getKs() && is_object($this->getKs()) && $this->getKs()->isAdmin())
{
myPlaylistUtils::setIsAdminKs(true);
}
list($entryFiltersViaEsearch, $entryFiltersViaSphinx, $totalResults) = myPlaylistUtils::splitEntryFilters($playlistContent);
$pagerSeparateQueries = self::decideWhereHandlingPager($pager,$entryFiltersViaEsearch, $entryFiltersViaSphinx);
$entryList = self::handlePlaylistByType($playlistType, $entryFiltersViaEsearch, $entryFiltersViaSphinx, $this->getPartnerId(), $pagerSeparateQueries, $pager, $totalResults, $playlistContent);
$entryList = self::handlePlaylistByType($playlistType, $entryFiltersViaEsearch, $entryFiltersViaSphinx, $partnerId, $pagerSeparateQueries, $pager, $totalResults, $playlistContent);
myEntryUtils::updatePuserIdsForEntries($entryList);
KalturaLog::debug("entry ids count: " . count($entryList));
return KalturaBaseEntryArray::fromDbArray($entryList, $this->getResponseProfile());
Expand Down

0 comments on commit 16da998

Please sign in to comment.