use ORM for article _labels_of/_feeds_of
This commit is contained in:
parent
f9888fc67f
commit
20d0cbff77
|
@ -417,42 +417,39 @@ class Article extends Handler_Protected {
|
|||
}
|
||||
|
||||
function getmetadatabyid() {
|
||||
$id = clean($_REQUEST['id']);
|
||||
$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']);
|
||||
|
||||
$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'];
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue