function _eloqua_cron in Eloqua 7
Same name and namespace in other branches
- 6 eloqua.cron.inc \_eloqua_cron()
Cron helper function.
Parameters
object $post: Saved post.
2 calls to _eloqua_cron()
- eloqua_webform_cron in eloqua_webform/
eloqua_webform.module - Implements hook_cron().
- eloqua_webform_submit in eloqua_webform/
eloqua_webform.module - Form submission handler for eloqua_admin_form().
File
- eloqua_webform/
eloqua_webform.cron.inc, line 16 - Cron Support Functions for Eloqua
Code
function _eloqua_cron($post = NULL) {
$posts = array();
// If post passed into this function, only process this post.
if ($post) {
$posts = array(
$post,
);
}
else {
$result_set = db_select('eloqua_saved_posts')
->fields('eloqua_saved_posts')
->condition('status', ELOQUA_STATUS_NEW)
->range(0, (int) variable_get('batch_size', 50))
->execute()
->fetchAll();
$posts = _eloqua_unserialize_data_column($result_set);
}
// If nothnig to do, or something funky happened, bail.
if (empty($posts) || !is_array($posts)) {
return;
}
foreach ($posts as $post) {
if (!is_array($post->data)) {
$post->data = array();
}
if (!empty($post->data['form_post']['elqSiteId'])) {
$elqSiteId = $post->data['form_post']['elqSiteId'];
}
else {
// Bail if no site id, because we can't generate proper url without it.
return;
}
$url = 'http://s' . $elqSiteId . '.t.eloqua.com/e/f2';
$original_headers = $post->data['user_headers'];
$headers = array(
'Accept-Language' => array_key_exists('accept-language', $original_headers) ? $original_headers['accept-language'] : 'en',
'User-Agent' => array_key_exists('user-agent', $original_headers) ? $original_headers['user-agent'] : 'User Relay',
'Content-Type' => 'application/x-www-form-urlencoded',
);
// Fetch the post fields to send to Eloqua.
$post_fields = _eloqua_cron_get_post_fields($post);
$options = array(
'method' => 'POST',
'timeout' => 5,
'headers' => $headers,
'data' => drupal_http_build_query($post_fields),
);
$result = drupal_http_request($url, $options);
// Update post data.
$post->data['server_post'][] = array(
'timestamp' => time(),
'response' => $result,
'http_status' => $result->code,
);
if ($result->code == '200') {
$post->{'status'} = ELOQUA_STATUS_UPLOADED;
}
else {
$post->{'status'} = ELOQUA_STATUS_FAILED;
}
eloqua_post_update($post);
}
}