function tweet_feed_run_import in Tweet Feed 7.2
Same name and namespace in other branches
- 7.3 tweet_feed_admin.inc \tweet_feed_run_import()
Run the Import
Handled through the web interface using the batch API
1 string reference to 'tweet_feed_run_import'
- tweet_feed_menu in ./
tweet_feed.module - Implements hook_menu().
File
- ./
tweet_feed_admin.inc, line 601
Code
function tweet_feed_run_import($fid) {
// Get all of the tweets to be imported
$tweets = tweet_feed_pull_data_from_feed($fid, TRUE);
// Get the feed info for our display
$feed = tweet_feed_get_feed_object($fid);
switch ($feed->query_type) {
case QUERY_SEARCH:
$query_type = 'Timeline Search';
$feed_criteria = $feed->search_term;
break;
case QUERY_TIMELINE:
$query_type = 'User Timeline';
$feed_criteria = $feed->timeline_id;
break;
case QUERY_LIST:
$query_type = 'User List';
$feed_criteria = $feed->timeline_id . '/' . $feed->list_name;
break;
default:
$query_type = t('Unknown');
$feed_criteria = t('Unknown');
}
// Now that we have the tweets, put them in the queue
$batch = array(
'title' => t('Tweet Feed Import Batch: Feed: ' . $query_type . ': ' . $feed_criteria),
'init_message' => t('Loading tweets...'),
'operations' => array(),
'finished' => 'tweet_feed_run_import_finish',
);
foreach ($tweets as $key => $tweet) {
// Initialize our update_node_id
$update_node_id = 0;
$hash = NULL;
// find out if we already have this tweet, if we do, add the update primary key (pk)
$result = db_select('tweet_hashes', 't')
->fields('t', array(
'nid',
'tid',
'hash',
))
->condition('t.tid', $tweet->id)
->execute();
if ($result
->rowCount() > 0) {
$tdata = $result
->fetchObject();
$hash = md5(serialize($tweet));
// If our hashes are equal, we have nothing to update and can move along
if ($hash == $tdata->hash) {
continue;
}
else {
$update_node_id = $tdata->nid;
}
}
$batch['operations'][] = array(
'tweet_feed_save_tweet',
array(
$tweet,
$feed,
$update_node_id,
$hash,
),
);
}
batch_set($batch);
batch_process('admin/config/services/tweet_feed/feeds');
}