]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
rpc: switch to PDO
[tt-rss.git] / include / functions.php
index 8d25457c9f8a9f1a08f27e9fe5737e1ef1d8259c..f09d72cd079607803da01d0cd31387562fb887b2 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");
 
 
                $u_sth = $pdo->prepare("SELECT pref_name
                        FROM ttrss_user_prefs WHERE owner_uid = :uid AND 
-                               profile = :profile OR (:profile IS NULL AND profile IS NULL)");
+                               (profile = :profile OR (:profile IS NULL AND profile IS NULL))");
                $u_sth->execute([':uid' => $uid, ':profile' => $profile]);
 
                $active_prefs = array();
                        }
                }
 
-               $pdo->commit();
+               if (!$in_nested_tr) $pdo->commit();
 
        }
 
                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();
 
                $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories
-                               WHERE (:parent IS NULL AND parent_cat IS NULL OR parent_cat = :parent
-                               AND title = :cat AND owner_uid = :uid");
+                               WHERE (parent_cat = :parent OR (:parent IS NULL AND parent_cat IS NULL)
+                               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 (?, ?, ?)");