X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=update.php;h=216a9c1f47758aa7030541a8cb46db5642e2a861;hb=9044e2e062e6e4cfc750613588557606704cd649;hp=894ccb3272da31007003ae2e589f6ee3b3538f7c;hpb=57bac1bea99cdac24305c53272a48821e52a7c2e;p=tt-rss.git diff --git a/update.php b/update.php index 894ccb32..216a9c1f 100755 --- a/update.php +++ b/update.php @@ -33,21 +33,29 @@ "update-schema", "convert-filters", "force-update", + "gen-search-idx", "list-plugins", "help"); - foreach ($pluginhost->get_commands() as $command => $data) { + foreach (PluginHost::getInstance()->get_commands() as $command => $data) { array_push($longopts, $command . $data["suffix"]); } $options = getopt("", $longopts); + if (!is_array($options)) { + die("error: getopt() failed. ". + "Most probably you are using PHP CGI to run this script ". + "instead of required PHP CLI. Check tt-rss wiki page on updating feeds for ". + "additional information.\n"); + } + if (count($options) == 0 && !defined('STDIN')) { ?> Tiny Tiny RSS data update script. - + @@ -73,13 +81,14 @@ print " --log FILE - log messages to FILE\n"; print " --indexes - recreate missing schema indexes\n"; print " --update-schema - update database schema\n"; + print " --gen-search-idx - generate basic PostgreSQL fulltext search index\n"; print " --convert-filters - convert type1 filters to type2\n"; print " --force-update - force update of all feeds\n"; print " --list-plugins - list all available plugins\n"; print " --help - show this help\n"; print "Plugin options:\n"; - foreach ($pluginhost->get_commands() as $command => $data) { + foreach (PluginHost::getInstance()->get_commands() as $command => $data) { $args = $data['arghelp']; printf(" --%-19s - %s\n", "$command $args", $data["description"]); } @@ -128,7 +137,7 @@ $lock_handle = make_lockfile($lock_filename); $must_exit = false; - if (isset($options["task"])) { + if (isset($options["task"]) && isset($options["pidlock"])) { $waits = $options["task"] * 5; _debug("Waiting before update ($waits)"); sleep($waits); @@ -148,21 +157,10 @@ } if (isset($options["feeds"])) { - // Update all feeds needing a update. update_daemon_common(); + housekeeping_common(true); - // Update feedbrowser - $count = update_feedbrowser_cache(); - _debug("Feedbrowser updated, $count feeds processed."); - - // Purge orphans and cleanup tags - purge_orphans( true); - - $rc = cleanup_tags( 14, 50000); - _debug("Cleaned $rc cached tags."); - - global $pluginhost; - $pluginhost->run_hooks($pluginhost::HOOK_UPDATE_TASK, "hook_update_task", $op); + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op); } if (isset($options["feedbrowser"])) { @@ -173,8 +171,9 @@ if (isset($options["daemon"])) { while (true) { $quiet = (isset($options["quiet"])) ? "--quiet" : ""; + $log = isset($options['log']) ? '--log '.$options['log'] : ''; - passthru(PHP_EXECUTABLE . " " . $argv[0] ." --daemon-loop $quiet"); + passthru(PHP_EXECUTABLE . " " . $argv[0] ." --daemon-loop $quiet $log"); _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds..."); sleep(DAEMON_SLEEP_INTERVAL); } @@ -185,25 +184,12 @@ _debug("warning: unable to create stampfile\n"); } - // Call to the feed batch update function - // or regenerate feedbrowser cache + update_daemon_common(isset($options["pidlock"]) ? 50 : DAEMON_FEED_LIMIT); - if (rand(0,100) > 30) { - update_daemon_common(); - } else { - $count = update_feedbrowser_cache(); - _debug("Feedbrowser updated, $count feeds processed."); - - purge_orphans( true); - - $rc = cleanup_tags( 14, 50000); - - _debug("Cleaned $rc cached tags."); - - global $pluginhost; - $pluginhost->run_hooks($pluginhost::HOOK_UPDATE_TASK, "hook_update_task", $op); - } + if (!isset($options["pidlock"]) || $options["task"] == 0) + housekeeping_common(true); + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op); } if (isset($options["cleanup-tags"])) { @@ -310,7 +296,7 @@ $_REQUEST = $filter; $_SESSION["uid"] = $owner_uid; - $filters = new Pref_Filters( $_REQUEST); + $filters = new Pref_Filters($_REQUEST); $filters->add(); } } @@ -320,7 +306,7 @@ if (isset($options["update-schema"])) { _debug("checking for updates (" . DB_TYPE . ")..."); - $updater = new DbUpdater( DB_TYPE, SCHEMA_VERSION); + $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION); if ($updater->isUpdateRequired()) { _debug("schema update required, version " . $updater->getSchemaVersion() . " to " . SCHEMA_VERSION); @@ -346,6 +332,37 @@ } + 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"); + + print "Articles to process: $count.\n"; + + $limit = 500; + $processed = 0; + + 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($line['content']), + 0, 1000000)); + + db_query("UPDATE ttrss_entries SET tsvector_combined = to_tsvector('english', '$tsvector_combined') WHERE id = " . $line["id"]); + } + + $processed += db_num_rows($result); + print "Processed $processed articles...\n"; + + if (db_num_rows($result) != $limit) { + echo "All done.\n"; + break; + } + } + } + if (isset($options["list-plugins"])) { $tmppluginhost = new PluginHost(); $tmppluginhost->load_all($tmppluginhost::KIND_ALL); @@ -368,11 +385,7 @@ } - $pluginhost->run_commands($options); - - if ($lock_handle != false) { - fclose($lock_handle); - } + PluginHost::getInstance()->run_commands($options); if (file_exists(LOCK_DIRECTORY . "/$lock_filename")) unlink(LOCK_DIRECTORY . "/$lock_filename");