]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
boolean handling changes which probably won't break everything
[tt-rss.git] / include / functions.php
index 4154d8d5e82293bf5d6cac94a40237eb0f1a32d5..0b301b82e0f3b34faed5320503c125a4b255d979 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; //no-op for PDO
        }
 
        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 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 (!$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)) 
                                        VALUES (?, ?, ?)");
                        $sth->execute([$_SESSION['uid'], $feed_cat, $parent_cat_id]);
 
-                       $pdo->commit();
+                       if (!$tr_in_progress) $pdo->commit();
 
                        return true;
                }