use ORM for article _labels_of/_feeds_of

master
Andrew Dolgov 3 years ago
parent f9888fc67f
commit 20d0cbff77

@ -417,42 +417,39 @@ class Article extends Handler_Protected {
} }
function getmetadatabyid() { function getmetadatabyid() {
$id = clean($_REQUEST['id']); $article = ORM::for_table('ttrss_entries')
->join('ttrss_user_entries', ['ref_id', '=', 'id'], 'ue')
$sth = $this->pdo->prepare("SELECT link, title FROM ttrss_entries, ttrss_user_entries ->where('ue.owner_uid', $_SESSION['uid'])
WHERE ref_id = ? AND ref_id = id AND owner_uid = ?"); ->find_one((int)$_REQUEST['id']);
$sth->execute([$id, $_SESSION['uid']]);
if ($row = $sth->fetch()) {
$link = $row['link'];
$title = $row['title'];
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) { static function _get_enclosures($id) {
$encs = ORM::for_table('ttrss_enclosures')
->where('post_id', $id)
->find_many();
$pdo = Db::pdo(); $rv = [];
$sth = $pdo->prepare("SELECT * FROM ttrss_enclosures
WHERE post_id = ? AND content_url != ''");
$sth->execute([$id]);
$rv = array();
$cache = new DiskCache("images"); $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"]))) { if ($cache->exists($cache_key)) {
$line["content_url"] = $cache->get_url(sha1($line["content_url"])); $enc->content_url = $cache->get_url($cache_key);
} }
array_push($rv, $line); array_push($rv, $enc->as_array());
} }
return $rv; return $rv;
} }
static function _purge_orphans() { static function _purge_orphans() {
@ -629,17 +626,16 @@ class Article extends Handler_Protected {
if (count($article_ids) == 0) if (count($article_ids) == 0)
return []; return [];
$id_qmarks = arr_qmarks($article_ids); $entries = ORM::for_table('ttrss_entries')
->table_alias('e')
$sth = Db::pdo()->prepare("SELECT DISTINCT label_cache FROM ttrss_entries e, ttrss_user_entries ue ->join('ttrss_user_entries', ['ref_id', '=', 'id'], 'ue')
WHERE ue.ref_id = e.id AND id IN ($id_qmarks)"); ->where_in('id', $article_ids)
->find_many();
$sth->execute($article_ids);
$rv = []; $rv = [];
while ($row = $sth->fetch()) { foreach ($entries as $entry) {
$labels = json_decode($row["label_cache"]); $labels = json_decode($entry->label_cache);
if (isset($labels) && is_array($labels)) { if (isset($labels) && is_array($labels)) {
foreach ($labels as $label) { foreach ($labels as $label) {
@ -656,19 +652,18 @@ class Article extends Handler_Protected {
if (count($article_ids) == 0) if (count($article_ids) == 0)
return []; return [];
$id_qmarks = arr_qmarks($article_ids); $entries = ORM::for_table('ttrss_entries')
->table_alias('e')
$sth = Db::pdo()->prepare("SELECT DISTINCT feed_id FROM ttrss_entries e, ttrss_user_entries ue ->join('ttrss_user_entries', ['ref_id', '=', 'id'], 'ue')
WHERE ue.ref_id = e.id AND id IN ($id_qmarks)"); ->where_in('id', $article_ids)
->find_many();
$sth->execute($article_ids);
$rv = []; $rv = [];
while ($row = $sth->fetch()) { foreach ($entries as $entry) {
array_push($rv, $row["feed_id"]); array_push($rv, $entry->feed_id);
} }
return $rv; return array_unique($rv);
} }
} }

@ -152,7 +152,9 @@ class RPC extends Handler_Protected {
if (count($ids) > 0) if (count($ids) > 0)
$this->markArticlesById($ids, $cmode); $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() { function publishSelected() {
@ -162,7 +164,9 @@ class RPC extends Handler_Protected {
if (count($ids) > 0) if (count($ids) > 0)
$this->publishArticlesById($ids, $cmode); $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() { function sanityCheck() {

Loading…
Cancel
Save