Index: twitter.module =================================================================== --- twitter.module (revision 36458) +++ twitter.module (revision 37078) @@ -163,45 +163,50 @@ * Imports new Twitter statuses for site users, and deletes expired tweets. */ function twitter_cron() { - if (!variable_get('twitter_import', TRUE)) { - return; - } + try { + if (!variable_get('twitter_import', TRUE)) { + return; + } - module_load_include('inc', 'twitter'); + 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. + // 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 tu.screen_name, tu.password, ta.protected FROM {twitter_user} tu "; - $sql .= "LEFT JOIN {twitter_account} ta ON tu.screen_name = ta.screen_name "; - $sql .= "WHERE tu.import = 1 ORDER BY ta.last_refresh ASC"; + $sql = "SELECT tu.screen_name, tu.password, ta.protected FROM {twitter_user} tu "; + $sql .= "LEFT JOIN {twitter_account} ta ON tu.screen_name = ta.screen_name "; + $sql .= "WHERE tu.import = 1 ORDER BY ta.last_refresh ASC"; - $results = db_query_range($sql, 0, 20); - while ($account = db_fetch_array($results)) { - // Use the 'cheaper' unauthenticated version if the account isn't protected, - // or if a password hasn't been specified. - if (empty($account['protected']) || empty($account['password'])) { - $statuses = twitter_fetch_timeline($account['screen_name']); + $results = db_query_range($sql, 0, 20); + while ($account = db_fetch_array($results)) { + // Use the 'cheaper' unauthenticated version if the account isn't protected, + // or if a password hasn't been specified. + if (empty($account['protected']) || empty($account['password'])) { + $statuses = twitter_fetch_timeline($account['screen_name']); + } + else { + $statuses = twitter_fetch_statuses($account['screen_name'], $account['password']); + } + + // If we got results back, update the account information with the latest + // follower count, location, user picture, etc. Also, touch the account's + // last_refreshed timestamp so it won't get thrashed before other, staler + // accounts. + if (!empty($statuses)) { + twitter_cache_account($statuses[0]['account']); + } + twitter_touch_account($account['screen_name']); } - else { - $statuses = twitter_fetch_statuses($account['screen_name'], $account['password']); - } - // If we got results back, update the account information with the latest - // follower count, location, user picture, etc. Also, touch the account's - // last_refreshed timestamp so it won't get thrashed before other, staler - // accounts. - if (!empty($statuses)) { - twitter_cache_account($statuses[0]['account']); + // Nuke old statuses. + if ($age = variable_get('twitter_expire', 0)) { + db_query('DELETE FROM {twitter} WHERE created_time < %d', time() - $age); } - twitter_touch_account($account['screen_name']); } - - // Nuke old statuses. - if ($age = variable_get('twitter_expire', 0)) { - db_query('DELETE FROM {twitter} WHERE created_time < %d', time() - $age); - } + catch (Exception $e) { + watchdog('twitter', 'Cron run for twitter module failed with exception !exception.', array('!exception' => $e)); + } }