You are here

function configuration_diff in Configuration Management 7

Page callback to display the differences between what's in code and what is in the db.

Parameters

$configuration: A loaded configuration object to display differences for.

$component: Optional: specific component to display differences for. If excluded, all components are used.

Return value

Themed display of what is different.

1 string reference to 'configuration_diff'
configuration_menu in ./configuration.module
Implements hook_menu().

File

./configuration.admin.inc, line 879

Code

function configuration_diff($component, $identifier) {
  drupal_add_css(drupal_get_path('module', 'configuration') . '/configuration.css');
  module_load_include('inc', 'configuration', 'configuration.export');
  $overrides = configuration_detect_overrides($component, $identifier);
  $config_in_sync = FALSE;
  $output = '';
  if (!empty($overrides)) {
    module_load_include('inc', 'diff', 'diff.engine');
    $formatter = new DrupalDiffFormatter();

    //- temporarily broken

    //$formatter = new DiffFormatter();
    $formatter->leading_context_lines = 2;
    $formatter->trailing_context_lines = 2;

    //$formatter->show_header = $show_header
    $rows = array();
    foreach ($overrides as $component => $items) {
      foreach ($items as $identifier => $item) {
        $rows[] = array(
          array(
            array(
              'data' => $component,
              'colspan' => 4,
              'header' => TRUE,
            ),
          ),
        );
        $diff = new Diff(explode("\n", configuration_var_export($item['datastore'])), explode("\n", configuration_var_export($item['activestore'])));
        $rows = array_merge($rows, $formatter
          ->format($diff));
        $d = $formatter
          ->format($diff);
        if (empty($d)) {

          // The initial method of checking differences is by comparing arrays.
          // For some reason, even if the arrays are different, running the
          // arrays through the Diff constructor above may not find difference.
          // This is creating FALSE positives and marking configs as not in
          // sync. If the diff system doesn't see a difference, set the status
          // to CONFIGURATION_IN_SYNC.
          drupal_set_message(t('Configuration is in sync.'));
          configuration_set_status($component, $identifier, CONFIGURATION_IN_SYNC);
          cache_clear_all('config_export', 'cache');
          $config_in_sync = TRUE;
        }
      }
    }
    if ($config_in_sync) {
      $output = "<div class='configuration-empty'>" . t('No changes have been made to this configuration.') . "</div>";
    }
    else {
      $header = array(
        array(
          'data' => t('Datastore'),
          'colspan' => 2,
        ),
        array(
          'data' => t('Activestore'),
          'colspan' => 2,
        ),
      );
      $output .= theme('table', array(
        'header' => $header,
        'rows' => $rows,
        'attributes' => array(
          'class' => array(
            'diff',
            'configuration-diff',
          ),
        ),
      ));
    }
  }
  else {
    $output = "<div class='configuration-empty'>" . t('No changes have been made to this configuration.') . "</div>";
  }
  $output = array(
    'page' => array(
      '#markup' => "<div class='configuration-comparison'>{$output}</div>",
    ),
  );
  return $output;
}