diff options
author | Andrew Dolgov <[email protected]> | 2021-03-02 15:03:01 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-03-02 15:03:01 +0300 |
commit | d6629ed18863f797d34ebdc65815d7af21cb8332 (patch) | |
tree | a72a114c576f2aa15710d18a8090a9bced9c56ba /classes | |
parent | 86b12fc06c33fe742ac4035a031716674bdb6462 (diff) |
move dbupdater to db/updater; move base SCHEMA_VERSION constant inside db/updater class
Diffstat (limited to 'classes')
-rw-r--r-- | classes/db/updater.php (renamed from classes/dbupdater.php) | 16 | ||||
-rwxr-xr-x | classes/handler/public.php | 12 | ||||
-rw-r--r-- | classes/opml.php | 6 | ||||
-rwxr-xr-x | classes/rpc.php | 2 | ||||
-rwxr-xr-x | classes/rssutils.php | 2 | ||||
-rw-r--r-- | classes/userhelper.php | 2 |
6 files changed, 20 insertions, 20 deletions
diff --git a/classes/dbupdater.php b/classes/db/updater.php index d1df31b40..9d27c94d9 100644 --- a/classes/dbupdater.php +++ b/classes/db/updater.php @@ -1,22 +1,22 @@ <?php -class DbUpdater { +class Db_Updater { + const SCHEMA_VERSION = 142; private $pdo; private $db_type; - private $need_version; - function __construct($pdo, $db_type, $need_version) { + function __construct($pdo, $db_type) { $this->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 { <?php @$op = clean($_REQUEST["subop"] ?? ""); - $updater = new DbUpdater(Db::pdo(), Config::get(Config::DB_TYPE), SCHEMA_VERSION); + $updater = new Db_Updater(Db::pdo(), Config::get(Config::DB_TYPE)); if ($op == "performupdate") { - if ($updater->is_update_required()) { + if (Db_Updater::is_update_required()) { - print "<h2>" . T_sprintf("Performing updates to version %d", SCHEMA_VERSION) . "</h2>"; + print "<h2>" . T_sprintf("Performing updates to version %d", Db_Updater::SCHEMA_VERSION) . "</h2>"; - 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 "<ul>"; print "<li class='text-info'>" . T_sprintf("Updating to version %d", $i) . "</li>"; @@ -704,10 +704,10 @@ class Handler_Public extends Handler { print "<a href='index.php'>".__("Return to Tiny Tiny RSS")."</a>"; } } else { - if ($updater->is_update_required()) { + if (Db_Updater::is_update_required()) { print "<h2>".T_sprintf("Tiny Tiny RSS database needs update to the latest version (%d to %d).", - $updater->get_schema_version(), SCHEMA_VERSION)."</h2>"; + Config::get_schema_version(true), Db_Updater::SCHEMA_VERSION)."</h2>"; if (Config::get(Config::DB_TYPE) == "mysql") { print_error("<strong>READ THIS:</strong> 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 .= "<outline text=\"tt-rss-prefs\" schema-version=\"".SCHEMA_VERSION."\">"; + $out .= "<outline text=\"tt-rss-prefs\" schema-version=\"".Db_Updater::SCHEMA_VERSION."\">"; $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 .= "</outline>"; - $out .= "<outline text=\"tt-rss-labels\" schema-version=\"".SCHEMA_VERSION."\">"; + $out .= "<outline text=\"tt-rss-labels\" schema-version=\"".Db_Updater::SCHEMA_VERSION."\">"; $sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE owner_uid = ?"); @@ -183,7 +183,7 @@ class OPML extends Handler_Protected { $out .= "</outline>"; - $out .= "<outline text=\"tt-rss-filters\" schema-version=\"".SCHEMA_VERSION."\">"; + $out .= "<outline text=\"tt-rss-filters\" schema-version=\"".Db_Updater::SCHEMA_VERSION."\">"; $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); |