From c6cfb2e5df5f780eaffa506bc99467f39dfb5ef8 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 16 Mar 2022 08:14:50 +0100 Subject: [PATCH] experimental implementation of #302 --- .../desktop/com.github.rssguard.appdata.xml | 2 +- src/librssguard/database/databasequeries.cpp | 18 ++++++++---------- src/librssguard/database/databasequeries.h | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/resources/desktop/com.github.rssguard.appdata.xml b/resources/desktop/com.github.rssguard.appdata.xml index 5c1f6f164..73109080f 100644 --- a/resources/desktop/com.github.rssguard.appdata.xml +++ b/resources/desktop/com.github.rssguard.appdata.xml @@ -26,7 +26,7 @@ https://github.com/sponsors/martinrotter - + none diff --git a/src/librssguard/database/databasequeries.cpp b/src/librssguard/database/databasequeries.cpp index 8a191e72d..c2eac5148 100644 --- a/src/librssguard/database/databasequeries.cpp +++ b/src/librssguard/database/databasequeries.cpp @@ -1936,18 +1936,15 @@ QStringList DatabaseQueries::customIdsOfMessagesFromFeed(const QSqlDatabase& db, return ids; } -void DatabaseQueries::createOverwriteCategory(const QSqlDatabase& db, Category* category, int account_id, int parent_id) { +void DatabaseQueries::createOverwriteCategory(const QSqlDatabase& db, Category* category, int account_id, int new_parent_id) { QSqlQuery q(db); int next_sort_order; - // TODO: check, then go to createoverwriteaccount - - if ((category->id() <= 0 && category->sortOrder() < 0) || - (category->parent() != nullptr && category->parent()->id() != parent_id)) { - // We need to insert category first. + if (category->id() <= 0 || + (category->parent() != nullptr && category->parent()->id() != new_parent_id)) { q.prepare(QSL("SELECT MAX(ordr) FROM Categories WHERE account_id = :account_id AND parent_id = :parent_id;")); q.bindValue(QSL(":account_id"), account_id); - q.bindValue(QSL(":parent_id"), parent_id); + q.bindValue(QSL(":parent_id"), new_parent_id); if (!q.exec() || !q.next()) { throw ApplicationException(q.lastError().text()); @@ -1961,6 +1958,7 @@ void DatabaseQueries::createOverwriteCategory(const QSqlDatabase& db, Category* } if (category->id() <= 0) { + // We need to insert category first. q.prepare(QSL("INSERT INTO " "Categories (parent_id, ordr, title, date_created, account_id) " "VALUES (0, 0, 'new', 0, %1);").arg(QString::number(account_id))); @@ -1972,7 +1970,7 @@ void DatabaseQueries::createOverwriteCategory(const QSqlDatabase& db, Category* category->setId(q.lastInsertId().toInt()); } } - else if (category->parent() != nullptr && category->parent()->id() != parent_id) { + else if (category->parent() != nullptr && category->parent()->id() != new_parent_id) { // Category is moving between parents. // 1. Move category to bottom of current parent. // 2. Assign proper new sort order. @@ -1989,7 +1987,7 @@ void DatabaseQueries::createOverwriteCategory(const QSqlDatabase& db, Category* "SET parent_id = :parent_id, ordr = :ordr, title = :title, description = :description, date_created = :date_created, " " icon = :icon, account_id = :account_id, custom_id = :custom_id " "WHERE id = :id;"); - q.bindValue(QSL(":parent_id"), parent_id); + q.bindValue(QSL(":parent_id"), new_parent_id); q.bindValue(QSL(":title"), category->title()); q.bindValue(QSL(":description"), category->description()); q.bindValue(QSL(":date_created"), category->creationDate().toMSecsSinceEpoch()); @@ -2008,7 +2006,7 @@ void DatabaseQueries::createOverwriteFeed(const QSqlDatabase& db, Feed* feed, in QSqlQuery q(db); int next_sort_order; - if ((feed->id() <= 0 && feed->sortOrder() < 0) || + if (feed->id() <= 0 || (feed->parent() != nullptr && feed->parent()->id() != new_parent_id)) { // We either insert completely new feed or we move feed // to new parent. Get new viable sort order. diff --git a/src/librssguard/database/databasequeries.h b/src/librssguard/database/databasequeries.h index 6b35caff4..eebe91204 100644 --- a/src/librssguard/database/databasequeries.h +++ b/src/librssguard/database/databasequeries.h @@ -123,7 +123,7 @@ class DatabaseQueries { static bool cleanFeeds(const QSqlDatabase& db, const QStringList& ids, bool clean_read_only, int account_id); static void storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id); static void createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int new_parent_id); - static void createOverwriteCategory(const QSqlDatabase& db, Category* category, int account_id, int parent_id); + static void createOverwriteCategory(const QSqlDatabase& db, Category* category, int account_id, int new_parent_id); static bool deleteFeed(const QSqlDatabase& db, Feed* feed, int account_id); static bool deleteCategory(const QSqlDatabase& db, Category* category);