/** * Event fired on database connection failure. * * @param FailedConnectionEvent $args * * @throws LowLevelDatabaseException */ public function failConnect(FailedConnectionEvent $args) { $e = $args->getException(); $this->logger->debug($e->getMessage(), ['event' => 'exception', 'exception' => $e]); // Trap double exceptions set_exception_handler(function () { }); /* * Using Driver here since Platform may try to connect * to the database, which has failed since we are here. */ $platform = $args->getDriver()->getName(); $platform = Str::replaceFirst('pdo_', '', $platform); throw LowLevelDatabaseException::failedConnect($platform, $e); }
protected function doDatabaseSqliteCheck($config) { if (!$this->sqliteLoaded) { throw LowLevelDatabaseException::missingDriver('SQLite', 'pdo_sqlite'); } // If in-memory connection, skip path checks if (isset($config['memory']) && $config['memory'] === true) { return; } // If the file is present, make sure it is writable $file = $config['path']; if (file_exists($file)) { if (!is_writable($file)) { throw LowLevelDatabaseException::unwritableFile($file); } return; } // If the file isn't present, make sure the directory // exists and is writable so the file can be created $dir = dirname($file); if (!file_exists($dir)) { throw LowLevelDatabaseException::nonexistantFolder($dir); } if (!is_writable($dir)) { throw LowLevelDatabaseException::unwritableFolder($dir); } }
protected function doDatabaseSqliteCheck($config) { if (!$this->sqliteLoaded) { throw LowLevelDatabaseException::missingDriver('SQLite', 'pdo_sqlite'); } // If in-memory connection, skip path checks if (isset($config['memory']) && $config['memory'] === true) { return; } // If the file is present, make sure it is writable $file = $config['path']; if (file_exists($file)) { if (!is_writable($file)) { throw LowLevelDatabaseException::unwritableFile($file); } return; } // If the file isn't present, make sure the directory // exists and is writable so the file can be created $dir = dirname($file); if (!file_exists($dir)) { // At this point, it is possible that the site has been moved and // the configured Sqlite database file path is no longer relevant // to the site's root path $cacheJson = $this->config->getPath('cache/config-cache.json'); if (file_exists($cacheJson)) { unlink($cacheJson); $this->config->app['config']->initialize(); $config = $this->config->app['config']->get('general/database'); if (!file_exists(dirname($config['path']))) { throw LowLevelDatabaseException::nonexistantFolder($dir); } } else { throw LowLevelDatabaseException::nonexistantFolder($dir); } } if (!is_writable($dir)) { throw LowLevelDatabaseException::unwritableFolder($dir); } }