function kaltura_cron in Kaltura 7.3
Same name and namespace in other branches
- 5 kaltura.module \kaltura_cron()
- 6.2 kaltura.module \kaltura_cron()
- 6 kaltura.module \kaltura_cron()
- 7.2 kaltura.module \kaltura_cron()
Implements hook_cron().
File
- ./
kaltura.module, line 552 - Kaltura integration module - core functions.
Code
function kaltura_cron() {
try {
$helpers = new KalturaHelpers();
$client = $helpers
->getKalturaClient(TRUE);
$queue = DrupalQueue::get('kaltura_import_entries');
// Don't fetch remote entries while there are unprocessed ones in the queue.
if (!$queue
->numberOfItems()) {
// Use order by updated date (DESC) because if some entries will be
// updated at the same time while we fetching them then those entries will
// be fetched on the next cron run.
$filter = new KalturaMediaEntryFilter();
$filter->orderBy = KalturaMediaEntryOrderBy::UPDATED_AT_DESC;
$filter->updatedAtGreaterThanOrEqual = variable_get('kaltura_last_imported');
$pager = new KalturaFilterPager();
// @todo Make this value configurable.
$pager->pageSize = 100;
$max_time = NULL;
while (TRUE) {
++$pager->pageIndex;
$result = $client->media
->listAction($filter, $pager);
if (empty($result->objects)) {
break;
}
$entry_ids = array();
foreach ($result->objects as $entry) {
$entry_ids[] = $entry->id;
}
$queue
->createItem($entry_ids);
// Store the maximum of 'updatedAt' property.
if (!isset($max_time)) {
$max_time = reset($result->objects)->updatedAt;
}
}
if (isset($max_time)) {
variable_set('kaltura_last_imported', $max_time);
}
}
} catch (Exception $e) {
watchdog_exception('kaltura', $e);
}
}