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

@ -636,10 +636,19 @@ abstract class Base
private static $db = NULL; private static $db = NULL;
public static function getDbDirectory () { public static function getDbList () {
global $config; global $config;
if (is_array ($config['calibre_directory'])) { 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']); $array = array_values ($config['calibre_directory']);
return $array[$database]; return $array[$database];
} }
@ -647,8 +656,8 @@ abstract class Base
} }
public static function getDbFileName () { public static function getDbFileName ($database = NULL) {
return self::getDbDirectory () .'metadata.db'; return self::getDbDirectory ($database) .'metadata.db';
} }
public static function getDb () { public static function getDb () {

View file

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