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

This commit is contained in:
Sébastien Lucas 2013-11-25 17:10:43 +01:00
parent 26f5b36563
commit 4d9b3a4925
3 changed files with 17 additions and 3 deletions

View file

@ -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;

View file

@ -129,6 +129,7 @@ Please check
}
?>
</article>
<?php if (is_readable (Base::getDbFileName ($i))) { ?>
<article class="frontpage">
<h2>Check if Calibre database file can be opened with PHP</h2>
<h4>
@ -182,6 +183,7 @@ Please check
</h4>
</article>
<?php } ?>
<?php } ?>
<?php $i++; } ?>
</section>
<footer></footer>

View file

@ -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");