move dbupdater to db/updater; move base SCHEMA_VERSION constant inside db/updater class
This commit is contained in:
parent
86b12fc06c
commit
d6629ed188
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
|
@ -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. ".
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
define('SCHEMA_VERSION', 142);
|
||||
|
||||
define('LABEL_BASE_INDEX', -1024);
|
||||
define('PLUGIN_FEED_BASE_INDEX', -128);
|
||||
|
||||
/** constant is @deprecated, use Db_Updater::SCHEMA_VERSION instead */
|
||||
define('SCHEMA_VERSION', Db_Updater::SCHEMA_VERSION);
|
||||
|
||||
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
|
||||
libxml_disable_entity_loader(true);
|
||||
}
|
||||
|
|
12
update.php
12
update.php
|
@ -146,7 +146,7 @@
|
|||
}
|
||||
|
||||
if (!isset($options['update-schema'])) {
|
||||
if (get_schema_version() != SCHEMA_VERSION) {
|
||||
if (Db_Updater::is_update_required()) {
|
||||
die("Schema version is wrong, please upgrade the database (--update-schema).\n");
|
||||
}
|
||||
}
|
||||
|
@ -374,10 +374,10 @@
|
|||
if (isset($options["update-schema"])) {
|
||||
Debug::log("Checking for updates (" . Config::get(Config::DB_TYPE) . ")...");
|
||||
|
||||
$updater = new DbUpdater(Db::pdo(), Config::get(Config::DB_TYPE), SCHEMA_VERSION);
|
||||
$updater = new Db_Updater(Db::pdo(), Config::get(Config::DB_TYPE));
|
||||
|
||||
if ($updater->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);
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue