Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $directory = $input->getArgument('directory');
     $source_storage = new FileStorage($directory);
     if ($input->getOption('reverse')) {
         $config_comparer = new StorageComparer($source_storage, $this->configStorage, $this->configManager);
     } else {
         $config_comparer = new StorageComparer($this->configStorage, $source_storage, $this->configManager);
     }
     if (!$config_comparer->createChangelist()->hasChanges()) {
         $output->writeln($this->trans('commands.config.diff.messages.no-changes'));
     }
     $change_list = [];
     foreach ($config_comparer->getAllCollectionNames() as $collection) {
         $change_list[$collection] = $config_comparer->getChangelist(null, $collection);
     }
     $this->outputDiffTable($io, $change_list);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $snapshot_comparer = new StorageComparer($this->activeStorage, $this->snapshotStorage, $this->configManager);
     if (!$form_state->getUserInput() && $snapshot_comparer->createChangelist()->hasChanges()) {
         $change_list = array();
         foreach ($snapshot_comparer->getAllCollectionNames() as $collection) {
             foreach ($snapshot_comparer->getChangelist(NULL, $collection) as $config_names) {
                 if (empty($config_names)) {
                     continue;
                 }
                 foreach ($config_names as $config_name) {
                     $change_list[] = $config_name;
                 }
             }
         }
         sort($change_list);
         $change_list_render = array('#theme' => 'item_list', '#items' => $change_list);
         $change_list_html = drupal_render($change_list_render);
         drupal_set_message($this->t('Your current configuration has changed. Changes to these configuration items will be lost on the next synchronization: !changes', array('!changes' => $change_list_html)), 'warning');
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Import all'));
     $source_list = $this->stagingStorage->listAll();
     $storage_comparer = new StorageComparer($this->stagingStorage, $this->activeStorage, $this->configManager);
     if (empty($source_list) || !$storage_comparer->createChangelist()->hasChanges()) {
         $form['no_changes'] = array('#type' => 'table', '#header' => array('Name', 'Operations'), '#rows' => array(), '#empty' => $this->t('There are no configuration changes to import.'));
         $form['actions']['#access'] = FALSE;
         return $form;
     } elseif (!$storage_comparer->validateSiteUuid()) {
         drupal_set_message($this->t('The staged configuration cannot be imported, because it originates from a different site than this site. You can only synchronize configuration between cloned instances of this site.'), 'error');
         $form['actions']['#access'] = FALSE;
         return $form;
     } else {
         // Store the comparer for use in the submit.
         $form_state->set('storage_comparer', $storage_comparer);
     }
     // Add the AJAX library to the form for dialog support.
     $form['#attached']['library'][] = 'core/drupal.ajax';
     foreach ($storage_comparer->getAllCollectionNames() as $collection) {
         if ($collection != StorageInterface::DEFAULT_COLLECTION) {
             $form[$collection]['collection_heading'] = array('#type' => 'html_tag', '#tag' => 'h2', '#value' => $this->t('!collection configuration collection', array('!collection' => $collection)));
         }
         foreach ($storage_comparer->getChangelist(NULL, $collection) as $config_change_type => $config_names) {
             if (empty($config_names)) {
                 continue;
             }
             // @todo A table caption would be more appropriate, but does not have the
             //   visual importance of a heading.
             $form[$collection][$config_change_type]['heading'] = array('#type' => 'html_tag', '#tag' => 'h3');
             switch ($config_change_type) {
                 case 'create':
                     $form[$collection][$config_change_type]['heading']['#value'] = format_plural(count($config_names), '@count new', '@count new');
                     break;
                 case 'update':
                     $form[$collection][$config_change_type]['heading']['#value'] = format_plural(count($config_names), '@count changed', '@count changed');
                     break;
                 case 'delete':
                     $form[$collection][$config_change_type]['heading']['#value'] = format_plural(count($config_names), '@count removed', '@count removed');
                     break;
                 case 'rename':
                     $form[$collection][$config_change_type]['heading']['#value'] = format_plural(count($config_names), '@count renamed', '@count renamed');
                     break;
             }
             $form[$collection][$config_change_type]['list'] = array('#type' => 'table', '#header' => array('Name', 'Operations'));
             foreach ($config_names as $config_name) {
                 if ($config_change_type == 'rename') {
                     $names = $storage_comparer->extractRenameNames($config_name);
                     $route_options = array('source_name' => $names['old_name'], 'target_name' => $names['new_name']);
                     $config_name = $this->t('!source_name to !target_name', array('!source_name' => $names['old_name'], '!target_name' => $names['new_name']));
                 } else {
                     $route_options = array('source_name' => $config_name);
                 }
                 if ($collection != StorageInterface::DEFAULT_COLLECTION) {
                     $route_name = 'config.diff_collection';
                     $route_options['collection'] = $collection;
                 } else {
                     $route_name = 'config.diff';
                 }
                 $links['view_diff'] = array('title' => $this->t('View differences'), 'url' => Url::fromRoute($route_name, $route_options), 'attributes' => array('class' => array('use-ajax'), 'data-accepts' => 'application/vnd.drupal-modal', 'data-dialog-options' => json_encode(array('width' => 700))));
                 $form[$collection][$config_change_type]['list']['#rows'][] = array('name' => $config_name, 'operations' => array('data' => array('#type' => 'operations', '#links' => $links)));
             }
         }
     }
     return $form;
 }