From 8740a007515dcf1b315d69ab5c64fcfd40ec980c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 11 Feb 2018 22:44:51 +0100 Subject: Return feedback on wether an upgrade has happened or not. --- common/store.cpp | 31 +++++++++++++++++++++---------- common/store.h | 6 +++++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/common/store.cpp b/common/store.cpp index edca842..c102c45 100644 --- a/common/store.cpp +++ b/common/store.cpp @@ -297,13 +297,13 @@ KAsync::Job Store::removeDataFromDisk(const QByteArray &identifier) }); } -static KAsync::Job upgrade(const QByteArray &resource) +static KAsync::Job upgrade(const QByteArray &resource) { - SinkLog() << "Upgrading " << resource; auto store = Sink::Storage::DataStore(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly); - if (Storage::DataStore::databaseVersion(store.createTransaction(Storage::DataStore::ReadOnly)) >= Sink::latestDatabaseVersion()) { - return KAsync::null(); + if (Storage::DataStore::databaseVersion(store.createTransaction(Storage::DataStore::ReadOnly)) == Sink::latestDatabaseVersion()) { + return KAsync::value(Store::UpgradeResult{false}); } + SinkLog() << "Upgrading " << resource; auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); return resourceAccess->sendCommand(Sink::Commands::UpgradeCommand) @@ -315,18 +315,29 @@ static KAsync::Job upgrade(const QByteArray &resource) } SinkTrace() << "Upgrade of resource " << resource << " complete."; return KAsync::null(); - }); + }) + .then(KAsync::value(Store::UpgradeResult{true})); } -KAsync::Job Store::upgrade() +KAsync::Job Store::upgrade() { SinkLog() << "Upgrading..."; + auto ret = QSharedPointer::create(false); return fetchAll({}) - .template each([](const ApplicationDomain::SinkResource::Ptr &resource) -> KAsync::Job { - return Sink::upgrade(resource->identifier()); + .template each([ret](const ApplicationDomain::SinkResource::Ptr &resource) -> KAsync::Job { + return Sink::upgrade(resource->identifier()) + .then([ret](UpgradeResult returnValue) { + if (returnValue.upgradeExecuted) { + SinkLog() << "Upgrade executed."; + *ret = true; + } + }); }) - .then([] { - SinkLog() << "Upgrade complete."; + .then([ret] { + if (*ret) { + SinkLog() << "Upgrade complete."; + } + return Store::UpgradeResult{*ret}; }); } diff --git a/common/store.h b/common/store.h index 62858c5..fb9c3fe 100644 --- a/common/store.h +++ b/common/store.h @@ -120,6 +120,10 @@ KAsync::Job SINK_EXPORT synchronize(const Sink::SyncScope &query); */ KAsync::Job SINK_EXPORT removeDataFromDisk(const QByteArray &resourceIdentifier); +struct UpgradeResult { + bool upgradeExecuted; +}; + /** * Run upgrade jobs. * @@ -130,7 +134,7 @@ KAsync::Job SINK_EXPORT removeDataFromDisk(const QByteArray &resourceIdent * * Note: The initial implementation simply calls removeDataFromDisk for all resources. */ -KAsync::Job SINK_EXPORT upgrade(); +KAsync::Job SINK_EXPORT upgrade(); template KAsync::Job SINK_EXPORT fetchOne(const Sink::Query &query); -- cgit v1.2.3