From 281f2efeb8a8fca6e145a816b77303373c200ace Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 25 Feb 2021 19:21:29 +0300 Subject: wrap prefs->migrate() into a transaction block --- classes/prefs.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'classes/prefs.php') diff --git a/classes/prefs.php b/classes/prefs.php index 29e315c22..fbe2d33d8 100644 --- a/classes/prefs.php +++ b/classes/prefs.php @@ -162,6 +162,9 @@ class Prefs { $owner_uid = (int) $_SESSION["uid"]; $profile_id = $_SESSION["profile"] ?? null; + + $in_nested_tr = false; + $this->migrate($owner_uid, $profile_id); $this->cache_all($owner_uid, $profile_id); }; @@ -352,6 +355,14 @@ class Prefs { if (!$this->_get(Prefs::_PREFS_MIGRATED, $owner_uid, $profile_id)) { + $in_nested_tr = false; + + try { + $this->pdo->beginTransaction(); + } catch (PDOException $e) { + $in_nested_tr = true; + } + $sth = $this->pdo->prepare("SELECT pref_name, value FROM ttrss_user_prefs WHERE owner_uid = :uid AND (profile = :profile OR (:profile IS NULL AND profile IS NULL))"); @@ -370,6 +381,11 @@ class Prefs { } $this->_set(Prefs::_PREFS_MIGRATED, "1", $owner_uid, $profile_id); + + if (!$in_nested_tr) + $this->pdo->commit(); + + Logger::log(E_USER_NOTICE, sprintf("Migrated preferences of user %d (profile %d)", $owner_uid, $profile_id)); } } -- cgit v1.2.3