can remove categories and accs, now to make proper changes of parents

This commit is contained in:
Martin Rotter 2022-03-15 15:46:18 +01:00
parent a312d02a07
commit aacf24726b
3 changed files with 8 additions and 4 deletions

View file

@ -1492,6 +1492,8 @@ bool DatabaseQueries::purgeMessagesFromBin(const QSqlDatabase& db, bool clear_on
} }
bool DatabaseQueries::deleteAccount(const QSqlDatabase& db, ServiceRoot* account) { bool DatabaseQueries::deleteAccount(const QSqlDatabase& db, ServiceRoot* account) {
moveItem(account, false, true, {}, db);
QSqlQuery query(db); QSqlQuery query(db);
query.setForwardOnly(true); query.setForwardOnly(true);
@ -2150,13 +2152,15 @@ bool DatabaseQueries::deleteFeed(const QSqlDatabase& db, Feed* feed, int account
purgeLeftoverLabelAssignments(db, account_id); purgeLeftoverLabelAssignments(db, account_id);
} }
bool DatabaseQueries::deleteCategory(const QSqlDatabase& db, int id) { bool DatabaseQueries::deleteCategory(const QSqlDatabase& db, Category* category) {
moveItem(category, false, true, {}, db);
QSqlQuery q(db); QSqlQuery q(db);
// Remove this category from database. // Remove this category from database.
q.setForwardOnly(true); q.setForwardOnly(true);
q.prepare(QSL("DELETE FROM Categories WHERE id = :category;")); q.prepare(QSL("DELETE FROM Categories WHERE id = :category;"));
q.bindValue(QSL(":category"), id); q.bindValue(QSL(":category"), category->id());
return q.exec(); return q.exec();
} }

View file

@ -125,7 +125,7 @@ class DatabaseQueries {
static void createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int new_parent_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 parent_id);
static bool deleteFeed(const QSqlDatabase& db, Feed* feed, int account_id); static bool deleteFeed(const QSqlDatabase& db, Feed* feed, int account_id);
static bool deleteCategory(const QSqlDatabase& db, int id); static bool deleteCategory(const QSqlDatabase& db, Category* category);
template<typename T> template<typename T>
static Assignment getCategories(const QSqlDatabase& db, int account_id, bool* ok = nullptr); static Assignment getCategories(const QSqlDatabase& db, int account_id, bool* ok = nullptr);

View file

@ -94,7 +94,7 @@ bool StandardCategory::removeItself() {
// Children are removed, remove this standard category too. // Children are removed, remove this standard category too.
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className()); QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
return DatabaseQueries::deleteCategory(database, id()); return DatabaseQueries::deleteCategory(database, this);
} }
else { else {
return false; return false;