+ if (isset($options["update-schema"])) {
+ _debug("checking for updates (" . DB_TYPE . ")...");
+
+ $updater = new DbUpdater(Db::pdo(), DB_TYPE, SCHEMA_VERSION);
+
+ if ($updater->isUpdateRequired()) {
+ _debug("schema update required, version " . $updater->getSchemaVersion() . " to " . SCHEMA_VERSION);
+ _debug("WARNING: please backup your database before continuing.");
+ _debug("Type 'yes' to continue.");
+
+ if (read_stdin() != 'yes')
+ exit;
+
+ for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
+ _debug("performing update up to version $i...");
+
+ $result = $updater->performUpdateTo($i, false);
+
+ _debug($result ? "OK!" : "FAILED!");
+
+ if (!$result) return;
+
+ }
+ } else {
+ _debug("update not required.");
+ }
+
+ }
+
+ if (isset($options["gen-search-idx"])) {
+ echo "Generating search index (stemming set to English)...\n";
+
+ $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) {
+
+ while ($line = $sth->fetch()) {
+ $tsvector_combined = mb_substr(strip_tags($line["title"] . " " . $line["content"]), 0, 1000000);
+
+ $usth->execute([$tsvector_combined, $line['id']]);
+
+ $processed++;
+ }
+
+ print "Processed $processed articles...\n";
+
+ if ($processed < $limit) {
+ echo "All done.\n";
+ break;
+ }
+ }
+ }
+