X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=update.php;h=9c9c6ae8de742de18d06cd7b5c36638167e7f8f4;hb=9b27cec8c01ff231085bc2045d196ace85e299d9;hp=34357f2f223b370c1762573b7eac0ec097d5478a;hpb=1559e3741c7a823cf0eecee25d751e6553c7af76;p=tt-rss.git diff --git a/update.php b/update.php old mode 100644 new mode 100755 index 34357f2f..9c9c6ae8 --- a/update.php +++ b/update.php @@ -1,157 +1,116 @@ +#!/usr/bin/php Error: your access level is insufficient to run this script.

"; - exit; + + $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"); } - - define('SCHEMA_VERSION', 13); -?> + // Create a database connection. + $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); - - -Database Updater - - - + 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); -

Database Updater

+ // Update feedbrowser + $count = update_feedbrowser_cache($link); + _debug("Feedbrowser updated, $count feeds processed."); -Tiny Tiny RSS database is up to date (version $version).

"; - print "

Return to Tiny Tiny RSS

"; - return; + + if ($op == "-daemon") { + while (true) { + passthru(PHP_EXECUTABLE . " " . $argv[0] . " -daemon-loop"); + _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds..."); + sleep(DAEMON_SLEEP_INTERVAL); + } } - - if (!$op) { - print "

Warning: Please backup your database before proceeding.

"; - - print "

Your Tiny Tiny RSS database needs update to the latest - version ($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 (from version $version)...

"; - - $num_updates = 0; - - foreach (array_keys($update_versions) as $v) { - if ($v == $version + 1) { - print "

Updating to version $v...

"; - $fp = fopen($update_versions[$v], "r"); - if ($fp) { - while (!feof($fp)) { - $query = trim(getline($fp, ";")); - if ($query != "") { - print "

QUERY: $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! ($version)"; - } 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 "

Finished. Performed $num_updates updates up to schema - version $version.

"; - - print "

Return to Tiny Tiny RSS

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