fixup wrong order ids

This commit is contained in:
Martin Rotter 2022-03-02 15:11:17 +01:00
parent 9b97c34bda
commit 45d7a78684
2 changed files with 13 additions and 7 deletions

View File

@ -2096,14 +2096,14 @@ bool DatabaseQueries::deleteCategory(const QSqlDatabase& db, int id) {
} }
void DatabaseQueries::fixupOrders(const QSqlDatabase& db) { void DatabaseQueries::fixupOrders(const QSqlDatabase& db) {
QSqlQuery res = db.exec(QSL("SELECT COUNT(*) FROM Accounts WHERE ordr = 0 " // We first determine if there are same orders assigned to some items
// which have same parent category/acc.
QSqlQuery res = db.exec(QSL("SELECT COUNT(*) FROM Accounts GROUP BY ordr HAVING COUNT(*) > 1 "
"UNION ALL " "UNION ALL "
"SELECT COUNT(*) FROM Categories WHERE ordr = 0 " "SELECT COUNT(*) FROM Categories GROUP BY account_id, parent_id, ordr HAVING COUNT(*) > 1 "
"UNION ALL " "UNION ALL "
"SELECT COUNT(*) FROM Feeds WHERE ordr = 0;")); "SELECT COUNT(*) FROM Feeds GROUP BY account_id, category, ordr HAVING COUNT(*) > 1;"));
bool should_fixup = false; bool should_fixup = res.lastError().isValid() || res.size() > 0;
while (res.next() && !(should_fixup = (res.value(0).toInt() > 1))) {}
if (should_fixup) { if (should_fixup) {
// Some orders are messed up, fix. // Some orders are messed up, fix.
@ -2117,6 +2117,9 @@ void DatabaseQueries::fixupOrders(const QSqlDatabase& db) {
} }
} }
} }
else {
qDebugNN << LOGSEC_DB << "No fixing of item order is needed.";
}
} }
void DatabaseQueries::moveItemUp(RootItem* item, const QSqlDatabase& db) {} void DatabaseQueries::moveItemUp(RootItem* item, const QSqlDatabase& db) {}

View File

@ -205,7 +205,10 @@ class RSSGUARD_DLLSPEC RootItem : public QObject {
// which can be manually sorted. Other types like "Label" cannot be // which can be manually sorted. Other types like "Label" cannot be
// automatically sorted and are always sorted by title. // automatically sorted and are always sorted by title.
// //
// Sort order number cannot be negative. // Sort order number cannot be negative but order of list of items with same
// parent does not have to form continuous series, for example:
// 0, 1, 2, 3, 4, ...
// 5, 7, 12, 13, 19
int sortOrder() const; int sortOrder() const;
void setSortOrder(int sort_order); void setSortOrder(int sort_order);