Verified Commit 6c4592b1 authored by godotislate's avatar godotislate
Browse files

task: #3614153 Install system module alongside other modules in the installer

By: catch
By: nicxvan
By: mstrelan
By: godotislate
By: amateescu
parent f80f6c21
Loading
Loading
Loading
Loading
Loading
+16 −22
Original line number Diff line number Diff line
@@ -348,7 +348,6 @@ function install_begin_request($class_loader, &$install_state): void {

  // Ensure that procedural dependencies are loaded as early as possible,
  // since the error/exception handlers depend on them.
  require_once __DIR__ . '/../modules/system/system.install';
  require_once __DIR__ . '/common.inc';
  require_once __DIR__ . '/install.inc';
  require_once __DIR__ . '/form.inc';
@@ -1120,7 +1119,6 @@ function install_verify_requirements(&$install_state) {
 *   An array of information about the current installation state.
 */
function install_base_system(&$install_state): void {
  // Install system.module.
  drupal_install_system($install_state);

  // Call HtaccessWriter::ensure() to ensure that all of Drupal's standard
@@ -1610,8 +1608,7 @@ function install_profile_modules(&$install_state) {
      $modules = array_merge($modules, array_keys($files[$module]->requires));
    }
  }
  // The System module has already been installed by install_base_system().
  $modules = array_diff(array_unique($modules), ['system']);

  foreach ($modules as $module) {
    if (!empty($files[$module]->info['required'])) {
      $required[$module] = $files[$module]->sort;
@@ -1652,7 +1649,7 @@ function install_profile_modules(&$install_state) {
    }
    $batch_builder->addOperation(
      '_install_module_batch',
      [$module_group, $names],
      [$module_group, $names, $install_state],
    );
  }
  $batch_builder
@@ -1868,10 +1865,21 @@ function install_finished(&$install_state): void {
 *
 * Performs batch installation of modules.
 */
function _install_module_batch(array $modules, array $module_names, array &$context): void {
function _install_module_batch(array $modules, array $module_names, array $install_state, array &$context): void {
  \Drupal::service('module_installer')->install($modules, FALSE);
  $context['results'] = array_merge($context['results'], $modules);
  $context['message'] = \Drupal::translation()->formatPlural(count($module_names), 'Installed %module module.', 'Installed %module modules.', ['%module' => implode(', ', $module_names)]);

  // If installing system module, set the langcode to the one chosen in the
  // installer.
  if (in_array('system', $modules)) {
    if (isset($install_state['parameters']['langcode'])) {
      \Drupal::configFactory()->getEditable('system.site')
        ->set('langcode', (string) $install_state['parameters']['langcode'])
        ->set('default_langcode', (string) $install_state['parameters']['langcode'])
        ->save();
    }
  }
}

/**
@@ -2329,17 +2337,6 @@ function install_config_import_batch() {

  // 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();
@@ -2525,7 +2522,7 @@ function _install_config_locale_overrides_process_batch(array $names, array $lan
 * @internal
 *   All installer code is internal.
 */
function install_recipe_required_modules() {
function install_recipe_required_modules(array $install_state) {
  // 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()
@@ -2550,9 +2547,6 @@ function install_recipe_required_modules() {
  }
  arsort($required);

  // The system module is already installed. See install_base_system().
  unset($required['system']);

  $modules = [];
  $names = [];
  foreach ($required as $module => $weight) {
@@ -2560,7 +2554,7 @@ function install_recipe_required_modules() {
    $names[] = $files[$module]->info['name'];
  }
  $batch_builder->addOperation('_install_module_batch',
    [$modules, $names]
    [$modules, $names, $install_state]
  );
  return $batch_builder->toArray();
}
+1 −12
Original line number Diff line number Diff line
@@ -179,7 +179,7 @@ function drupal_verify_profile($install_state): array {
}

/**
 * Installs the system module.
 * Install the base system and any required database drivers.
 *
 * Separated from the installation of other modules so core system
 * functions can be made available while other modules are installed.
@@ -240,17 +240,6 @@ function drupal_install_system($install_state): void {
      $kernel->getContainer()->get('module_installer')->install([$provider], TRUE);
    }
  }

  // Install System module.
  $kernel->getContainer()->get('module_installer')->install(['system'], FALSE);

  // Ensure default language is saved.
  if (isset($install_state['parameters']['langcode'])) {
    \Drupal::configFactory()->getEditable('system.site')
      ->set('langcode', (string) $install_state['parameters']['langcode'])
      ->set('default_langcode', (string) $install_state['parameters']['langcode'])
      ->save();
  }
}

/**
+8 −3
Original line number Diff line number Diff line
@@ -431,11 +431,16 @@ public function hasChanges() {
   * {@inheritdoc}
   */
  public function validateSiteUuid() {
    $source = $this->sourceStorage->read('system.site');
    $target = $this->targetStorage->read('system.site');
    // It is possible that the storage does not contain system.site
    // If there is no target configuration yet, then the entire site may be
    // getting reinstalled from config.
    if (!$target) {
      return TRUE;
    }
    $source = $this->sourceStorage->read('system.site');
    // It is possible that the source storage does not contain system.site
    // configuration. In such cases the site UUID cannot be valid.
    return $source && $target && $source['uuid'] === $target['uuid'];
    return $source && $source['uuid'] === $target['uuid'];
  }

  /**
+12 −0
Original line number Diff line number Diff line
@@ -1528,6 +1528,18 @@ protected function compileContainer() {
        $default_language_values = ['id' => $system['langcode']];
      }
    }
    else {
      // If the system.site config doesn't exist, then we're in the installer,
      // if langcode is set in install state parameters, then set that as the
      // default language. This allows the default language to be correct on the
      // container just before system module is installed.
      // @todo move default language configuration to core from system module so
      // that it can be set prior to system module install without workarounds.
      // @see https://www.drupal.org/project/drupal/issues/3615365
      if (isset($GLOBALS['install_state']['parameters']['langcode'])) {
        $default_language_values['id'] = $GLOBALS['install_state']['parameters']['langcode'];
      }
    }
    $container->setParameter('language.default_values', $default_language_values);

    // Register synthetic services.
+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ class BasicAuthTest extends BrowserTestBase {
    'router_test',
    'locale',
    'basic_auth_test',
    'page_cache',
    'dynamic_page_cache',
  ];

  /**
Loading