diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 0b1f633..1d8a746 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -10,6 +10,7 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Unicode; +use Drupal\Core\Database\Database; use Drupal\Core\DrupalKernel; use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\Core\Logger\RfcLogLevel; @@ -758,6 +759,22 @@ function drupal_installation_attempted() { } /** + * Check whether Drupal is installed. + * + * @return bool + * TRUE if Drupal is installed, FALSE otherwise. + */ +function drupal_is_installed() { + // Check that a default database connection has been defined. + if (!Database::getConnectionInfo()) { + return FALSE; + } + + // Check whether the sessions table exists. + return Database::getConnection()->schema()->tableExists('sessions'); +} + +/** * Gets the name of the currently active installation profile. * * When this function is called during Drupal's initial installation process, diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 890f7be..86130ba 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1096,14 +1096,8 @@ function install_verify_database_settings($site_path) { * Verify that the database is ready (no existing Drupal installation). */ function install_verify_database_ready() { - $system_schema = system_schema(); - end($system_schema); - $table = key($system_schema); - - if ($database = Database::getConnectionInfo()) { - if (Database::getConnection()->schema()->tableExists($table)) { - throw new AlreadyInstalledException(\Drupal::service('string_translation')); - } + if (drupal_is_installed()) { + throw new AlreadyInstalledException(\Drupal::service('string_translation')); } } diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 2ddc3ee..7cfe0fb 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -13,7 +13,6 @@ use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Config\BootstrapConfigStorageFactory; use Drupal\Core\Config\NullStorage; -use Drupal\Core\Database\Database; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceModifierInterface; use Drupal\Core\DependencyInjection\ServiceProviderInterface; @@ -629,9 +628,9 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = $this->initializeSettings($request); // Redirect the user to the installation script if Drupal has not been - // installed yet (i.e., if no $databases array has been defined in the - // settings.php file) and we are not already installing. - if (!Database::getConnectionInfo() && !drupal_installation_attempted() && PHP_SAPI !== 'cli') { + // installed yet, and we are not already installing, and we are not on the + // command line. + if (!drupal_installation_attempted() && PHP_SAPI !== 'cli' && !drupal_is_installed()) { $response = new RedirectResponse($request->getBasePath() . '/core/install.php'); } else {