Refactor the detection of the case when no database has been selected. re #127
This commit is contained in:
parent
8a3cc9ed5c
commit
a1cb83eea9
11
base.php
11
base.php
|
@ -453,8 +453,7 @@ class Page
|
||||||
global $config;
|
global $config;
|
||||||
$this->title = $config['cops_title_default'];
|
$this->title = $config['cops_title_default'];
|
||||||
$this->subtitle = $config['cops_subtitle_default'];
|
$this->subtitle = $config['cops_subtitle_default'];
|
||||||
$database = GetUrlParam (DB);
|
if (Base::noDatabaseSelected ()) {
|
||||||
if (is_array ($config['calibre_directory']) && is_null ($database)) {
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach (array_keys ($config['calibre_directory']) as $key) {
|
foreach (array_keys ($config['calibre_directory']) as $key) {
|
||||||
$nBooks = Book::getBookCount ($i);
|
$nBooks = Book::getBookCount ($i);
|
||||||
|
@ -484,7 +483,7 @@ class Page
|
||||||
}
|
}
|
||||||
$this->entryArray = array_merge ($this->entryArray, Book::getCount());
|
$this->entryArray = array_merge ($this->entryArray, Book::getCount());
|
||||||
|
|
||||||
if (!is_null ($database)) $this->title = Base::getDbName ();
|
if (Base::isMultipleDatabaseEnabled ()) $this->title = Base::getDbName ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -739,7 +738,7 @@ class PageQueryResult extends Page
|
||||||
$crit = "%" . $this->query . "%";
|
$crit = "%" . $this->query . "%";
|
||||||
|
|
||||||
// Special case when we are doing a search and no database is selected
|
// Special case when we are doing a search and no database is selected
|
||||||
if (is_array ($config['calibre_directory']) && is_null (GetUrlParam (DB))) {
|
if (Base::noDatabaseSelected ()) {
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($config['calibre_directory'] as $key => $value) {
|
foreach ($config['calibre_directory'] as $key => $value) {
|
||||||
Base::clearDb ();
|
Base::clearDb ();
|
||||||
|
@ -893,6 +892,10 @@ abstract class Base
|
||||||
return is_array ($config['calibre_directory']);
|
return is_array ($config['calibre_directory']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function noDatabaseSelected () {
|
||||||
|
return self::isMultipleDatabaseEnabled () && is_null (GetUrlParam (DB));
|
||||||
|
}
|
||||||
|
|
||||||
public static function getDbList () {
|
public static function getDbList () {
|
||||||
global $config;
|
global $config;
|
||||||
if (self::isMultipleDatabaseEnabled ()) {
|
if (self::isMultipleDatabaseEnabled ()) {
|
||||||
|
|
3
book.php
3
book.php
|
@ -631,7 +631,6 @@ function getJson ($complete = false) {
|
||||||
$page = getURLParam ("page", Base::PAGE_INDEX);
|
$page = getURLParam ("page", Base::PAGE_INDEX);
|
||||||
$query = getURLParam ("query");
|
$query = getURLParam ("query");
|
||||||
$search = getURLParam ("search");
|
$search = getURLParam ("search");
|
||||||
$multi = getURLParam ("multi");
|
|
||||||
$qid = getURLParam ("id");
|
$qid = getURLParam ("id");
|
||||||
$n = getURLParam ("n", "1");
|
$n = getURLParam ("n", "1");
|
||||||
$database = GetUrlParam (DB);
|
$database = GetUrlParam (DB);
|
||||||
|
@ -641,7 +640,7 @@ function getJson ($complete = false) {
|
||||||
$pagequery = Base::PAGE_OPENSEARCH_QUERY;
|
$pagequery = Base::PAGE_OPENSEARCH_QUERY;
|
||||||
|
|
||||||
// Special case when no databases were chosen, we search on all databases
|
// Special case when no databases were chosen, we search on all databases
|
||||||
if (is_array ($config['calibre_directory']) && $multi === "1") {
|
if (Base::noDatabaseSelected ()) {
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach (array_keys ($config['calibre_directory']) as $key) {
|
foreach (array_keys ($config['calibre_directory']) as $key) {
|
||||||
Base::clearDb ();
|
Base::clearDb ();
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
// Access the database ASAP to be sure it's readable, redirect if that's not the case.
|
// 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.
|
// It has to be done before any header is sent.
|
||||||
if (is_array ($config['calibre_directory']) && is_null ($database)) {
|
if (Base::noDatabaseSelected ()) {
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach (array_keys ($config['calibre_directory']) as $key) {
|
foreach (array_keys ($config['calibre_directory']) as $key) {
|
||||||
$test = Base::getDb ($i);
|
$test = Base::getDb ($i);
|
||||||
|
|
7
util.js
7
util.js
|
@ -280,13 +280,12 @@ updatePage = function (data) {
|
||||||
limit: 24,
|
limit: 24,
|
||||||
template: templateSuggestion,
|
template: templateSuggestion,
|
||||||
remote: {
|
remote: {
|
||||||
url: 'getJSON.php?search=1&db=%DB&query=%QUERY&multi=%MULTI',
|
url: 'getJSON.php?search=1&db=%DB&query=%QUERY',
|
||||||
replace: function (url, query) {
|
replace: function (url, query) {
|
||||||
var multi = 0;
|
|
||||||
if (currentData.multipleDatabase === 1 && currentData.databaseId === "") {
|
if (currentData.multipleDatabase === 1 && currentData.databaseId === "") {
|
||||||
multi = 1;
|
return url.replace('%QUERY', query).replace('&db=%DB', "")
|
||||||
}
|
}
|
||||||
return url.replace('%QUERY', query).replace('%DB', currentData.databaseId).replace ("%MULTI", multi);
|
return url.replace('%QUERY', query).replace('%DB', currentData.databaseId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue