From 2680295b1958c9890ff3fafa0f82ba506d11a87d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 24 Oct 2012 11:59:36 +0400 Subject: [PATCH] fix sql crash workaround preventing feed/category filters from testing properly; fix filter testing for categories with children --- include/functions.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/include/functions.php b/include/functions.php index ccaea76a..4c88c035 100644 --- a/include/functions.php +++ b/include/functions.php @@ -2321,10 +2321,11 @@ $override_order = "updated DESC"; - $filter_query_part = filter_to_sql($filter); + $filter_query_part = filter_to_sql($link, $filter, $owner_uid); // Try to check if SQL regexp implementation chokes on a valid regexp - $result = db_query($link, "SELECT true AS true FROM ttrss_entries + $result = db_query($link, "SELECT true AS true FROM ttrss_entries, + ttrss_user_entries, ttrss_feeds, ttrss_feed_categories WHERE $filter_query_part LIMIT 1", false); $test = db_fetch_result($result, 0, "true"); @@ -5110,7 +5111,7 @@ return $html; } - function filter_to_sql($filter) { + function filter_to_sql($link, $filter, $owner_uid) { $query = array(); if (DB_TYPE == "pgsql") @@ -5159,7 +5160,19 @@ } if (isset($rule["cat_id"])) { - $qpart .= " AND cat_id " . ($rule["cat_id"] ? '= ' . $rule["cat_id"] : 'IS NULL'); + + if ($rule["cat_id"] > 0) { + $children = getChildCategories($link, $rule["cat_id"], $owner_uid); + array_push($children, $rule["cat_id"]); + + $children = join(",", $children); + + $cat_qpart = "cat_id IN ($children)"; + } else { + $cat_qpart = "cat_id IS NULL"; + } + + $qpart .= " AND $cat_qpart"; } array_push($query, "($qpart)"); -- 2.39.5