getStorageComparer example

/** * {@inheritdoc} */
  public function onConfigImporterValidate(ConfigImporterEvent $event) {
    foreach (['update', 'delete'] as $op) {
      $unprocessed_configurations = $event->getConfigImporter()->getUnprocessedConfiguration($op);
      foreach ($unprocessed_configurations as $unprocessed_configuration) {
        if ($workflow = $this->getWorkflow($unprocessed_configuration)) {
          if ($op === 'update') {
            $original_workflow_config = $event->getConfigImporter()
              ->getStorageComparer()
              ->getSourceStorage()
              ->read($unprocessed_configuration);
            $workflow_config = $event->getConfigImporter()
              ->getStorageComparer()
              ->getTargetStorage()
              ->read($unprocessed_configuration);
            $diff = array_diff_key($workflow_config['type_settings']['states']$original_workflow_config['type_settings']['states']);
            foreach (array_keys($diff) as $state_id) {
              $state = $workflow->getTypePlugin()->getState($state_id);
              if ($workflow->getTypePlugin()->workflowStateHasData($workflow$state)) {
                $event->getConfigImporter()->logError($this->t('The moderation state @state_label is being used, but is not in the source storage.', ['@state_label' => $state->label()]));
              }

  protected static function initializeSandbox(array &$context, ConfigImporter $config_importer) {
    $context['sandbox']['field']['purge_batch_size'] = \Drupal::config('field.settings')->get('purge_batch_size');
    // Save the future list of installed extensions to limit the amount of times     // the configuration is read from disk.     $context['sandbox']['field']['extensions'] = $config_importer->getStorageComparer()->getSourceStorage()->read('core.extension');

    $context['sandbox']['field']['steps_to_delete'] = 0;
    $fields = static::getFieldStoragesToPurge($context['sandbox']['field']['extensions']$config_importer->getUnprocessedConfiguration('delete'));
    foreach ($fields as $field) {
      $row_count = \Drupal::entityTypeManager()->getStorage($field->getTargetEntityTypeId())
        ->countFieldData($field);
      if ($row_count > 0) {
        // The number of steps to delete each field is determined by the         // purge_batch_size setting. For example if the field has 9 rows and the         // batch size is 10 then this will add 1 step to $number_of_steps.         $how_many_steps = ceil($row_count / $context['sandbox']['field']['purge_batch_size']);
        
unset($parameters['forms']['install_configure_form']['enable_update_status_module']);
    unset($parameters['forms']['install_configure_form']['enable_update_status_emails']);

    return $parameters;
  }

  /** * Confirms that the installation installed the configuration correctly. */
  public function testConfigSync() {
    // After installation there is no snapshot and nothing to import.     $change_list = $this->configImporter()->getStorageComparer()->getChangelist();
    $expected = [
      'create' => [],
      // The system.mail is changed configuration because the test system       // changes it to ensure that mails are not sent.       'update' => ['system.mail'],
      'delete' => [],
      'rename' => [],
    ];
    $this->assertEquals($expected$change_list);
  }

  
      // will also be synced after the deletee due to alphabetical ordering.       'dependencies' => [
        'config' => [$name_deleter],
      ],
    ];
    $storage->write($name_other$values_other);
    $values_other['label'] = 'Updated other';
    $sync->write($name_other$values_other);

    // Check update changelist order.     $config_importer = $this->configImporter();
    $updates = $config_importer->getStorageComparer()->getChangelist('update');
    $expected = [
      $name_deleter,
      $name_deletee,
      $name_other,
    ];
    $this->assertSame($expected$updates);

    // Import.     $config_importer->import();

    $entity_storage = \Drupal::entityTypeManager()->getStorage('config_test');
    
foreach ($event->getConfigImporter()->getUnprocessedConfiguration($op) as $name) {
        try {
          Config::validateName($name);
        }
        catch (ConfigNameException $e) {
          $message = $this->t('The config name @config_name is invalid.', ['@config_name' => $name]);
          $event->getConfigImporter()->logError($message);
        }
      }
    }
    $config_importer = $event->getConfigImporter();
    if ($config_importer->getStorageComparer()->getSourceStorage()->exists('core.extension')) {
      $this->validateModules($config_importer);
      $this->validateThemes($config_importer);
      $this->validateDependencies($config_importer);
    }
    else {
      $config_importer->logError($this->t('The core.extension configuration does not exist.'));
    }
  }

  /** * Validates module installations and uninstallations. * * @param \Drupal\Core\Config\ConfigImporter $config_importer * The configuration importer. */

  public function getChangelist($op = NULL, $collection = StorageInterface::DEFAULT_COLLECTION) {
    return $this->configImporter->getStorageComparer()->getChangelist($op$collection);
  }

}
file_put_contents($this->publicFilesDirectory . '/translations/drupal-8.0.0.es.po', $this->getPo('es'));
    $locale_settings = Yaml::decode(file_get_contents($this->siteDirectory . '/config/sync/locale.settings.yml'));
    $locale_settings['translation']['use_source'] = 'local';
    $locale_settings['translation']['path'] = $this->publicFilesDirectory . '/translations';
    file_put_contents($this->siteDirectory . '/config/sync/locale.settings.yml', Yaml::encode($locale_settings));
  }

  /** * Confirms that the installation installed the configuration correctly. */
  public function testConfigSync() {
    $comparer = $this->configImporter()->getStorageComparer();
    $expected_changelist_default_collection = [
      'create' => [],
      // The system.mail is changed configuration because the test system       // changes it to ensure that mails are not sent.       'update' => ['system.mail'],
      'delete' => [],
      'rename' => [],
    ];
    $this->assertEquals($expected_changelist_default_collection$comparer->getChangelist());
    $expected_changelist_spanish_collection = [
      'create' => [],
      

  public function onConfigImporterValidate(ConfigImporterEvent $event) {
    // Make sure config syncs performed via the Config UI don't break, but     // don't worry about syncs initiated via the command line.     if (PHP_SAPI === 'cli') {
      return;
    }
    $importer = $event->getConfigImporter();
    $core_extension = $importer->getStorageComparer()->getSourceStorage()->read('core.extension');
    if (!isset($core_extension['module']['config'])) {
      $importer->logError($this->t('Can not uninstall the Configuration module as part of a configuration synchronization through the user interface.'));
    }
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    $events[ConfigEvents::IMPORT_VALIDATE][] = ['onConfigImporterValidate', 20];
    return $events;
  }
/** * Checks that the configuration synchronization is valid. * * This event listener prevents deleting all configuration. If there is * nothing to import then event propagation is stopped because there is no * config import to validate. * * @param \Drupal\Core\Config\ConfigImporterEvent $event * The config import event. */
  public function onConfigImporterValidateNotEmpty(ConfigImporterEvent $event) {
    $importList = $event->getConfigImporter()->getStorageComparer()->getSourceStorage()->listAll();
    if (empty($importList)) {
      $event->getConfigImporter()->logError($this->t('This import is empty and if applied would delete all of your configuration, so has been rejected.'));
      $event->stopPropagation();
    }
  }

  /** * Checks that the configuration synchronization is valid. * * This event listener checks that the system.site:uuid's in the source and * target match. * * @param \Drupal\Core\Config\ConfigImporterEvent $event * The config import event. */
Home | Imprint | This part of the site doesn't use cookies.