diff options
| author | Greg Roach <fisharebest@gmail.com> | 2017-11-11 21:51:31 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2017-11-11 21:51:31 +0000 |
| commit | 35e2e946f342051d77c0da0b3dc48a896b1ed34a (patch) | |
| tree | f168f074be74328782a0299ac2ab27b681cd34aa /includes/session.php | |
| parent | d83ab2d7059ca6b5039167717eccf478ee229185 (diff) | |
| download | webtrees-35e2e946f342051d77c0da0b3dc48a896b1ed34a.tar.gz webtrees-35e2e946f342051d77c0da0b3dc48a896b1ed34a.tar.bz2 webtrees-35e2e946f342051d77c0da0b3dc48a896b1ed34a.zip | |
Use views/template for DB connection errors
Diffstat (limited to 'includes/session.php')
| -rw-r--r-- | includes/session.php | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/includes/session.php b/includes/session.php index 5145d4b8bd..aa863776a1 100644 --- a/includes/session.php +++ b/includes/session.php @@ -16,12 +16,14 @@ namespace Fisharebest\Webtrees; use DateTime; +use ErrorException; use Fisharebest\Webtrees\Theme\AdministrationTheme; use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; use PDOException; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Throwable; /** @@ -136,7 +138,7 @@ define('WT_SCRIPT_NAME', basename(Filter::server('SCRIPT_NAME'))); // Convert PHP errors into exceptions set_error_handler(function ($errno, $errstr, $errfile, $errline) { - throw new \ErrorException($errfile . ':' . $errline . ' ' . $errstr, $errno); + throw new ErrorException($errfile . ':' . $errline . ' ' . $errstr, $errno); }); set_exception_handler(function (Throwable $ex) { @@ -187,12 +189,6 @@ set_exception_handler(function (Throwable $ex) { // Load our configuration file, so we can connect to the database if (file_exists(WT_ROOT . 'data/config.ini.php')) { - $dbconfig = parse_ini_file(WT_ROOT . 'data/config.ini.php'); - // Invalid/unreadable config file? - if (!is_array($dbconfig)) { - header('Location: site-unavailable.php'); - exit; - } // Down for maintenance? if (file_exists(WT_ROOT . 'data/offline.txt')) { header('Location: site-offline.php'); @@ -208,20 +204,38 @@ if (file_exists(WT_ROOT . 'data/config.ini.php')) { // Connect to the database try { + // Read the connection settings + $dbconfig = parse_ini_file(WT_ROOT . 'data/config.ini.php'); Database::createInstance($dbconfig['dbhost'], $dbconfig['dbport'], $dbconfig['dbname'], $dbconfig['dbuser'], $dbconfig['dbpass']); define('WT_TBLPREFIX', $dbconfig['tblpfx']); unset($dbconfig); + // Some of the FAMILY JOIN HUSBAND JOIN WIFE queries can excede the MAX_JOIN_SIZE setting Database::exec("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci', SQL_BIG_SELECTS=1"); - // Update the database schema - $updated = Database::updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', WT_SCHEMA_VERSION); - if ($updated) { - // updateSchema() might load custom modules - which we cannot load again. - header('Location: ' . $request->getRequestUri()); - exit; - } + + // Update the database schema, if necessary. + Database::updateSchema('\Fisharebest\Webtrees\Schema', 'WT_SCHEMA_VERSION', WT_SCHEMA_VERSION); } catch (PDOException $ex) { - header('Location: ' . Html::url('site-unavailable.php', ['message' => $ex->getMessage()])); + define('WT_DATA_DIR', 'data/'); + I18N::init(); + if ($ex->getCode() === 1045) { + // Error during connection? + $content = View::make('errors/database-connection', ['error' => $ex->getMessage()]); + } else { + // Error in a migration script? + $content = View::make('errors/database-error', ['error' => $ex->getMessage()]); + } + $html = View::make('layouts/error', ['content' => $content]); + $response = new Response($html, 503); + $response->prepare($request)->send(); + exit; +} catch (ErrorException $ex) { + define('WT_DATA_DIR', 'data/'); + I18N::init(); + $content = View::make('errors/database-connection', ['error' => $ex->getMessage()]); + $html = View::make('layouts/error', ['content' => $content]); + $response = new Response($html, 503); + $response->prepare($request)->send(); exit; } |
