From 4d9b3a4925de2e66a47ccd8f5d3d0d9032e3065a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Mon, 25 Nov 2013 17:10:43 +0100 Subject: [PATCH] Fix the redirect in case the database is not found. I also handle better the case were no file are actually found. Thanks to At Libitum. fix #116 --- base.php | 14 +++++++++++--- checkconfig.php | 2 ++ index.php | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/base.php b/base.php index 46b7a77..350ca34 100644 --- a/base.php +++ b/base.php @@ -889,15 +889,23 @@ abstract class Base public static function getDbFileName ($database = NULL) { return self::getDbDirectory ($database) .'metadata.db'; } + + private static function error () { + header("location: checkconfig.php?err=1"); + exit(); + } public static function getDb ($database = NULL) { global $config; if (is_null (self::$db)) { try { - self::$db = new PDO('sqlite:'. self::getDbFileName ($database)); + if (file_exists (self::getDbFileName ($database))) { + self::$db = new PDO('sqlite:'. self::getDbFileName ($database)); + } else { + self::error (); + } } catch (Exception $e) { - header("location: checkconfig.php?err=1"); - exit(); + self::error (); } } return self::$db; diff --git a/checkconfig.php b/checkconfig.php index 57f97a7..aac84bc 100644 --- a/checkconfig.php +++ b/checkconfig.php @@ -129,6 +129,7 @@ Please check } ?> +

Check if Calibre database file can be opened with PHP

@@ -182,6 +183,7 @@ Please check

+ diff --git a/index.php b/index.php index f9070d0..4dcea57 100644 --- a/index.php +++ b/index.php @@ -23,6 +23,10 @@ exit (); } + // Access the database ASAP to be sure it's readable, redirect if that's not the case. + // It has to be done before any header is sent. + $test = Base::getDb (); + header ("Content-Type:text/html;charset=utf-8"); $page = getURLParam ("page", Base::PAGE_INDEX); $query = getURLParam ("query");