You are here

function drupagram_cron in Drupagram 7

Same name and namespace in other branches
  1. 6 drupagram.module \drupagram_cron()

Implements hook_cron().

Imports new Instagram statuses for site users, and deletes expired media.

File

./drupagram.module, line 173
Provides API integration with the Instagram microblogging service.

Code

function drupagram_cron() {
  if (!variable_get('drupagram_import', TRUE)) {
    return;
  }

  // Pull up a list of Instagram accounts that are flagged for updating,
  // sorted by how long it's been since we last updated them. This ensures
  // that the most out-of-date accounts get updated first.
  module_load_include('inc', 'drupagram');
  $result = db_query_range("SELECT drupagram_id FROM {drupagram_account} WHERE import = :import ORDER BY last_refresh ASC", 0, 20, array(
    ':import' => 1,
  ));
  foreach ($result as $account) {

    // drupagram_fetch_user_feed($account->drupagram_id);
    drupagram_fetch_recent_items($account->drupagram_id);
  }

  // Nuke old items.
  if ($age = variable_get('drupagram_expire', 0)) {
    db_delete('drupagram')
      ->condition('created_time', REQUEST_TIME - $age, '<')
      ->execute();
  }
}