createChangelist example

$sync = $this->container->get('config.storage.sync');
    $snapshot = $this->container->get('config.storage.snapshot');
    $config_name = 'config_test.system';
    $config_key = 'foo';
    $new_data = 'foobar';

    $active_snapshot_comparer = new StorageComparer($active$snapshot);
    $sync_snapshot_comparer = new StorageComparer($sync$snapshot);

    // Verify that we have an initial snapshot that matches the active     // configuration. This has to be true as no config should be installed.     $this->assertFalse($active_snapshot_comparer->createChangelist()->hasChanges());

    // Install the default config.     $this->installConfig(['config_test']);
    // Although we have imported config this has not affected the snapshot.     $this->assertTrue($active_snapshot_comparer->reset()->hasChanges());

    // Update the config snapshot.     \Drupal::service('config.manager')->createSnapshot($active$snapshot);

    // The snapshot and active config should now contain the same config     // objects.
$config_name = $form_state->getValue('config_name');
      $config = $this->config($config_name);
      $this->configExists = !$config->isNew() ? $config : FALSE;
    }

    // Use ConfigImporter validation.     if (!$form_state->getErrors()) {
      $source_storage = new StorageReplaceDataWrapper($this->configStorage);
      $source_storage->replaceData($config_name$data);
      $storage_comparer = new StorageComparer($source_storage$this->configStorage);

      $storage_comparer->createChangelist();
      if (!$storage_comparer->hasChanges()) {
        $form_state->setErrorByName('import', $this->t('There are no changes to import.'));
      }
      else {
        $config_importer = new ConfigImporter(
          $storage_comparer,
          $this->eventDispatcher,
          $this->configManager,
          $this->lock,
          $this->typedConfigManager,
          $this->moduleHandler,
          


    $this->installConfig(['system']);
    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $this->configImporter = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock'),
      $this->container->get('config.typed'),
      $this->container->get('module_handler'),
      $this->container->get('module_installer'),
      $this->container->get('theme_handler'),
      $this->container->get('string_translation'),
      $this->container->get('extension.list.module'),
      $this->container->get('extension.list.theme')
    );
  }
$this->installConfig(['system']);
    $this->installEntitySchema('entity_test_mul');
    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $this->configImporter = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock'),
      $this->container->get('config.typed'),
      $this->container->get('module_handler'),
      $this->container->get('module_installer'),
      $this->container->get('theme_handler'),
      $this->container->get('string_translation'),
      $this->container->get('extension.list.module'),
      $this->container->get('extension.list.theme')
    );
  }


  /** * {@inheritdoc} */
  public function reset() {
    $this->changelist = [StorageInterface::DEFAULT_COLLECTION => $this->getEmptyChangelist()];
    $this->sourceNames = $this->targetNames = [];
    // Reset the static configuration data caches.     $this->sourceCacheStorage->deleteAll();
    $this->targetCacheStorage->deleteAll();
    return $this->createChangelist();
  }

  /** * {@inheritdoc} */
  public function hasChanges() {
    foreach ($this->getAllCollectionNames() as $collection) {
      foreach (['delete', 'create', 'update', 'rename'] as $op) {
        if (!empty($this->changelist[$collection][$op])) {
          return TRUE;
        }
      }
$contact_form = ContactForm::create(['id' => 'test', 'label' => 'Test contact form']);
    $contact_form->save();

    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $config_importer = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock'),
      $this->container->get('config.typed'),
      $this->container->get('module_handler'),
      $this->container->get('module_installer'),
      $this->container->get('theme_handler'),
      $this->container->get('string_translation'),
      $this->container->get('extension.list.module'),
      $this->container->get('extension.list.theme')
    );

    

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['actions'] = ['#type' => 'actions'];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Import all'),
    ];
    $syncStorage = $this->importTransformer->transform($this->syncStorage);
    $source_list = $syncStorage->listAll();
    $storage_comparer = new StorageComparer($syncStorage$this->activeStorage);
    $storage_comparer->createChangelist();
    if (empty($source_list) || !$storage_comparer->hasChanges()) {
      $form['no_changes'] = [
        '#type' => 'table',
        '#header' => [$this->t('Name')$this->t('Operations')],
        '#rows' => [],
        '#empty' => empty($source_list) ? $this->t('There is no staged configuration.') : $this->t('The staged configuration is identical to the active configuration.'),
      ];
      $form['actions']['#access'] = FALSE;
      return $form;
    }
    elseif (!$storage_comparer->validateSiteUuid()) {
      
    // so it has to be cleared out manually.     unset($GLOBALS['hook_config_test']);

    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $this->configImporter = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock'),
      $this->container->get('config.typed'),
      $this->container->get('module_handler'),
      $this->container->get('module_installer'),
      $this->container->get('theme_handler'),
      $this->container->get('string_translation'),
      $this->container->get('extension.list.module'),
      $this->container->get('extension.list.theme')
    );
  }
