From e4107ac9520ca404d4ab49ef79ca74430e8fd772 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 22 Feb 2021 21:47:48 +0300 Subject: wip: initial for config object --- update.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'update.php') diff --git a/update.php b/update.php index ab6272c83..4aff4a774 100755 --- a/update.php +++ b/update.php @@ -14,7 +14,7 @@ require_once "db-prefs.php"; function make_stampfile($filename) { - $fp = fopen(LOCK_DIRECTORY . "/$filename", "w"); + $fp = fopen(Config::get(Config::LOCK_DIRECTORY) . "/$filename", "w"); if (flock($fp, LOCK_EX | LOCK_NB)) { fwrite($fp, time() . "\n"); @@ -30,9 +30,9 @@ $days = (int) $days; - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $interval_query = "date_updated < NOW() - INTERVAL '$days days'"; - } else /*if (DB_TYPE == "mysql") */ { + } else /*if (Config::get(Config::DB_TYPE) == "mysql") */ { $interval_query = "date_updated < DATE_SUB(NOW(), INTERVAL $days DAY)"; } @@ -224,7 +224,7 @@ $log = isset($options['log']) ? '--log '.$options['log'] : ''; $log_level = isset($options['log-level']) ? '--log-level '.$options['log-level'] : ''; - passthru(PHP_EXECUTABLE . " " . $argv[0] ." --daemon-loop $quiet $log $log_level"); + passthru(Config::get(Config::PHP_EXECUTABLE) . " " . $argv[0] ." --daemon-loop $quiet $log $log_level"); // let's enforce a minimum spawn interval as to not forkbomb the host $spawn_interval = max(60, DAEMON_SLEEP_INTERVAL); @@ -277,7 +277,7 @@ Debug::log("clearing existing indexes..."); - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $sth = $pdo->query( "SELECT relname FROM pg_catalog.pg_class WHERE relname LIKE 'ttrss_%' AND relname NOT LIKE '%_pkey' @@ -288,7 +288,7 @@ } while ($line = $sth->fetch()) { - if (DB_TYPE == "pgsql") { + if (Config::get(Config::DB_TYPE) == "pgsql") { $statement = "DROP INDEX " . $line["relname"]; Debug::log($statement); } else { @@ -299,9 +299,9 @@ $pdo->query($statement); } - Debug::log("reading indexes from schema for: " . DB_TYPE); + Debug::log("reading indexes from schema for: " . Config::get(Config::DB_TYPE)); - $fp = fopen("schema/ttrss_schema_" . DB_TYPE . ".sql", "r"); + $fp = fopen("schema/ttrss_schema_" . Config::get(Config::DB_TYPE) . ".sql", "r"); if ($fp) { while ($line = fgets($fp)) { $matches = array(); @@ -375,14 +375,14 @@ } if (isset($options["update-schema"])) { - Debug::log("Checking for updates (" . DB_TYPE . ")..."); + Debug::log("Checking for updates (" . Config::get(Config::DB_TYPE) . ")..."); - $updater = new DbUpdater(Db::pdo(), DB_TYPE, SCHEMA_VERSION); + $updater = new DbUpdater(Db::pdo(), Config::get(Config::DB_TYPE), SCHEMA_VERSION); if ($updater->is_update_required()) { Debug::log("Schema update required, version " . $updater->get_schema_version() . " to " . SCHEMA_VERSION); - if (DB_TYPE == "mysql") + if (Config::get(Config::DB_TYPE) == "mysql") Debug::Log("READ THIS: Due to MySQL limitations, your database is not completely protected while updating.\n". "Errors may put it in an inconsistent state requiring manual rollback.\nBACKUP YOUR DATABASE BEFORE CONTINUING."); else @@ -460,7 +460,7 @@ if (isset($options["list-plugins"])) { $tmppluginhost = new PluginHost(); $tmppluginhost->load_all($tmppluginhost::KIND_ALL); - $enabled = array_map("trim", explode(",", PLUGINS)); + $enabled = array_map("trim", explode(",", Config::get(Config::PLUGINS))); echo "List of all available plugins:\n"; @@ -515,8 +515,8 @@ PluginHost::getInstance()->run_commands($options); - if (file_exists(LOCK_DIRECTORY . "/$lock_filename")) + if (file_exists(Config::get(Config::LOCK_DIRECTORY) . "/$lock_filename")) if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') fclose($lock_handle); - unlink(LOCK_DIRECTORY . "/$lock_filename"); + unlink(Config::get(Config::LOCK_DIRECTORY) . "/$lock_filename"); ?> -- cgit v1.2.3 From 211f699aa0c4211e4ee8a02446d51b9811d0c28c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 22 Feb 2021 22:35:27 +0300 Subject: migrate the rest into Config:: --- update.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'update.php') diff --git a/update.php b/update.php index 4aff4a774..92a087a2e 100755 --- a/update.php +++ b/update.php @@ -212,7 +212,7 @@ } if (isset($options["feeds"])) { - RSSUtils::update_daemon_common(DAEMON_FEED_LIMIT, $options); + RSSUtils::update_daemon_common(Config::get(Config::DAEMON_FEED_LIMIT), $options); RSSUtils::housekeeping_common(); PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, $options); @@ -227,7 +227,7 @@ passthru(Config::get(Config::PHP_EXECUTABLE) . " " . $argv[0] ." --daemon-loop $quiet $log $log_level"); // let's enforce a minimum spawn interval as to not forkbomb the host - $spawn_interval = max(60, DAEMON_SLEEP_INTERVAL); + $spawn_interval = max(60, Config::get(Config::DAEMON_SLEEP_INTERVAL)); Debug::log("Sleeping for $spawn_interval seconds..."); sleep($spawn_interval); @@ -255,7 +255,7 @@ Debug::log("warning: unable to create stampfile\n"); } - RSSUtils::update_daemon_common(isset($options["pidlock"]) ? 50 : DAEMON_FEED_LIMIT, $options); + RSSUtils::update_daemon_common(isset($options["pidlock"]) ? 50 : Config::get(Config::DAEMON_FEED_LIMIT), $options); if (!isset($options["pidlock"]) || $options["task"] == 0) RSSUtils::housekeeping_common(); -- cgit v1.2.3 From 12bcf826e4f2672afbda85264a970fb4735d97f1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 22 Feb 2021 22:39:20 +0300 Subject: don't include config.php everywhere --- update.php | 1 - 1 file changed, 1 deletion(-) (limited to 'update.php') diff --git a/update.php b/update.php index 92a087a2e..af541f517 100755 --- a/update.php +++ b/update.php @@ -9,7 +9,6 @@ require_once "autoload.php"; require_once "functions.php"; - require_once "config.php"; require_once "sanity_check.php"; require_once "db-prefs.php"; -- cgit v1.2.3 From 29ada58b4ac06178c908869e0bb078949e1cb465 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 22 Feb 2021 23:25:14 +0300 Subject: move db-prefs shortcut functions to functions.php --- update.php | 1 - 1 file changed, 1 deletion(-) (limited to 'update.php') diff --git a/update.php b/update.php index af541f517..8d8566db7 100755 --- a/update.php +++ b/update.php @@ -10,7 +10,6 @@ require_once "autoload.php"; require_once "functions.php"; require_once "sanity_check.php"; - require_once "db-prefs.php"; function make_stampfile($filename) { $fp = fopen(Config::get(Config::LOCK_DIRECTORY) . "/$filename", "w"); -- cgit v1.2.3