You are here

function drush_tweet_feed_tf_import_tweets in Tweet Feed 7.3

Same name and namespace in other branches
  1. 7.2 tweet_feed.drush.inc \drush_tweet_feed_tf_import_tweets()

Import Tweets

Drush command to import all tweets from all feeds or just the one specified. TODO: Allow specifying import by machine name

Implements drush_HOOK_COMMAND().

File

./tweet_feed.drush.inc, line 35

Code

function drush_tweet_feed_tf_import_tweets() {
  $fid = drush_get_option('fid');
  $all = drush_get_option('all');
  $run = FALSE;

  // If we have not specified anything, present a list of available configured feeds to
  // update. Of course, if we only have one feed, then just roll with that
  if (empty($fid) && empty($all)) {

    // If we have one, then roll with it, if we have more, then present a list
    $result = db_query("SELECT fid, feed_name, query_type FROM {tweet_feeds}\n                        ORDER BY feed_name");
    if ($result
      ->rowCount() > 1) {
      $option = array();
      while ($fdata = $result
        ->fetchObject()) {
        switch ($fdata->query_type) {
          case 1:
            $query_type = 'Search';
            break;
          case 2:
            $query_type = 'Timeline';
            break;
          case 3:
            $query_type = 'List';
            break;
        }
        $option[$fdata->fid] = $fdata->feed_name . ' (' . $query_type . ')';
      }
      $choice = drush_choice($option, dt('Which feed would you like to input?'));
      if ($choice && array_key_exists($choice, $option)) {
        tweet_feed_process_feed($choice);
        $run = TRUE;
      }
      else {
        tweet_feed_set_message('Unable to process feed. Illegal feed id specified.', 'fatal');
        $run = TRUE;
      }
    }
    else {
      $feed = $result
        ->fetchObject();
      tweet_feed_process_feed($feed->fid);
      $run = TRUE;
    }
  }

  // If we're processing all, then pass null to the feeds processor
  if (!empty($all) && $run == FALSE) {
    tweet_feed_process_feed(NULL);
    $run = TRUE;
  }
  if ($run == FALSE) {
    $fid = !empty($fid) ? $fid : NULL;
    tweet_feed_process_feed($fid);
  }
}