X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=update.php;h=8f268cd35ac20cbebe0d9ed45980ce3f0670d630;hb=22366ccc5b4b82f6867ded767b318b1ac9978270;hp=fe2b3c572373189638533af61592b53b16d2e66f;hpb=e6c886bf66928d4bd496672f12b79b547747677b;p=tt-rss.git diff --git a/update.php b/update.php index fe2b3c57..8f268cd3 100755 --- a/update.php +++ b/update.php @@ -17,6 +17,8 @@ if (!defined('PHP_EXECUTABLE')) define('PHP_EXECUTABLE', '/usr/bin/php'); + $pdo = Db::pdo(); + init_plugins(); $longopts = array("feeds", @@ -37,7 +39,6 @@ "debug-feed:", "force-refetch", "force-rehash", - "decrypt-feeds", "help"); foreach (PluginHost::getInstance()->get_commands() as $command => $data) { @@ -58,7 +59,6 @@ Tiny Tiny RSS data update script. - @@ -91,7 +91,6 @@ print " --debug-feed N - perform debug update of feed N\n"; print " --force-refetch - debug update: force refetch feed data\n"; print " --force-rehash - debug update: force rehash articles\n"; - print " --decrypt-feeds - decrypt feed passwords\n"; print " --help - show this help\n"; print "Plugin options:\n"; @@ -159,8 +158,8 @@ if (isset($options["force-update"])) { _debug("marking all feeds as needing update..."); - db_query( "UPDATE ttrss_feeds SET last_update_started = '1970-01-01', - last_updated = '1970-01-01'"); + $pdo->query( "UPDATE ttrss_feeds SET + last_update_started = '1970-01-01', last_updated = '1970-01-01'"); } if (isset($options["feeds"])) { @@ -181,8 +180,12 @@ $log = isset($options['log']) ? '--log '.$options['log'] : ''; passthru(PHP_EXECUTABLE . " " . $argv[0] ." --daemon-loop $quiet $log"); - _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds..."); - sleep(DAEMON_SLEEP_INTERVAL); + + // let's enforce a minimum spawn interval as to not forkbomb the host + $spawn_interval = max(60, DAEMON_SLEEP_INTERVAL); + + _debug("Sleeping for $spawn_interval seconds..."); + sleep($spawn_interval); } } @@ -214,16 +217,16 @@ _debug("clearing existing indexes..."); if (DB_TYPE == "pgsql") { - $result = db_query( "SELECT relname FROM + $sth = $pdo->query( "SELECT relname FROM pg_catalog.pg_class WHERE relname LIKE 'ttrss_%' AND relname NOT LIKE '%_pkey' AND relkind = 'i'"); } else { - $result = db_query( "SELECT index_name,table_name FROM + $sth = $pdo->query( "SELECT index_name,table_name FROM information_schema.statistics WHERE index_name LIKE 'ttrss_%'"); } - while ($line = db_fetch_assoc($result)) { + while ($line = $sth->fetch()) { if (DB_TYPE == "pgsql") { $statement = "DROP INDEX " . $line["relname"]; _debug($statement); @@ -232,7 +235,7 @@ $line['table_name']." DROP INDEX ".$line['index_name']; _debug($statement); } - db_query( $statement, false); + $pdo->query($statement); } _debug("reading indexes from schema for: " . DB_TYPE); @@ -249,7 +252,7 @@ $statement = "CREATE INDEX $index ON $table"; _debug($statement); - db_query( $statement); + $pdo->query($statement); } } fclose($fp); @@ -268,11 +271,11 @@ _debug("converting filters..."); - db_query( "DELETE FROM ttrss_filters2"); + $pdo->query("DELETE FROM ttrss_filters2"); - $result = db_query( "SELECT * FROM ttrss_filters ORDER BY id"); + $res = $pdo->query("SELECT * FROM ttrss_filters ORDER BY id"); - while ($line = db_fetch_assoc($result)) { + while ($line = $res->fetch()) { $owner_uid = $line["owner_uid"]; // date filters are removed @@ -313,7 +316,7 @@ if (isset($options["update-schema"])) { _debug("checking for updates (" . DB_TYPE . ")..."); - $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION); + $updater = new DbUpdater(Db::pdo(), DB_TYPE, SCHEMA_VERSION); if ($updater->isUpdateRequired()) { _debug("schema update required, version " . $updater->getSchemaVersion() . " to " . SCHEMA_VERSION); @@ -342,28 +345,35 @@ if (isset($options["gen-search-idx"])) { echo "Generating search index (stemming set to English)...\n"; - $result = db_query("SELECT COUNT(id) AS count FROM ttrss_entries WHERE tsvector_combined IS NULL"); - $count = db_fetch_result($result, 0, "count"); + $res = $pdo->query("SELECT COUNT(id) AS count FROM ttrss_entries WHERE tsvector_combined IS NULL"); + $row = $res->fetch(); + $count = $row['count']; print "Articles to process: $count.\n"; $limit = 500; $processed = 0; + $sth = $pdo->prepare("SELECT id, title, content FROM ttrss_entries WHERE + tsvector_combined IS NULL ORDER BY id LIMIT ?"); + $sth->execute([$limit]); + + $usth = $pdo->prepare("UPDATE ttrss_entries + SET tsvector_combined = to_tsvector('english', ?) WHERE id = ?"); + while (true) { - $result = db_query("SELECT id, title, content FROM ttrss_entries WHERE tsvector_combined IS NULL ORDER BY id LIMIT $limit"); - while ($line = db_fetch_assoc($result)) { - $tsvector_combined = db_escape_string(mb_substr($line['title'] . ' ' . strip_tags(str_replace('<', ' <', $line['content'])), - 0, 1000000)); + while ($line = $sth->fetch()) { + $tsvector_combined = mb_substr(strip_tags($line["title"] . " " . $line["content"]), 0, 1000000); - db_query("UPDATE ttrss_entries SET tsvector_combined = to_tsvector('english', '$tsvector_combined') WHERE id = " . $line["id"]); + $usth->execute([$tsvector_combined, $line['id']]); + + $processed++; } - $processed += db_num_rows($result); print "Processed $processed articles...\n"; - if (db_num_rows($result) != $limit) { + if ($processed < $limit) { echo "All done.\n"; break; } @@ -405,36 +415,6 @@ exit($rc); } - if (isset($options["decrypt-feeds"])) { - $result = db_query("SELECT id, auth_pass FROM ttrss_feeds WHERE auth_pass_encrypted = true"); - - if (!function_exists("mcrypt_decrypt")) { - _debug("mcrypt functions not available."); - return; - } - - require_once "crypt.php"; - - $total = 0; - - db_query("BEGIN"); - - while ($line = db_fetch_assoc($result)) { - _debug("processing feed id " . $line["id"]); - - $auth_pass = db_escape_string(decrypt_string($line["auth_pass"])); - - db_query("UPDATE ttrss_feeds SET auth_pass_encrypted = false, auth_pass = '$auth_pass' - WHERE id = " . $line["id"]); - - ++$total; - } - - db_query("COMMIT"); - - _debug("$total feeds processed."); - } - PluginHost::getInstance()->run_commands($options); if (file_exists(LOCK_DIRECTORY . "/$lock_filename"))