diff --git a/classes/feeds.php b/classes/feeds.php index 6f8ceeced..c67edbc51 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -1909,40 +1909,27 @@ class Feeds extends Handler_Protected { $cat->delete(); } - static function _add_cat($feed_cat, $parent_cat_id = false, $order_id = 0) { + static function _add_cat(string $title, int $owner_uid, int $parent_cat = null, int $order_id = 0) { - if (!$feed_cat) return false; + $cat = ORM::for_table('ttrss_feed_categories') + ->where('owner_uid', $owner_uid) + ->where('parent_cat', $parent_cat) + ->where('title', $title) + ->find_one(); - $feed_cat = mb_substr($feed_cat, 0, 250); - if (!$parent_cat_id) $parent_cat_id = null; + if (!$cat) { + $cat = ORM::for_table('ttrss_feed_categories')->create(); - $pdo = Db::pdo(); - $tr_in_progress = false; + $cat->set([ + 'owner_uid' => $owner_uid, + 'parent_cat' => $parent_cat, + 'order_id' => $order_id, + 'title' => $title, + ]); - try { - $pdo->beginTransaction(); - } catch (Exception $e) { - $tr_in_progress = true; + return $cat->save(); } - $sth = $pdo->prepare("SELECT id FROM ttrss_feed_categories - 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()) { - - $sth = $pdo->prepare("INSERT INTO ttrss_feed_categories (owner_uid,title,parent_cat,order_id) - VALUES (?, ?, ?, ?)"); - $sth->execute([$_SESSION['uid'], $feed_cat, $parent_cat_id, (int)$order_id]); - - if (!$tr_in_progress) $pdo->commit(); - - return true; - } - - $pdo->commit(); - return false; } diff --git a/classes/opml.php b/classes/opml.php index aa4879c4c..c60d411eb 100644 --- a/classes/opml.php +++ b/classes/opml.php @@ -31,7 +31,7 @@ class OPML extends Handler_Protected {

".__('OPML Utility')."

"; - Feeds::_add_cat("Imported feeds"); + Feeds::_add_cat("Imported feeds", $owner_uid); $this->opml_notice(__("Importing OPML...")); @@ -521,9 +521,8 @@ class OPML extends Handler_Protected { if ($cat_id === false) { $order_id = (int) $root_node->attributes->getNamedItem('ttrssSortOrder')->nodeValue; - if (!$order_id) $order_id = 0; - Feeds::_add_cat($cat_title, $parent_id, $order_id); + Feeds::_add_cat($cat_title, $_SESSION['uid'], $parent_id ? $parent_id : null, (int)$order_id); $cat_id = $this->get_feed_category($cat_title, $parent_id); } diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 2afa9013c..340f6515d 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -867,7 +867,7 @@ class Pref_Feeds extends Handler_Protected { function addCat() { $feed_cat = clean($_REQUEST["cat"]); - Feeds::_add_cat($feed_cat); + Feeds::_add_cat($feed_cat, $_SESSION['uid']); } function importOpml() {