diff options
Diffstat (limited to 'update.php')
-rwxr-xr-x | update.php | 94 |
1 files changed, 53 insertions, 41 deletions
diff --git a/update.php b/update.php index 079069a3b..2ad4c963c 100755 --- a/update.php +++ b/update.php @@ -30,36 +30,31 @@ $days = (int) $days; if (Config::get(Config::DB_TYPE) == "pgsql") { - $interval_query = "date_updated < NOW() - INTERVAL '$days days'"; + $interval_query = "e.date_updated < NOW() - INTERVAL '$days days'"; } else /*if (Config::get(Config::DB_TYPE) == "mysql") */ { - $interval_query = "date_updated < DATE_SUB(NOW(), INTERVAL $days DAY)"; + $interval_query = "e.date_updated < DATE_SUB(NOW(), INTERVAL $days DAY)"; } $tags_deleted = 0; - - $pdo = Db::pdo(); + $limit_part = 500; while ($limit > 0) { - $limit_part = 500; - - $sth = $pdo->prepare("SELECT ttrss_tags.id AS id - FROM ttrss_tags, ttrss_user_entries, ttrss_entries - WHERE post_int_id = int_id AND $interval_query AND - ref_id = ttrss_entries.id AND tag_cache != '' LIMIT ?"); - $sth->bindValue(1, $limit_part, PDO::PARAM_INT); - $sth->execute(); - - $ids = array(); - - while ($line = $sth->fetch()) { - array_push($ids, $line['id']); - } - - if (count($ids) > 0) { - $ids = join(",", $ids); - - $usth = $pdo->query("DELETE FROM ttrss_tags WHERE id IN ($ids)"); - $tags_deleted = $usth->rowCount(); + $tags = ORM::for_table('ttrss_tags') + ->table_alias('t') + ->select('t.id') + ->join('ttrss_user_entries', ['ue.int_id', '=', 't.post_int_id'], 'ue') + ->join('ttrss_entries', ['e.id', '=', 'ue.ref_id'], 'e') + ->where_not_equal('ue.tag_cache', '') + ->where_raw($interval_query) + ->limit($limit_part) + ->find_many(); + + if (count($tags)) { + ORM::for_table('ttrss_tags') + ->where_id_in(array_column($tags->as_array(), 'id')) + ->delete_many(); + + $tags_deleted += ORM::get_last_statement()->rowCount(); } else { break; } @@ -91,9 +86,10 @@ "gen-search-idx" => "generate basic PostgreSQL fulltext search index", "plugins-list" => "list installed plugins", "debug-feed:" => ["N", "update specified feed with debug output enabled"], - "debug-force-refetch" => "debug update: force refetch feed data", - "debug-force-rehash" => "debug update: force rehash articles", + "force-refetch" => "debug update: force refetch feed data", + "force-rehash" => "debug update: force rehash articles", "opml-export:" => ["USER:FILE", "export OPML of USER to FILE"], + "opml-import:" => ["USER:FILE", "import OPML for USER from FILE"], "user-list" => "list all users", # "user-add:" => ["USER[:PASSWORD]", "add USER, optionally without prompting for PASSWORD"], # "user-remove:" => ["USERNAME", "remove specified user"], @@ -290,29 +286,29 @@ 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"; + $count = ORM::for_table('ttrss_entries') + ->where_null('tsvector_combined') + ->count(); $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]); + print "Articles to process: $count (will limit to $limit).\n"; + + $entries = ORM::for_table('ttrss_entries') + ->select_many('id', 'title', 'content') + ->where_null('tsvector_combined') + ->order_by_asc('id') + ->limit($limit) + ->find_many(); $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']]); - + foreach ($entries as $entry) { + $tsvector_combined = mb_substr(strip_tags($entry->title . " " . $entry->content), 0, 1000000); + $usth->execute([$tsvector_combined, $entry->id]); $processed++; } @@ -366,7 +362,7 @@ if (isset($options["user-list"])) { $users = ORM::for_table('ttrss_users') - ->order_by_expr('id') + ->order_by_asc('id') ->find_many(); foreach ($users as $user) { @@ -389,6 +385,22 @@ } else { Debug::log("User not found: $user"); } + } + + if (isset($options["opml-import"])) { + list ($user, $filename) = explode(":", $options["opml-import"], 2); + + Debug::log("Importing feeds of user $user from OPML file $filename..."); + + if ($owner_uid = UserHelper::find_user_by_login($user)) { + $opml = new OPML(""); + + $rc = $opml->opml_import($owner_uid, $filename); + + Debug::log($rc ? "Success." : "Failed."); + } else { + Debug::log("User not found: $user"); + } } |