summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-03-02 12:08:54 +0300
committerAndrew Dolgov <[email protected]>2021-03-02 12:08:54 +0300
commit20d0cbff7767df31943a8db833b1ab4247bb001b (patch)
treee27ee0778dca265775a4c95eb8d8ecc1674ad60b
parentf9888fc67fc229ee61575af39f99de31f1885896 (diff)
use ORM for article _labels_of/_feeds_of
-rwxr-xr-xclasses/article.php71
-rwxr-xr-xclasses/rpc.php8
2 files changed, 39 insertions, 40 deletions
diff --git a/classes/article.php b/classes/article.php
index 9a9e46f21..648b1e2c1 100755
--- a/classes/article.php
+++ b/classes/article.php
@@ -417,42 +417,39 @@ class Article extends Handler_Protected {
}
function getmetadatabyid() {
- $id = clean($_REQUEST['id']);
-
- $sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries
- WHERE ref_id = ? AND ref_id = id AND owner_uid = ?");
- $sth->execute([$id, $_SESSION['uid']]);
-
- if ($row = $sth->fetch()) {
- $link = $row['link'];
- $title = $row['title'];
+ $article = ORM::for_table('ttrss_entries')
+ ->join('ttrss_user_entries', ['ref_id', '=', 'id'], 'ue')
+ ->where('ue.owner_uid', $_SESSION['uid'])
+ ->find_one((int)$_REQUEST['id']);
- echo json_encode(["link" => $link, "title" => $title]);
+ if ($article) {
+ echo json_encode(["link" => $article->link, "title" => $article->title]);
+ } else {
+ echo json_encode([]);
}
}
static function _get_enclosures($id) {
+ $encs = ORM::for_table('ttrss_enclosures')
+ ->where('post_id', $id)
+ ->find_many();
- $pdo = Db::pdo();
-
- $sth = $pdo->prepare("SELECT * FROM ttrss_enclosures
- WHERE post_id = ? AND content_url != ''");
- $sth->execute([$id]);
-
- $rv = array();
+ $rv = [];
$cache = new DiskCache("images");
- while ($line = $sth->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($encs as $enc) {
+ $cache_key = sha1($enc->content_url);
- if ($cache->exists(sha1($line["content_url"]))) {
- $line["content_url"] = $cache->get_url(sha1($line["content_url"]));
+ if ($cache->exists($cache_key)) {
+ $enc->content_url = $cache->get_url($cache_key);
}
- array_push($rv, $line);
+ array_push($rv, $enc->as_array());
}
return $rv;
+
}
static function _purge_orphans() {
@@ -629,17 +626,16 @@ class Article extends Handler_Protected {
if (count($article_ids) == 0)
return [];
- $id_qmarks = arr_qmarks($article_ids);
-
- $sth = Db::pdo()->prepare("SELECT DISTINCT label_cache FROM ttrss_entries e, ttrss_user_entries ue
- WHERE ue.ref_id = e.id AND id IN ($id_qmarks)");
-
- $sth->execute($article_ids);
+ $entries = ORM::for_table('ttrss_entries')
+ ->table_alias('e')
+ ->join('ttrss_user_entries', ['ref_id', '=', 'id'], 'ue')
+ ->where_in('id', $article_ids)
+ ->find_many();
$rv = [];
- while ($row = $sth->fetch()) {
- $labels = json_decode($row["label_cache"]);
+ foreach ($entries as $entry) {
+ $labels = json_decode($entry->label_cache);
if (isset($labels) && is_array($labels)) {
foreach ($labels as $label) {
@@ -656,19 +652,18 @@ class Article extends Handler_Protected {
if (count($article_ids) == 0)
return [];
- $id_qmarks = arr_qmarks($article_ids);
-
- $sth = Db::pdo()->prepare("SELECT DISTINCT feed_id FROM ttrss_entries e, ttrss_user_entries ue
- WHERE ue.ref_id = e.id AND id IN ($id_qmarks)");
-
- $sth->execute($article_ids);
+ $entries = ORM::for_table('ttrss_entries')
+ ->table_alias('e')
+ ->join('ttrss_user_entries', ['ref_id', '=', 'id'], 'ue')
+ ->where_in('id', $article_ids)
+ ->find_many();
$rv = [];
- while ($row = $sth->fetch()) {
- array_push($rv, $row["feed_id"]);
+ foreach ($entries as $entry) {
+ array_push($rv, $entry->feed_id);
}
- return $rv;
+ return array_unique($rv);
}
}
diff --git a/classes/rpc.php b/classes/rpc.php
index 4c3ecf8eb..c158f0cf6 100755
--- a/classes/rpc.php
+++ b/classes/rpc.php
@@ -152,7 +152,9 @@ class RPC extends Handler_Protected {
if (count($ids) > 0)
$this->markArticlesById($ids, $cmode);
- print json_encode(["message" => "UPDATE_COUNTERS", "feeds" => Article::_feeds_of($ids)]);
+ print json_encode(["message" => "UPDATE_COUNTERS",
+ "labels" => Article::_labels_of($ids),
+ "feeds" => Article::_feeds_of($ids)]);
}
function publishSelected() {
@@ -162,7 +164,9 @@ class RPC extends Handler_Protected {
if (count($ids) > 0)
$this->publishArticlesById($ids, $cmode);
- print json_encode(["message" => "UPDATE_COUNTERS", "feeds" => Article::_feeds_of($ids)]);
+ print json_encode(["message" => "UPDATE_COUNTERS",
+ "labels" => Article::_labels_of($ids),
+ "feeds" => Article::_feeds_of($ids)]);
}
function sanityCheck() {