diff --git a/core/lib/Drupal/Core/Installer/CheckInstalledTrait.php b/core/lib/Drupal/Core/Installer/CheckInstalledTrait.php index e7638a8..8bbef6a 100644 --- a/core/lib/Drupal/Core/Installer/CheckInstalledTrait.php +++ b/core/lib/Drupal/Core/Installer/CheckInstalledTrait.php @@ -52,40 +52,28 @@ protected function shouldRedirectToInstaller(\Exception $exception, Connection $ return TRUE; } + // A database error with code 1049 means "missing database", and it should + // be safe to redirect in that case. + if (($exception instanceof \PDOException || $exception instanceof DatabaseException) && $exception->getCode() == 1049) { + return TRUE; + } + // Redirect if the database is empty. if ($connection) { - return $this->databaseEmpty($connection); + try { + return !$connection->schema()->tableExists('sessions'); + } + catch (\Exception $e) { + // If we still have an exception at this point, we need to be careful + // since we should not redirect if the exception represents an error on an + // already-installed site (for example, if the database server went down). + // Assume we shouldn't redirect, just in case. + return FALSE; + } } // Default to FALSE to minimize the chance of overwriting an installed // database. return FALSE; } - - /** - * Checks if the database is empty. - * - * @param \Drupal\Core\Database\Connection|null $connection $connection - * The drupal database connection to check. - * - * @return bool - * Returns TRUE if there is an empty database for the given connection. - */ - public function databaseEmpty(Connection $connection) { - // Check for the presence of a database table provided in the hook_schema() - // implementation of a required core module. That should always be present - // if Drupal is already installed. - try { - return !$connection->schema()->tableExists('sessions'); - } - catch (\Exception $e) { - // If we still have an exception at this point, we need to be careful - // since we should not redirect if the exception represents an error on an - // already-installed site (for example, if the database server went down). - // However a database error with code 1049 means "missing database", and - // it should be safe to redirect in that case. - return ($e instanceof \PDOException || $e instanceof DatabaseException) && $e->getCode() == 1049; - } - } - }