]> git.wh0rd.org - tt-rss.git/blobdiff - classes/labels.php
fix missing sprintf() argument
[tt-rss.git] / classes / labels.php
index 9c6f22f5177989fe173959ac4d83284f1c864d4b..fd9e454bb106f478b079274e4a306781055b9a5f 100644 (file)
@@ -42,7 +42,7 @@ class Labels
 
                $pdo = Db::pdo();
 
-               $sth = $pdo->prepare("SELECT id, fg_color, bg_color, caption FROM ttrss_labels2 
+               $sth = $pdo->prepare("SELECT id, fg_color, bg_color, caption FROM ttrss_labels2
                        WHERE owner_uid = ? ORDER BY caption");
                $sth->execute([$owner_uid]);
 
@@ -62,7 +62,7 @@ class Labels
                if (!$labels)
                        $labels = Article::get_article_labels($id);
 
-               $labels = db_escape_string(json_encode($labels));
+               $labels = json_encode($labels);
 
                $sth = $pdo->prepare("UPDATE ttrss_user_entries SET
                        label_cache = ? WHERE ref_id = ? AND owner_uid = ?");
@@ -131,8 +131,13 @@ class Labels
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
 
                $pdo = Db::pdo();
+               $tr_in_progress = false;
 
-               $pdo->beginTransaction();
+               try {
+                       $pdo->beginTransaction();
+               } catch (Exception $e) {
+                       $tr_in_progress = true;
+               }
 
                $sth = $pdo->prepare("SELECT caption FROM ttrss_labels2
                        WHERE id = ?");
@@ -163,7 +168,7 @@ class Labels
 
                }
 
-               $pdo->commit();
+               if (!$tr_in_progress) $pdo->commit();
        }
 
        static function create($caption, $fg_color = '', $bg_color = '', $owner_uid = false)    {
@@ -172,14 +177,20 @@ class Labels
 
                $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_labels2
                        WHERE caption = ? AND owner_uid = ?");
                $sth->execute([$caption, $owner_uid]);
 
                if (!$sth->fetch()) {
-                       $sth = $pdo->prepare("INSERT INTO ttrss_labels2 
+                       $sth = $pdo->prepare("INSERT INTO ttrss_labels2
                                (caption,owner_uid,fg_color,bg_color) VALUES (?, ?, ?, ?)");
 
                        $sth->execute([$caption, $owner_uid, $fg_color, $bg_color]);
@@ -187,7 +198,7 @@ class Labels
                        $result = $sth->rowCount();
                }
 
-               $pdo->commit();
+               if (!$tr_in_progress) $pdo->commit();
 
                return $result;
        }