$this->installEntitySchema('user');
    $this->installEntitySchema('node');
    $this->installConfig(['system', 'field']);

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $this->configImporter = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock.persistent'),
      $this->container->get('config.typed'),
      $this->container->get('module_handler'),
      $this->container->get('module_installer'),
      $this->container->get('theme_handler'),
      $this->container->get('string_translation'),
      $this->container->get('extension.list.module'),
      $this->container->get('extension.list.theme')
    );
  }
->willReturn($config_data);
    $this->targetStorage->expects($this->once())
      ->method('readMultiple')
      ->willReturn($config_data);
    $this->sourceStorage->expects($this->once())
      ->method('getAllCollectionNames')
      ->willReturn([]);
    $this->targetStorage->expects($this->once())
      ->method('getAllCollectionNames')
      ->willReturn([]);

    $this->storageComparer->createChangelist();
    $this->assertEmpty($this->storageComparer->getChangelist('create'));
    $this->assertEmpty($this->storageComparer->getChangelist('delete'));
    $this->assertEmpty($this->storageComparer->getChangelist('update'));
  }

  /** * @covers ::createChangelist */
  public function testCreateChangelistCreate() {
    $target_data = $source_data = $this->getConfigData();
    unset($target_data['field.storage.node.body']);
    
    $this->assertModules(array_keys($modules_to_uninstall), TRUE);
    foreach ($modules_to_uninstall as $module => $info) {
      $this->assertModuleConfig($module);
      $this->assertModuleTablesExist($module);
    }

    // Ensure that we have no configuration changes to import.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $this->assertSame($storage_comparer->getEmptyChangelist()$storage_comparer->createChangelist()->getChangelist());

    // Now we have all configuration imported, test all of them for schema     // conformance. Ensures all imported default configuration is valid when     // all modules are enabled.     $names = $this->container->get('config.storage')->listAll();
    /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config */
    $typed_config = $this->container->get('config.typed');
    foreach ($names as $name) {
      $config = $this->config($name);
      $this->assertConfigSchema($typed_config$name$config->get());
    }
  }
parent::setUp();

    $this->installConfig(['system']);
    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $this->configImporter = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock'),
      $this->container->get('config.typed'),
      $this->container->get('module_handler'),
      $this->container->get('module_installer'),
      $this->container->get('theme_handler'),
      $this->container->get('string_translation'),
      $this->container->get('extension.list.module'),
      $this->container->get('extension.list.theme')
    );
  }
$this->installEntitySchema('node');
    $this->installConfig(['system', 'field', 'node']);

    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $this->configImporter = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock'),
      $this->container->get('config.typed'),
      $this->container->get('module_handler'),
      $this->container->get('module_installer'),
      $this->container->get('theme_handler'),
      $this->container->get('string_translation'),
      $this->container->get('extension.list.module'),
      $this->container->get('extension.list.theme')
    );
  }
Home | Imprint | This part of the site doesn't use cookies.