View source
<?php
function variablecheck_perm() {
return array(
'check system variables',
);
}
function variablecheck_menu() {
$items['admin/reports/variablecheck'] = array(
'title' => 'Check System Variables',
'description' => 'Check the validity of settings in the variable table.',
'page callback' => 'variablecheck_check_variables_page',
'access arguments' => array(
'check system variables',
),
);
return $items;
}
function variablecheck_requirements($phase) {
$problem = count(variablecheck_check_variables());
$requirements = array();
$requirements['valiablecheck'] = array(
'title' => 'Variables',
'value' => $problem ? format_plural($problem, 'Found one invalid entry', 'Found @count invalid entries') : t('No problem'),
'description' => $problem ? t('The variable table contains an invalid entry. Please check the <a href="@url">variable report</a> for more information.', array(
'@url' => url('admin/reports/variablecheck'),
)) : '',
'severity' => $problem ? REQUIREMENT_WARNING : REQUIREMENT_OK,
);
return $requirements;
}
function variablecheck_check_variables() {
$rows = null;
$result = db_query("SELECT name, value FROM {variable} ORDER BY name ASC");
while ($entry = db_fetch_object($result)) {
$value = @unserialize($entry->value);
if ($value === FALSE && $entry->value != serialize(FALSE)) {
$row = array(
$entry->name,
$entry->value,
);
$rows[] = $row;
}
}
return $rows;
}
function variablecheck_check_variables_page() {
$header = array(
t('Name'),
t('Value'),
);
$rows = variablecheck_check_variables();
drupal_set_title(t('Invalid Variables'));
if ($count = count($rows)) {
drupal_set_message(format_plural($count, 'Found one invalid entry', 'Found @count invalid entries'), 'error');
$output = format_plural($count, 'You will want to either remove this entry or let the module developer know there is a problem with their module.', 'You will want to either remove these entries or let the module developer know there is a problem with their module.');
$output .= theme('table', $header, $rows);
}
else {
$output = t('No invalid entries were found in the variable table.');
}
return $output;
}