| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
// by James Glasgow (jrglasgow) of Tribute Media - http://www.tributemedia.com
|
| 4 |
|
| 5 |
/**
|
| 6 |
* Implementation of hook_cron().
|
| 7 |
*/
|
| 8 |
function http_request_fail_reset_cron() {
|
| 9 |
// check to see if the check needs to be performed
|
| 10 |
$total_interval = variable_get('http_request_fail_reset_interval', 86400) * variable_get('http_request_fail_reset_interval_multiplier', 1);
|
| 11 |
$now = time();
|
| 12 |
$last_checked = variable_get('http_request_fail_reset_last_checked', 0);
|
| 13 |
if ($now - $last_checked > $total_interval) {
|
| 14 |
$fails = variable_get('drupal_http_request_fails', 0);
|
| 15 |
print '$fails = '. ($fails ? 'TRUE' : 'FALSE') ;
|
| 16 |
// check to see if the last test failed
|
| 17 |
if ($fails) {
|
| 18 |
variable_set('drupal_http_request_fails', 0);
|
| 19 |
watchdog('HRFR', 'HTTP Request Fails Reset: variable "drupal_http_request_fails" reset', array(), WATCHDOG_ALERT);
|
| 20 |
}
|
| 21 |
else {
|
| 22 |
watchdog('HRFR', 'HTTP Request Fails Reset: variable "drupal_http_request_fails" checked, no need to reset.');
|
| 23 |
}
|
| 24 |
variable_set('http_request_fail_reset_last_checked', $now);
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Implementation of hook_menu().
|
| 30 |
*/
|
| 31 |
function http_request_fail_reset_menu() {
|
| 32 |
$items = array();
|
| 33 |
$items['admin/settings/http_request_fail_reset'] = array(
|
| 34 |
'title' => 'HTTP Request Fail Reset',
|
| 35 |
'description' => 'Change interval for resetting drupal_http_request_fails',
|
| 36 |
'page callback' => 'drupal_get_form',
|
| 37 |
'page arguments' => array('_http_request_fail_reset_admin_form'),
|
| 38 |
'access arguments' => array('administer site configuration'),
|
| 39 |
);
|
| 40 |
return $items;
|
| 41 |
}
|
| 42 |
|
| 43 |
/**
|
| 44 |
* Module settings form
|
| 45 |
*/
|
| 46 |
function _http_request_fail_reset_admin_form() {
|
| 47 |
$form = array();
|
| 48 |
$form['http_request_fail_reset_interval_multiplier'] = array(
|
| 49 |
'#title' => 'Interval Quantity',
|
| 50 |
'#description' => 'How often do you want the variable "drupal_http_request_fails" reset?',
|
| 51 |
'#type' => 'textfield',
|
| 52 |
'#default_value' => variable_get('http_request_fail_reset_interval_multiplier', 1),
|
| 53 |
);
|
| 54 |
$form['http_request_fail_reset_interval'] = array(
|
| 55 |
'#title' => 'Interval',
|
| 56 |
'#description' => 'What interval?',
|
| 57 |
'#type' => 'select',
|
| 58 |
'#default_value' => variable_get('http_request_fail_reset_interval', 86400),
|
| 59 |
'#options' => array(
|
| 60 |
60 => 'minutes',
|
| 61 |
3600 => 'hours',
|
| 62 |
86400 => 'days',
|
| 63 |
604800 => 'weeks',
|
| 64 |
),
|
| 65 |
);
|
| 66 |
return system_settings_form($form);
|
| 67 |
}
|