diff --git a/backend.php b/backend.php
index 4184e87c8..ef1184068 100644
--- a/backend.php
+++ b/backend.php
@@ -51,7 +51,7 @@
UserHelper::load_user_plugins($_SESSION["uid"]);
}
- if (Config::get_schema_version() !== SCHEMA_VERSION) {
+ if (Db_Updater::is_update_required()) {
print Errors::to_json(Errors::E_SCHEMA_MISMATCH);
return;
}
diff --git a/classes/dbupdater.php b/classes/db/updater.php
similarity index 81%
rename from classes/dbupdater.php
rename to classes/db/updater.php
index d1df31b40..9d27c94d9 100644
--- a/classes/dbupdater.php
+++ b/classes/db/updater.php
@@ -1,22 +1,22 @@
pdo = $pdo;
$this->db_type = $db_type;
- $this->need_version = (int) $need_version;
}
- function get_schema_version() {
+ /** always returns actual (=uncached) value */
+ private static function get_schema_version() {
return Config::get_schema_version(true);
}
- function is_update_required() {
- return $this->get_schema_version() < $this->need_version;
+ static function is_update_required() {
+ return self::get_schema_version() < self::SCHEMA_VERSION;
}
function get_schema_lines($version) {
@@ -62,7 +62,7 @@ class DbUpdater {
}
}
- $db_version = $this->get_schema_version();
+ $db_version = self::get_schema_version();
if ($db_version == $version) {
$this->pdo->commit();
diff --git a/classes/handler/public.php b/classes/handler/public.php
index f7df6fc74..08df7bbc1 100755
--- a/classes/handler/public.php
+++ b/classes/handler/public.php
@@ -660,14 +660,14 @@ class Handler_Public extends Handler {
is_update_required()) {
+ if (Db_Updater::is_update_required()) {
- print "
" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "
";
+ print "" . T_sprintf("Performing updates to version %d", Db_Updater::SCHEMA_VERSION) . "
";
- for ($i = $updater->get_schema_version() + 1; $i <= SCHEMA_VERSION; $i++) {
+ for ($i = Config::get_schema_version(true) + 1; $i <= Db_Updater::SCHEMA_VERSION; $i++) {
print "";
print "- " . T_sprintf("Updating to version %d", $i) . "
";
@@ -704,10 +704,10 @@ class Handler_Public extends Handler {
print "".__("Return to Tiny Tiny RSS")."";
}
} else {
- if ($updater->is_update_required()) {
+ if (Db_Updater::is_update_required()) {
print "".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).",
- $updater->get_schema_version(), SCHEMA_VERSION)."
";
+ Config::get_schema_version(true), Db_Updater::SCHEMA_VERSION)."";
if (Config::get(Config::DB_TYPE) == "mysql") {
print_error("READ THIS: Due to MySQL limitations, your database is not completely protected while updating. ".
diff --git a/classes/opml.php b/classes/opml.php
index c60d411eb..1a223788f 100644
--- a/classes/opml.php
+++ b/classes/opml.php
@@ -151,7 +151,7 @@ class OPML extends Handler_Protected {
# export tt-rss settings
if ($include_settings) {
- $out .= "";
+ $out .= "";
$sth = $this->pdo->prepare("SELECT pref_name, value FROM ttrss_user_prefs2 WHERE
profile IS NULL AND owner_uid = ? ORDER BY pref_name");
@@ -166,7 +166,7 @@ class OPML extends Handler_Protected {
$out .= "";
- $out .= "";
+ $out .= "";
$sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE
owner_uid = ?");
@@ -183,7 +183,7 @@ class OPML extends Handler_Protected {
$out .= "";
- $out .= "";
+ $out .= "";
$sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2
WHERE owner_uid = ? ORDER BY id");
diff --git a/classes/rpc.php b/classes/rpc.php
index ebe29e5cb..90c2c762a 100755
--- a/classes/rpc.php
+++ b/classes/rpc.php
@@ -181,7 +181,7 @@ class RPC extends Handler_Protected {
$client_scheme = parse_url($client_location, PHP_URL_SCHEME);
$server_scheme = parse_url(Config::get_self_url(), PHP_URL_SCHEME);
- if (get_schema_version() != SCHEMA_VERSION) {
+ if (Db_Updater::is_update_required()) {
$error = Errors::E_SCHEMA_MISMATCH;
} else if ($client_scheme != $server_scheme) {
$error = Errors::E_URL_SCHEME_MISMATCH;
diff --git a/classes/rssutils.php b/classes/rssutils.php
index e3d717e73..0d78e0ec7 100755
--- a/classes/rssutils.php
+++ b/classes/rssutils.php
@@ -55,7 +55,7 @@ class RSSUtils {
static function update_daemon_common($limit = null, $options = []) {
if (!$limit) $limit = Config::get(Config::DAEMON_FEED_LIMIT);
- if (get_schema_version() != SCHEMA_VERSION) {
+ if (Config::get_schema_version() != Db_Updater::SCHEMA_VERSION) {
die("Schema version is wrong, please upgrade the database.\n");
}
diff --git a/classes/userhelper.php b/classes/userhelper.php
index 4b795df7d..d929583f7 100644
--- a/classes/userhelper.php
+++ b/classes/userhelper.php
@@ -89,7 +89,7 @@ class UserHelper {
if (!$pluginhost) $pluginhost = PluginHost::getInstance();
- if ($owner_uid && SCHEMA_VERSION >= 100 && empty($_SESSION["safe_mode"])) {
+ if ($owner_uid && Config::get_schema_version() >= 100 && empty($_SESSION["safe_mode"])) {
$plugins = get_pref(Prefs::_ENABLED_PLUGINS, $owner_uid);
$pluginhost->load((string)$plugins, PluginHost::KIND_USER, $owner_uid);
diff --git a/include/functions.php b/include/functions.php
index ce6b48181..4d11ea31f 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,9 +1,10 @@
is_update_required()) {
- Debug::log("Schema update required, version " . $updater->get_schema_version() . " to " . SCHEMA_VERSION);
+ if (Db_Updater::is_update_required()) {
+ Debug::log("Schema update required, version " . Config::get_schema_version(true) . " to " . Db_Updater::SCHEMA_VERSION);
if (Config::get(Config::DB_TYPE) == "mysql")
Debug::Log("READ THIS: Due to MySQL limitations, your database is not completely protected while updating.\n".
@@ -394,9 +394,9 @@
Debug::log("Proceeding to update without confirmation...");
}
- Debug::log("Performing updates to version " . SCHEMA_VERSION . "...");
+ Debug::log("Performing updates to version " . Db_Updater::SCHEMA_VERSION . "...");
- for ($i = $updater->get_schema_version() + 1; $i <= SCHEMA_VERSION; $i++) {
+ for ($i = Config::get_schema_version(true) + 1; $i <= Db_Updater::SCHEMA_VERSION; $i++) {
Debug::log("* Updating to version $i...");
$result = $updater->update_to($i, false);
diff --git a/update_daemon2.php b/update_daemon2.php
index 8168c576e..17bca48ee 100755
--- a/update_daemon2.php
+++ b/update_daemon2.php
@@ -189,7 +189,7 @@
"Maybe another daemon is already running.\n");
}
- if (get_schema_version() != SCHEMA_VERSION) {
+ if (Db_Updater::is_update_required()) {
die("Schema version is wrong, please upgrade the database.\n");
}