function better_statistics_disable_fields in Better Statistics 7
Disables a list of statistics fields.
Parameters
$fields: An array of statistics fields to be disabled.
Return value
An array of the statistics fields that were disabled.
2 calls to better_statistics_disable_fields()
- drush_better_statistics_stats_dis in ./
better_statistics.drush.inc - Drush command callback for stats-dis.
- _better_statistics_settings_form_submit in ./
better_statistics.admin.inc - Submit handler for Better Statistics configuration settings.
File
- ./
better_statistics.admin.inc, line 353 - Admin and config code for the Better Statistics module.
Code
function better_statistics_disable_fields($fields) {
// Get all declared and active fields.
$declared = _better_statistics_get_custom_fields_by_module();
$active = variable_get('better_statistics_fields', better_statistics_get_default_fields());
$successfully_disabled = array();
// Accept a single field enable.
if (!is_array($fields)) {
$fields = array(
$fields,
);
}
// Load field schema data for all fields being enabled.
$fields_removed = array();
foreach ($fields as $name) {
foreach ($declared as $module => $module_fields) {
if (isset($module_fields[$name])) {
$fields_removed[$name] = $module_fields[$name];
}
}
}
// Loop through each missing field.
foreach ($fields_removed as $field => $data) {
// Verify the field exists.
if (db_field_exists('accesslog', $field)) {
// Drop the field from the database.
db_drop_field('accesslog', $field);
// Remove the field from the active store.
unset($active[$field]);
// Log the field removal in watchdog.
watchdog('better statistics', 'Successfully dropped field %field from accesslog.', array(
'%field' => $field,
), WATCHDOG_NOTICE);
// Add key to the list of fields successfully removed.
$successfully_disabled[] = $field;
}
}
// Save the active store with any changes.
variable_set('better_statistics_fields', $active);
// It can be convenient to call the field update function after configuration.
_better_statistics_update_fields();
_better_statistics_update_methods();
// Clear the Views data cache so fields are registered.
if (module_exists('views')) {
cache_clear_all('views_data:', 'cache_views', TRUE);
}
return $successfully_disabled;
}