diff --git a/db-updater.php b/db-updater.php new file mode 100644 index 000000000..76e308856 --- /dev/null +++ b/db-updater.php @@ -0,0 +1,171 @@ + + + +
+".__("Tiny Tiny RSS database is up to date.")."
"; + print ""; + } + + return; + } + + if (!$op) { + print_warning(__("Please backup your database before proceeding.")); + + print "" . T_sprintf("Your Tiny Tiny RSS database needs update to the latest version (%d to %d).", $version, $latest_version) . "
"; + + /* print "Available incremental updates:"; + + foreach (array_keys($update_versions) as $v) { + if ($v > $version) { + print " $v"; + } + } */ + + print "
"; + + print ""; + + } else if ($op == "do") { + + print "".__("Performing updates...")."
"; + + $num_updates = 0; + + foreach (array_keys($update_versions) as $v) { + if ($v == $version + 1) { + print "".T_sprintf("Updating to version %d...", $v)."
"; + $fp = fopen($update_versions[$v], "r"); + if ($fp) { + while (!feof($fp)) { + $query = trim(getline($fp, ";")); + if ($query != "") { + print "$query
"; + db_query($link, $query); + } + } + } + fclose($fp); + + print "".__("Checking version... "); + + $result = db_query($link, "SELECT schema_version FROM ttrss_version"); + $version = db_fetch_result($result, 0, "schema_version"); + + if ($version == $v) { + print __("OK!"); + } else { + print "".__("ERROR!").""; + return; + } + + $num_updates++; + } + } + + print "
".T_sprintf("Finished. Performed %d update(s) up to schema + version %d.", $num_updates, $version)."
"; + + print ""; + + } + +?> + + + + diff --git a/digest.js b/digest.js index 0bb1638a8..50d5e3116 100644 --- a/digest.js +++ b/digest.js @@ -719,7 +719,7 @@ function fatal_error(code, msg) { if (code == 6) { window.location.href = "digest.php"; } else if (code == 5) { - window.location.href = "update.php"; + window.location.href = "db-updater.php"; } else { if (msg == "") msg = "Unknown error"; diff --git a/errors.php b/errors.php index bd7b53fe4..b2e0841a3 100644 --- a/errors.php +++ b/errors.php @@ -12,7 +12,7 @@ $ERRORS[4] = __("Frontend sanity check failed."); - $ERRORS[5] = __("Incorrect database schema version. <a href='update.php'>Please update</a>."); + $ERRORS[5] = __("Incorrect database schema version. <a href='db-updater.php'>Please update</a>."); $ERRORS[6] = __("Request not authorized."); diff --git a/functions.js b/functions.js index 9e990c447..ae7ecee35 100644 --- a/functions.js +++ b/functions.js @@ -1375,7 +1375,7 @@ function fatalError(code, msg, ext_info) { if (code == 6) { window.location.href = "tt-rss.php"; } else if (code == 5) { - window.location.href = "update.php"; + window.location.href = "db-updater.php"; } else { if (msg == "") msg = "Unknown error"; diff --git a/update.php b/update.php old mode 100644 new mode 100755 index 76e308856..50b9fc412 --- a/update.php +++ b/update.php @@ -1,171 +1,98 @@ +#!/usr/bin/php - - - -".__("Tiny Tiny RSS database is up to date.")."
"; - print ""; - } + $op = $argv[1]; + if (!$op || $op == "-help") { + print "Tiny Tiny RSS data update script.\n\n"; + print "Options:\n"; + print " -feeds - update feeds\n"; + print " -feedbrowser - update feedbrowser\n"; + print " -daemon - start single-process update daemon\n"; + print " -help - show this help\n"; return; } - - if (!$op) { - print_warning(__("Please backup your database before proceeding.")); - - print "" . T_sprintf("Your Tiny Tiny RSS database needs update to the latest version (%d to %d).", $version, $latest_version) . "
"; - - /* print "Available incremental updates:"; - - foreach (array_keys($update_versions) as $v) { - if ($v > $version) { - print " $v"; - } - } */ - - print "
"; - - print ""; - - } else if ($op == "do") { - - print "".__("Performing updates...")."
"; - - $num_updates = 0; - - foreach (array_keys($update_versions) as $v) { - if ($v == $version + 1) { - print "".T_sprintf("Updating to version %d...", $v)."
"; - $fp = fopen($update_versions[$v], "r"); - if ($fp) { - while (!feof($fp)) { - $query = trim(getline($fp, ";")); - if ($query != "") { - print "$query
"; - db_query($link, $query); - } - } - } - fclose($fp); - - print "".__("Checking version... "); - - $result = db_query($link, "SELECT schema_version FROM ttrss_version"); - $version = db_fetch_result($result, 0, "schema_version"); - - if ($version == $v) { - print __("OK!"); - } else { - print "".__("ERROR!").""; - return; - } - - $num_updates++; - } + + if ($op != "-daemon") { + $lock_filename = "update.lock"; + } else { + $lock_filename = "update_daemon.lock"; + } + + $lock_handle = make_lockfile($lock_filename); + $must_exit = false; + + // Try to lock a file in order to avoid concurrent update. + if (!$lock_handle) { + die("error: Can't create lockfile ($lock_filename). ". + "Maybe another update process is already running.\n"); + } + + // Create a database connection. + $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); + + if (!$link) { + if (DB_TYPE == "mysql") { + print mysql_error(); + } + // PG seems to display its own errors just fine by default. + return; + } + + init_connection($link); + + if ($op == "-feeds") { + // Update all feeds needing a update. + update_daemon_common($link); + } + + if ($op == "-feedbrowser") { + $count = update_feedbrowser_cache($link); + print "Finished, $count feeds processed.\n"; + } + + if ($op == "-daemon") { + if (!ENABLE_UPDATE_DAEMON) + die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n"); + + while (true) { + passthru(PHP_EXECUTABLE . " " . $argv[0] . " -daemon-loop"); + _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds..."); + sleep(DAEMON_SLEEP_INTERVAL); + } + } + + if ($op == "-daemon-loop") { + if (!make_stampfile('update_daemon.stamp')) { + die("error: unable to create stampfile\n"); + } + + // Call to the feed batch update function + // or regenerate feedbrowser cache + + if (rand(0,100) > 30) { + update_daemon_common($link); + } else { + $count = update_feedbrowser_cache($link); + _debug("Finished, $count feeds processed."); } - - print "
".T_sprintf("Finished. Performed %d update(s) up to schema - version %d.", $num_updates, $version)."
"; - - print ""; } - + + db_close($link); + + unlink(LOCK_DIRECTORY . "/$lock_filename"); ?> - - - - diff --git a/update_daemon.php b/update_daemon.php deleted file mode 100755 index 03d366b5e..000000000 --- a/update_daemon.php +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/php - diff --git a/update_daemon_loop.php b/update_daemon_loop.php deleted file mode 100755 index 7fa22d19d..000000000 --- a/update_daemon_loop.php +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/php - 50) { - update_daemon_common($link); - } else { - $count = update_feedbrowser_cache($link); - _debug("Finished, $count feeds processed."); - } - - db_close($link); - -?> diff --git a/update_feedbrowser.php b/update_feedbrowser.php deleted file mode 100755 index 0031ff315..000000000 --- a/update_feedbrowser.php +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/php - diff --git a/update_feeds.php b/update_feeds.php deleted file mode 100755 index 6a4aa2a1b..000000000 --- a/update_feeds.php +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/php - diff --git a/update-translations.sh b/utils/update-translations.sh similarity index 100% rename from update-translations.sh rename to utils/update-translations.sh