function install_config_import_batch

Same name and namespace in other branches
  1. 9 core/includes/install.core.inc \install_config_import_batch()
  2. 8.9.x core/includes/install.core.inc \install_config_import_batch()
  3. 11.x core/includes/install.core.inc \install_config_import_batch()

Creates a batch for the config importer to process.

See also

install_tasks()

File

core/includes/install.core.inc, line 2326

Code

function install_config_import_batch() {
    // We need to manually trigger the installation of core-provided entity types,
    // as those will not be handled by the module installer.
    // @see install_profile_modules()
    install_core_entity_type_definitions();
    // Get the sync storage.
    $sync = \Drupal::service('config.storage.sync');
    // Match up the site UUIDs, the install_base_system install task will have
    // installed the system module and created a new UUID.
    $system_site = $sync->read('system.site');
    // When installing from configuration it is possible that system.site
    // configuration is not present. If this occurs a ConfigImporterException will
    // by thrown when $config_importer->initialize() is called below and the error
    // will be reported to the user.
    if ($system_site !== FALSE) {
        \Drupal::configFactory()->getEditable('system.site')
            ->set('uuid', $system_site['uuid'])
            ->save();
    }
    // Create the storage comparer and the config importer.
    $storage_comparer = new StorageComparer($sync, \Drupal::service('config.storage'));
    $storage_comparer->createChangelist();
    $config_importer = new ConfigImporter($storage_comparer, \Drupal::service('event_dispatcher'), \Drupal::service('config.manager'), \Drupal::service('lock.persistent'), \Drupal::service('config.typed'), \Drupal::service('module_handler'), \Drupal::service('module_installer'), \Drupal::service('theme_handler'), \Drupal::service('string_translation'), \Drupal::service('extension.list.module'), \Drupal::service('extension.list.theme'));
    try {
        $sync_steps = $config_importer->initialize();
        $batch_builder = new BatchBuilder();
        $batch_builder->setFinishCallback([
            ConfigImporterBatch::class,
            'finish',
        ])
            ->setTitle(t('Importing configuration'))
            ->setInitMessage(t('Starting configuration import.'))
            ->setErrorMessage(t('Configuration import has encountered an error.'));
        foreach ($sync_steps as $sync_step) {
            $batch_builder->addOperation([
                ConfigImporterBatch::class,
                'process',
            ], [
                $config_importer,
                $sync_step,
            ]);
        }
        return $batch_builder->toArray();
    } catch (ConfigImporterException $e) {
        global $install_state;
        // There are validation errors.
        $messenger = \Drupal::messenger();
        $messenger->addError(t('The configuration synchronization failed validation.'));
        foreach ($config_importer->getErrors() as $message) {
            $messenger->addError($message);
        }
        install_display_output([
            '#title' => t('Configuration validation'),
        ], $install_state);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.