summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-03-29 18:20:17 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-03-29 18:20:17 +0200
commit02894290c87f8529e109824190845f95f5b92960 (patch)
tree53be3a84ba8da28548cacb842a567b30214612f0
parente7c2e4c9072b72162421965980419288f132656f (diff)
downloadsink-02894290c87f8529e109824190845f95f5b92960.tar.gz
sink-02894290c87f8529e109824190845f95f5b92960.zip
Migrate from sink.dav to sink.carddav
-rw-r--r--common/resourceconfig.cpp10
-rw-r--r--common/resourceconfig.h1
-rw-r--r--common/store.cpp12
3 files changed, 22 insertions, 1 deletions
diff --git a/common/resourceconfig.cpp b/common/resourceconfig.cpp
index 68ac0bc..5270df6 100644
--- a/common/resourceconfig.cpp
+++ b/common/resourceconfig.cpp
@@ -49,6 +49,16 @@ void ResourceConfig::addResource(const QByteArray &identifier, const QByteArray
49 settings->sync(); 49 settings->sync();
50} 50}
51 51
52void ResourceConfig::setResourceType(const QByteArray &identifier, const QByteArray &type)
53{
54 auto settings = getConfig("resources");
55 settings->beginGroup(QString::fromLatin1(identifier));
56 settings->setValue(Sink::ApplicationDomain::SinkResource::ResourceType::name, type);
57 settings->endGroup();
58 settings->sync();
59}
60
61
52void ResourceConfig::removeResource(const QByteArray &identifier) 62void ResourceConfig::removeResource(const QByteArray &identifier)
53{ 63{
54 auto settings = getConfig("resources"); 64 auto settings = getConfig("resources");
diff --git a/common/resourceconfig.h b/common/resourceconfig.h
index fb74249..f02590d 100644
--- a/common/resourceconfig.h
+++ b/common/resourceconfig.h
@@ -32,6 +32,7 @@ public:
32 static QByteArray getResourceType(const QByteArray &identifier); 32 static QByteArray getResourceType(const QByteArray &identifier);
33 static QByteArray newIdentifier(const QByteArray &type); 33 static QByteArray newIdentifier(const QByteArray &type);
34 static void addResource(const QByteArray &identifier, const QByteArray &type); 34 static void addResource(const QByteArray &identifier, const QByteArray &type);
35 static void setResourceType(const QByteArray &identifier, const QByteArray &type);
35 static void removeResource(const QByteArray &identifier); 36 static void removeResource(const QByteArray &identifier);
36 static void clear(); 37 static void clear();
37 static void configureResource(const QByteArray &identifier, const QMap<QByteArray, QVariant> &configuration); 38 static void configureResource(const QByteArray &identifier, const QMap<QByteArray, QVariant> &configuration);
diff --git a/common/store.cpp b/common/store.cpp
index 4c9ef4c..be2488a 100644
--- a/common/store.cpp
+++ b/common/store.cpp
@@ -332,7 +332,8 @@ static KAsync::Job<Store::UpgradeResult> upgrade(const QByteArray &resource)
332 } 332 }
333 SinkLog() << "Upgrading " << resource; 333 SinkLog() << "Upgrading " << resource;
334 334
335 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); 335 //We're not using the factory to avoid getting a cached resourceaccess with the wrong resourceType
336 auto resourceAccess = Sink::ResourceAccess::Ptr{new Sink::ResourceAccess(resource, ResourceConfig::getResourceType(resource)), &QObject::deleteLater};
336 return resourceAccess->sendCommand(Sink::Commands::UpgradeCommand) 337 return resourceAccess->sendCommand(Sink::Commands::UpgradeCommand)
337 .addToContext(resourceAccess) 338 .addToContext(resourceAccess)
338 .then([=](const KAsync::Error &error) { 339 .then([=](const KAsync::Error &error) {
@@ -349,6 +350,15 @@ static KAsync::Job<Store::UpgradeResult> upgrade(const QByteArray &resource)
349KAsync::Job<Store::UpgradeResult> Store::upgrade() 350KAsync::Job<Store::UpgradeResult> Store::upgrade()
350{ 351{
351 SinkLog() << "Upgrading..."; 352 SinkLog() << "Upgrading...";
353
354 //Migrate from sink.dav to sink.carddav
355 const auto resources = ResourceConfig::getResources();
356 for (auto it = resources.constBegin(); it != resources.constEnd(); it++) {
357 if (it.value() == "sink.dav") {
358 ResourceConfig::setResourceType(it.key(), "sink.carddav");
359 }
360 }
361
352 auto ret = QSharedPointer<bool>::create(false); 362 auto ret = QSharedPointer<bool>::create(false);
353 return fetchAll<ApplicationDomain::SinkResource>({}) 363 return fetchAll<ApplicationDomain::SinkResource>({})
354 .template each([ret](const ApplicationDomain::SinkResource::Ptr &resource) -> KAsync::Job<void> { 364 .template each([ret](const ApplicationDomain::SinkResource::Ptr &resource) -> KAsync::Job<void> {