Commit 71db2cb1 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

USe Akonadi/ClearCacheJob

parent 37ca710e
Pipeline #203637 failed with stage
in 35 seconds
......@@ -12,6 +12,7 @@
#include "collectioninternalspage.h"
#include "config-akonadiconsole.h"
#include "tagpropertiesdialog.h"
#include <Akonadi/ClearCacheJob>
#include <Akonadi/DbAccess>
#include <Akonadi/AttributeFactory>
......@@ -526,52 +527,10 @@ void BrowserWidget::dumpToXmlResult(KJob *job)
void BrowserWidget::clearCache()
{
const Collection coll = currentCollection();
if (!coll.isValid()) {
return;
}
const auto ridCount = QStringLiteral("SELECT COUNT(*) FROM PimItemTable WHERE collectionId=%1 AND remoteId=''").arg(coll.id());
QSqlQuery query(DbAccess::database());
if (!query.exec(ridCount)) {
qCWarning(AKONADICONSOLE_LOG) << "Failed to execute query" << ridCount << ":" << query.lastError().text();
KMessageBox::error(this, query.lastError().text());
return;
}
query.next();
const int emptyRidCount = query.value(0).toInt();
if (emptyRidCount > 0) {
if (KMessageBox::warningContinueCancel(this,
QStringLiteral("The collection '%1' contains %2 items without Remote ID. "
"Those items were likely never uploaded to the destination server, "
"so clearing this collection means that those <b>data will be lost</b>. "
"Are you sure you want to proceed?")
.arg(coll.id())
.arg(emptyRidCount),
QStringLiteral("POSSIBLE DATA LOSS!"))
== KMessageBox::Cancel) {
return;
}
}
QString str = QStringLiteral("DELETE FROM PimItemTable WHERE collectionId=%1").arg(coll.id());
qCDebug(AKONADICONSOLE_LOG) << str;
query = QSqlQuery(str, DbAccess::database());
if (query.exec()) {
if (query.lastError().isValid()) {
qCDebug(AKONADICONSOLE_LOG) << query.lastError();
KMessageBox::error(this, query.lastError().text());
}
}
// TODO: Clear external parts
// TODO: Reset Akonadi's internal collection statistics cache
// TODO: Notify all clients EXCEPT FOR THE RESOURCE about the deletion?
// TODO: Clear search index
// TODO: ???
KMessageBox::information(this, QStringLiteral("Collection cache cleared. You should restart Akonadi now."));
Akonadi::ClearCacheJob *job = new Akonadi::ClearCacheJob(this);
job->setCollection(currentCollection());
job->setParentWidget(this);
job->start();
}
Akonadi::Collection BrowserWidget::currentCollection() const
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment