X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=update.php;h=ac785373d34858dbf4a11086cc73460bb8ab8922;hb=dbaa4e4aac5e68c6d4714941ae99d3e4028410e5;hp=27cd871f980ae21f648aa0f6f016bfa8f1d356b4;hpb=441acab8ff3a62e11d70ed920f0b12ad08b20e09;p=tt-rss.git diff --git a/update.php b/update.php old mode 100644 new mode 100755 index 27cd871f..ac785373 --- a/update.php +++ b/update.php @@ -1,166 +1,105 @@ +#!/usr/bin/php ". - __("Error: your access level is insufficient to run this script.")."

"; - exit; + + if ($op != "-daemon") { + $lock_filename = "update.lock"; + } else { + $lock_filename = "update_daemon.lock"; } - - define('SCHEMA_VERSION', 14); -?> + $lock_handle = make_lockfile($lock_filename); + $must_exit = false; - - -Database Updater - - - + // 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); + } -".__("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++; - } + 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("Feedbrowser updated, $count feeds processed."); + + purge_orphans($link, true); + + $rc = cleanup_tags($link, 14, 50000); + + _debug("Cleaned $rc cached tags."); } - - print "

".T_sprintf("Finished. Performed %d update(s) up to schema - version %d.", $num_updates, $version)."

"; - - print "
- -
"; } - -?> - - + if ($op == "-cleanup-tags") { + $rc = cleanup_tags($link, 14, 50000); + print "$rc tags deleted.\n"; + } + + db_close($link); + unlink(LOCK_DIRECTORY . "/$lock_filename"); +?>