You are here

function drush_better_statistics_stats_en in Better Statistics 7

Drush command callback for stats-en.

File

./better_statistics.drush.inc, line 121
Drush integration of Better Statistics.

Code

function drush_better_statistics_stats_en($fields) {
  module_load_include('inc', 'better_statistics', 'better_statistics.admin');
  $fields = func_get_args();
  $active = variable_get('better_statistics_fields', better_statistics_get_default_fields());
  $available = _better_statistics_get_custom_fields_by_module();
  foreach ($fields as $index => $field) {
    if (!_better_statistics_field_exists($field)) {
      unset($fields[$index]);
      drush_print(dt("The @field field doesn't exist. Use drush stats-ls to view a full list of available fields.", array(
        '@field' => $field,
      )));
    }
    elseif (isset($active[$field])) {
      unset($fields[$index]);
      drush_print(dt('The @field field is already enabled.', array(
        '@field' => $field,
      )));
    }
  }
  if (empty($fields)) {
    return drush_log(dt('There were no fields that could be enabled.'), 'ok');
  }
  else {

    // Inform the user which fields will be enabled.
    drush_print(dt('The following statistics fields will be enabled: !fields', array(
      '!fields' => implode(', ', $fields),
    )));
    if (!drush_confirm(dt('Do you really want to continue?'))) {
      return drush_user_abort();
    }

    // Enable the fields here.
    $enabled = better_statistics_enable_fields($fields);

    // Print confirmation of field enablement.
    drush_print(dt("The following fields were successfully enabled: @fields", array(
      '@fields' => implode(', ', $enabled),
    )));
  }
}