You are here

function twitter_cron in Twitter 6.4

Same name and namespace in other branches
  1. 6.5 twitter.module \twitter_cron()
  2. 6.2 twitter.module \twitter_cron()
  3. 6.3 twitter.module \twitter_cron()
  4. 7.6 twitter.module \twitter_cron()
  5. 7.3 twitter.module \twitter_cron()
  6. 7.4 twitter.module \twitter_cron()
  7. 7.5 twitter.module \twitter_cron()

Implementation of hook_cron()

Imports new Twitter statuses for site users, and deletes expired tweets.

1 call to twitter_cron()
TwitterTest::testAccountAdditionNoOauth in tests/core.test
Tests account addition process

File

./twitter.module, line 130
Establishes an interface to communicate with Twitter

Code

function twitter_cron() {
  if (!variable_get('twitter_import', TRUE)) {
    return;
  }
  module_load_include('inc', 'twitter');

  // Pull up a list of Twitter 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.
  $sql = "SELECT twitter_uid FROM {twitter_account} WHERE import = 1 ORDER BY last_refresh ASC";
  $results = db_query_range($sql, 0, 20);
  while ($account = db_fetch_object($results)) {
    twitter_fetch_user_timeline($account->twitter_uid);
  }

  // Nuke old statuses.
  if ($age = variable_get('twitter_expire', 0)) {
    db_query('DELETE FROM {twitter} WHERE created_time < %d', time() - $age);
  }
}