Checkconfig can now handle multi database. re #40

This commit is contained in:
Sébastien Lucas 2013-04-04 20:53:44 +02:00
parent 3a9561d5c0
commit ff95d618db
2 changed files with 29 additions and 16 deletions

View File

@ -635,11 +635,20 @@ abstract class Base
const COMPATIBILITY_XML_ALDIKO = "aldiko";
private static $db = NULL;
public static function getDbDirectory () {
public static function getDbList () {
global $config;
if (is_array ($config['calibre_directory'])) {
$database = GetUrlParam (DB, 0);
return $config['calibre_directory'];
} else {
return array ("" => $config['calibre_directory']);
}
}
public static function getDbDirectory ($database = NULL) {
global $config;
if (is_array ($config['calibre_directory'])) {
if (is_null ($database)) $database = GetUrlParam (DB, 0);
$array = array_values ($config['calibre_directory']);
return $array[$database];
}
@ -647,8 +656,8 @@ abstract class Base
}
public static function getDbFileName () {
return self::getDbDirectory () .'metadata.db';
public static function getDbFileName ($database = NULL) {
return self::getDbDirectory ($database) .'metadata.db';
}
public static function getDb () {

View File

@ -74,15 +74,18 @@
?>
</div>
</div>
<?php
$i = 0;
foreach (Base::getDbList () as $name => $database) {
?>
<div class="entry">
<div class="entryTitle">Check if Calibre database file exists and is readable</div>
<div class="entryContent">
<?php
if (is_readable (Base::getDbFileName ())) {
echo "OK";
if (is_readable (Base::getDbFileName ($i))) {
echo "{$name} OK";
} else {
echo "File " . Base::getDbFileName () . " not found,
echo "{$name} File " . Base::getDbFileName ($i) . " not found,
Please check
<ul>
<li>Value of \$config['calibre_directory'] in config_local.php</li>
@ -99,10 +102,10 @@ Please check
<div class="entryContent">
<?php
try {
$db = new PDO('sqlite:'. Base::getDbFileName ());
echo "OK";
$db = new PDO('sqlite:'. Base::getDbFileName ($i));
echo "{$name} OK";
} catch (Exception $e) {
echo "If the file is readable, check your php configuration. Exception detail : " . $e;
echo "{$name} If the file is readable, check your php configuration. Exception detail : " . $e;
}
?>
</div>
@ -112,19 +115,20 @@ Please check
<div class="entryContent">
<?php
try {
$db = new PDO('sqlite:'. Base::getDbFileName ());
$db = new PDO('sqlite:'. Base::getDbFileName ($i));
$count = $db->query("select count(*) FROM sqlite_master WHERE type='table' AND name in ('books', 'authors', 'tags', 'series')")->fetchColumn();
if ($count == 4) {
echo "OK";
echo "{$name} OK";
} else {
echo "Not all Calibre tables were found. Are you you're using the correct database.";
echo "{$name} Not all Calibre tables were found. Are you you're using the correct database.";
}
} catch (Exception $e) {
echo "If the file is readable, check your php configuration. Exception detail : " . $e;
echo "{$name} If the file is readable, check your php configuration. Exception detail : " . $e;
}
?>
</div>
</div>
<?php $i++; } ?>
</div>
</div>
</body>