You are here

function kaltura_cron in Kaltura 5

Same name and namespace in other branches
  1. 6.2 kaltura.module \kaltura_cron()
  2. 6 kaltura.module \kaltura_cron()
  3. 7.3 kaltura.module \kaltura_cron()
  4. 7.2 kaltura.module \kaltura_cron()

File

./kaltura.module, line 397

Code

function kaltura_cron() {

  // get all entries from node_kaltura table,
  // use the getEntries service to retrieve the data of entries
  $get_entries = 'SELECT kaltura_entryId FROM {node_kaltura} node_kaltura LEFT JOIN {node} node ON node.nid = node_kaltura.nid WHERE node.status = 1';
  $entries = db_query($get_entries);
  while ($entry = db_fetch_object($entries)) {
    $all_entries[] = $entry->kaltura_entryId;
  }
  if (is_array($all_entries) && count($all_entries)) {
    $my_entries = implode(',', $all_entries);
    $result = kaltura_get_entries($my_entries);
  }
  else {
    $result = FALSE;
  }

  // if we got a good result, we update the entry data in the DB
  if ($result !== FALSE) {
    foreach ($result['entries'] as $key => $entry) {
      $update_entry = 'UPDATE {node_kaltura} SET kstatus = %d, kaltura_views = %d, kaltura_plays = %d, kaltura_rank = %d, kaltura_total_rank = %d,
        kaltura_duration = %d, kaltura_votes = %d, kaltura_thumbnail_url = \'%s\' WHERE kaltura_entryId = \'%s\'';
      if ($entry['duration']) {
        $duration = $entry['duration'];
      }
      else {
        $duration = (int) ($entry['length_in_msecs'] / 1000);
      }
      $updated = db_query($update_entry, $entry['status'], $entry['views'], $entry['plays'], $entry['rank'], $entry['totalRank'], $duration, $entry['votes'], $entry['thumbnailUrl'], $entry['id']);
    }
  }
}