Run hook_cron on submit

In twitter module imported status only get updated on cron run. So whenever a account is added in the twitter block nothing is displayed. So i run hook_cron on submit, i just added the hook_cron in custom submit handler as in last post.

function twitter_account_form_submit_custom($form, &$form_state) {
module_load_include('lib.php', 'twitter','twitter');
module_load_include('inc', 'twitter','twitter');
$name = ($form_state['profiles']['main']->field_twitter_handle['und'][0]['value']);
$twitter = new Twitter($name);
try {
$account = $twitter->users_show($name, FALSE);
} catch (TwitterException $e) {
form_set_error('screen_name', t('Request failed: @message.', array('@message' => $e->getMessage())));
return;
}
$uid= $form_state['values']['uid'];
$result = db_select('twitter_account' , 't')
->fields('t')
->condition('uid',$uid, '=')
->execute()
->fetchAssoc();
if($result){
db_delete('twitter_account')
->condition('uid', $uid, '=')
->execute();
}
twitter_account_save($account, TRUE, user_load($form_state['values']['uid']));
twitter_cron();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s