]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
more boolean fixes
[tt-rss.git] / include / functions.php
index c28460dff1e330036db1c6611c8342dbf9fbb4ca..6637bd5d1a1a1d253a508351a2434ee961ca5d39 100644 (file)
                if (get_schema_version() < 63) $profile_qpart = "";
 
         $pdo = DB::pdo();
+        $in_nested_tr = false;
 
-        $pdo->beginTransaction();
+        try {
+                       $pdo->beginTransaction();
+               } catch (Exception $e) {
+               $in_nested_tr = true;
+               }
 
                $sth = $pdo->query("SELECT pref_name,def_value FROM ttrss_prefs");
 
                        }
                }
 
-               $pdo->commit();
+               if (!$in_nested_tr) $pdo->commit();
 
        }
 
        }
 
        function sql_bool_to_bool($s) {
-               if ($s == "t" || $s == "1" || strtolower($s) == "true") {
-                       return true;
-               } else {
-                       return false;
-               }
+               return $s && ($s != "f" && $s != "false"); //no-op for PDO, backwards compat for legacy layer
        }
 
        function bool_to_sql_bool($s) {
-               if ($s) {
-                       return "true";
-               } else {
-                       return "false";
-               }
+               return (bool)$s; //no-op for PDO
        }
 
        // Session caching removed due to causing wrong redirects to upgrade
        }
 
        function checkbox_to_sql_bool($val) {
-               return ($val == "on") ? "true" : "false";
+               return ($val == "on") ? true : false;
        }
 
        function uniqid_short() {
        function load_filters($feed_id, $owner_uid) {
                $filters = array();
 
+               $feed_id = (int) $feed_id;
                $cat_id = (int)Feeds::getFeedCategory($feed_id);
 
                if ($cat_id == 0)
                if (!$feed_cat) return false;
 
                $feed_cat = mb_substr($feed_cat, 0, 250);
+               if (!$parent_cat_id) $parent_cat_id = null;
 
                $pdo = Db::pdo();
-               $pdo->beginTransaction();
+               $tr_in_progress = false;
+
+               try {
+                       $pdo->beginTransaction();
+               } catch (Exception $e) {
+                       $tr_in_progress = true;
+               }
 
                $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories
                                WHERE (parent_cat = :parent OR (:parent IS NULL AND parent_cat IS NULL)) 
-                               AND title = :cat AND owner_uid = :uid");
+                               AND title = :title AND owner_uid = :uid");
                $sth->execute([':parent' => $parent_cat_id, ':title' => $feed_cat, ':uid' => $_SESSION['uid']]);
 
-               if ($sth->fetch()) {
+               if (!$sth->fetch()) {
 
                        $sth = $pdo->prepare("INSERT INTO ttrss_feed_categories (owner_uid,title,parent_cat)
                                        VALUES (?, ?, ?)");
                        $sth->execute([$_SESSION['uid'], $feed_cat, $parent_cat_id]);
 
-                       $pdo->commit();
+                       if (!$tr_in_progress) $pdo->commit();
 
                        return true;
                }