* Feeds::_get_counters - fix retrieving unread for tags

* mark several symbols as @deprecated properly
 * replace uses of (deprecated) getFeedUnread() with Feeds::_get_counters()
This commit is contained in:
Andrew Dolgov 2022-02-20 11:04:15 +03:00
parent 168dc6fe57
commit 77f39d65b5
5 changed files with 34 additions and 19 deletions

View File

@ -106,7 +106,7 @@ class API extends Handler {
$is_cat = self::_param_to_bool($_REQUEST["is_cat"] ?? false); $is_cat = self::_param_to_bool($_REQUEST["is_cat"] ?? false);
if ($feed_id) { if ($feed_id) {
return $this->_wrap(self::STATUS_OK, array("unread" => getFeedUnread($feed_id, $is_cat))); return $this->_wrap(self::STATUS_OK, array("unread" => Feeds::_get_counters($feed_id, $is_cat)));
} else { } else {
return $this->_wrap(self::STATUS_OK, array("unread" => Feeds::_get_global_unread())); return $this->_wrap(self::STATUS_OK, array("unread" => Feeds::_get_global_unread()));
} }
@ -152,7 +152,7 @@ class API extends Handler {
foreach ($categories->find_many() as $category) { foreach ($categories->find_many() as $category) {
if ($include_empty || $category->num_feeds > 0 || $category->num_cats > 0) { if ($include_empty || $category->num_feeds > 0 || $category->num_cats > 0) {
$unread = getFeedUnread($category->id, true); $unread = Feeds::_get_counters($category->id, true);
if ($enable_nested) if ($enable_nested)
$unread += Feeds::_get_cat_children_unread($category->id); $unread += Feeds::_get_cat_children_unread($category->id);
@ -170,7 +170,7 @@ class API extends Handler {
foreach ([-2,-1,0] as $cat_id) { foreach ([-2,-1,0] as $cat_id) {
if ($include_empty || !$this->_is_cat_empty($cat_id)) { if ($include_empty || !$this->_is_cat_empty($cat_id)) {
$unread = getFeedUnread($cat_id, true); $unread = Feeds::_get_counters($cat_id, true);
if ($unread || !$unread_only) { if ($unread || !$unread_only) {
array_push($cats, [ array_push($cats, [
@ -546,7 +546,7 @@ class API extends Handler {
if ($cat_id == -4 || $cat_id == -1) { if ($cat_id == -4 || $cat_id == -1) {
foreach ([-1, -2, -3, -4, -6, 0] as $i) { foreach ([-1, -2, -3, -4, -6, 0] as $i) {
$unread = getFeedUnread($i); $unread = Feeds::_get_counters($i);
if ($unread || !$unread_only) { if ($unread || !$unread_only) {
$title = Feeds::_get_title($i); $title = Feeds::_get_title($i);
@ -573,7 +573,7 @@ class API extends Handler {
->find_many(); ->find_many();
foreach ($categories as $category) { foreach ($categories as $category) {
$unread = getFeedUnread($category->id, true) + $unread = Feeds::_get_counters($category->id, true) +
Feeds::_get_cat_children_unread($category->id); Feeds::_get_cat_children_unread($category->id);
if ($unread || !$unread_only) { if ($unread || !$unread_only) {
@ -607,7 +607,7 @@ class API extends Handler {
} }
foreach ($feeds_obj->find_many() as $feed) { foreach ($feeds_obj->find_many() as $feed) {
$unread = getFeedUnread($feed->id); $unread = Feeds::_get_counters($feed->id);
$has_icon = Feeds::_has_icon($feed->id); $has_icon = Feeds::_has_icon($feed->id);
if ($unread || !$unread_only) { if ($unread || !$unread_only) {

View File

@ -250,7 +250,7 @@ class Counters {
for ($i = 0; $i >= -4; $i--) { for ($i = 0; $i >= -4; $i--) {
$count = getFeedUnread($i); $count = Feeds::_get_counters($i);
if ($i == 0 || $i == -1 || $i == -2) if ($i == 0 || $i == -1 || $i == -2)
$auxctr = Feeds::_get_counters($i, false); $auxctr = Feeds::_get_counters($i, false);

View File

@ -936,7 +936,15 @@ class Feeds extends Handler_Protected {
} }
} }
static function _get_counters(int $feed, bool $is_cat = false, bool $unread_only = false, ?int $owner_uid = null): int { /**
* @param int|string $feed feed id or tag name
* @param bool $is_cat
* @param bool $unread_only
* @param null|int $owner_uid
* @return int
* @throws PDOException
*/
static function _get_counters($feed, bool $is_cat = false, bool $unread_only = false, ?int $owner_uid = null): int {
$n_feed = (int) $feed; $n_feed = (int) $feed;
$need_entries = false; $need_entries = false;
@ -957,6 +965,7 @@ class Feeds extends Handler_Protected {
return self::_get_cat_unread($n_feed, $owner_uid); return self::_get_cat_unread($n_feed, $owner_uid);
} else if ($n_feed == -6) { } else if ($n_feed == -6) {
return 0; return 0;
// tags
} else if ($feed != "0" && $n_feed == 0) { } else if ($feed != "0" && $n_feed == 0) {
$sth = $pdo->prepare("SELECT SUM((SELECT COUNT(int_id) $sth = $pdo->prepare("SELECT SUM((SELECT COUNT(int_id)
@ -1498,7 +1507,7 @@ class Feeds extends Handler_Protected {
$view_query_part = " "; $view_query_part = " ";
} else if ($feed != -1) { } else if ($feed != -1) {
$unread = getFeedUnread($feed, $cat_view); $unread = Feeds::_get_counters($feed, $cat_view);
if ($cat_view && $feed > 0 && $include_children) if ($cat_view && $feed > 0 && $include_children)
$unread += self::_get_cat_children_unread($feed); $unread += self::_get_cat_children_unread($feed);

View File

@ -1111,7 +1111,7 @@ class Pref_Feeds extends Handler_Protected {
$title = Feeds::_get_title($feed_id, false); $title = Feeds::_get_title($feed_id, false);
if ($unread === false) if ($unread === false)
$unread = getFeedUnread($feed_id, false); $unread = Feeds::_get_counters($feed_id, false);
return [ return [
'id' => 'FEED:' . $feed_id, 'id' => 'FEED:' . $feed_id,

View File

@ -2,7 +2,7 @@
define('LABEL_BASE_INDEX', -1024); define('LABEL_BASE_INDEX', -1024);
define('PLUGIN_FEED_BASE_INDEX', -128); define('PLUGIN_FEED_BASE_INDEX', -128);
/** constant is @deprecated, use Config::SCHEMA_VERSION instead */ /** @deprecated by Config::SCHEMA_VERSION */
define('SCHEMA_VERSION', Config::SCHEMA_VERSION); define('SCHEMA_VERSION', Config::SCHEMA_VERSION);
if (version_compare(PHP_VERSION, '8.0.0', '<')) { if (version_compare(PHP_VERSION, '8.0.0', '<')) {
@ -179,18 +179,24 @@
return Config::get_version(); return Config::get_version();
} }
/** function is @deprecated by Config::get_schema_version() */ /** @deprecated by Config::get_schema_version() */
function get_schema_version(): int { function get_schema_version(): int {
return Config::get_schema_version(); return Config::get_schema_version();
} }
/** function is @deprecated by Debug::log() */ /** @deprecated by Debug::log() */
function _debug(string $msg): void { function _debug(string $msg): void {
Debug::log($msg); Debug::log($msg);
} }
/** function is @deprecated */
function getFeedUnread(int $feed, bool $is_cat = false): int { /** @deprecated by Feeds::_get_counters()
* @param int|string $feed feed id or tag name
* @param bool $is_cat
* @return int
* @throws PDOException
*/
function getFeedUnread($feed, bool $is_cat = false): int {
return Feeds::_get_counters($feed, $is_cat, true, $_SESSION["uid"]); return Feeds::_get_counters($feed, $is_cat, true, $_SESSION["uid"]);
} }
@ -239,23 +245,23 @@
return UrlHelper::validate($url); return UrlHelper::validate($url);
} }
/** function is @deprecated by UserHelper::authenticate() */ /** @deprecated by UserHelper::authenticate() */
function authenticate_user(string $login = null, string $password = null, bool $check_only = false, string $service = null): bool { function authenticate_user(string $login = null, string $password = null, bool $check_only = false, string $service = null): bool {
return UserHelper::authenticate($login, $password, $check_only, $service); return UserHelper::authenticate($login, $password, $check_only, $service);
} }
/** function is @deprecated by TimeHelper::smart_date_time() */ /** @deprecated by TimeHelper::smart_date_time() */
function smart_date_time(int $timestamp, int $tz_offset = 0, int $owner_uid = null, bool $eta_min = false): string { function smart_date_time(int $timestamp, int $tz_offset = 0, int $owner_uid = null, bool $eta_min = false): string {
return TimeHelper::smart_date_time($timestamp, $tz_offset, $owner_uid, $eta_min); return TimeHelper::smart_date_time($timestamp, $tz_offset, $owner_uid, $eta_min);
} }
/** function is @deprecated by TimeHelper::make_local_datetime() */ /** @deprecated by TimeHelper::make_local_datetime() */
function make_local_datetime(string $timestamp, bool $long, int $owner_uid = null, bool $no_smart_dt = false, bool $eta_min = false): string { function make_local_datetime(string $timestamp, bool $long, int $owner_uid = null, bool $no_smart_dt = false, bool $eta_min = false): string {
return TimeHelper::make_local_datetime($timestamp, $long, $owner_uid, $no_smart_dt, $eta_min); return TimeHelper::make_local_datetime($timestamp, $long, $owner_uid, $no_smart_dt, $eta_min);
} }
// this returns Config::SELF_URL_PATH sans ending slash // this returns Config::SELF_URL_PATH sans ending slash
/** function is @deprecated by Config::get_self_url() */ /** @deprecated by Config::get_self_url() */
function get_self_url_prefix(): string { function get_self_url_prefix(): string {
return Config::get_self_url(); return Config::get_self_url();
} }