]> git.wh0rd.org Git - tt-rss.git/commitdiff
fix sql crash workaround preventing feed/category filters from testing
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 24 Oct 2012 07:59:36 +0000 (11:59 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Wed, 24 Oct 2012 07:59:36 +0000 (11:59 +0400)
properly; fix filter testing for categories with children

include/functions.php

index ccaea76ac34a5bdf2fd418db8b9fff98ac87dc39..4c88c0350bbedcdfd6010e6f19b64cd606018627 100644 (file)
 
                                $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");
                        return $html;
        }
 
-       function filter_to_sql($filter) {
+       function filter_to_sql($link, $filter, $owner_uid) {
                $query = array();
 
                if (DB_TYPE == "pgsql")
                                }
 
                                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)");