summaryrefslogtreecommitdiffstats
path: root/common/store.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/store.cpp')
-rw-r--r--common/store.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/common/store.cpp b/common/store.cpp
index b16fa4e..2fa62d6 100644
--- a/common/store.cpp
+++ b/common/store.cpp
@@ -302,13 +302,33 @@ KAsync::Job<void> Store::removeDataFromDisk(const QByteArray &identifier)
302 }); 302 });
303} 303}
304 304
305static KAsync::Job<void> upgrade(const QByteArray &resource)
306{
307 SinkLog() << "Upgrading " << resource;
308 auto store = Sink::Storage::DataStore(Sink::storageLocation(), resource, Sink::Storage::DataStore::ReadOnly);
309 if (Storage::DataStore::databaseVersion(store.createTransaction(Storage::DataStore::ReadOnly)) >= Sink::latestDatabaseVersion()) {
310 return KAsync::null();
311 }
312
313 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource));
314 return resourceAccess->sendCommand(Sink::Commands::UpgradeCommand)
315 .addToContext(resourceAccess)
316 .then([=](const KAsync::Error &error) {
317 if (error) {
318 SinkWarning() << "Error during upgrade.";
319 return KAsync::error(error);
320 }
321 SinkTrace() << "Upgrade of resource " << resource << " complete.";
322 return KAsync::null();
323 });
324}
325
305KAsync::Job<void> Store::upgrade() 326KAsync::Job<void> Store::upgrade()
306{ 327{
307 SinkLog() << "Upgrading..."; 328 SinkLog() << "Upgrading...";
308 return fetchAll<ApplicationDomain::SinkResource>({}) 329 return fetchAll<ApplicationDomain::SinkResource>({})
309 .template each([](const ApplicationDomain::SinkResource::Ptr &resource) -> KAsync::Job<void> { 330 .template each([](const ApplicationDomain::SinkResource::Ptr &resource) -> KAsync::Job<void> {
310 SinkLog() << "Removing caches for " << resource->identifier(); 331 return Sink::upgrade(resource->identifier());
311 return removeDataFromDisk(resource->identifier());
312 }) 332 })
313 .then([] { 333 .then([] {
314 SinkLog() << "Upgrade complete."; 334 SinkLog() << "Upgrade complete.";