From 02894290c87f8529e109824190845f95f5b92960 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 29 Mar 2018 18:20:17 +0200 Subject: Migrate from sink.dav to sink.carddav --- common/resourceconfig.cpp | 10 ++++++++++ common/resourceconfig.h | 1 + common/store.cpp | 12 +++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) (limited to 'common') 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 settings->sync(); } +void ResourceConfig::setResourceType(const QByteArray &identifier, const QByteArray &type) +{ + auto settings = getConfig("resources"); + settings->beginGroup(QString::fromLatin1(identifier)); + settings->setValue(Sink::ApplicationDomain::SinkResource::ResourceType::name, type); + settings->endGroup(); + settings->sync(); +} + + void ResourceConfig::removeResource(const QByteArray &identifier) { 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: static QByteArray getResourceType(const QByteArray &identifier); static QByteArray newIdentifier(const QByteArray &type); static void addResource(const QByteArray &identifier, const QByteArray &type); + static void setResourceType(const QByteArray &identifier, const QByteArray &type); static void removeResource(const QByteArray &identifier); static void clear(); static void configureResource(const QByteArray &identifier, const QMap &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 upgrade(const QByteArray &resource) } SinkLog() << "Upgrading " << resource; - auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); + //We're not using the factory to avoid getting a cached resourceaccess with the wrong resourceType + auto resourceAccess = Sink::ResourceAccess::Ptr{new Sink::ResourceAccess(resource, ResourceConfig::getResourceType(resource)), &QObject::deleteLater}; return resourceAccess->sendCommand(Sink::Commands::UpgradeCommand) .addToContext(resourceAccess) .then([=](const KAsync::Error &error) { @@ -349,6 +350,15 @@ static KAsync::Job upgrade(const QByteArray &resource) KAsync::Job Store::upgrade() { SinkLog() << "Upgrading..."; + + //Migrate from sink.dav to sink.carddav + const auto resources = ResourceConfig::getResources(); + for (auto it = resources.constBegin(); it != resources.constEnd(); it++) { + if (it.value() == "sink.dav") { + ResourceConfig::setResourceType(it.key(), "sink.carddav"); + } + } + auto ret = QSharedPointer::create(false); return fetchAll({}) .template each([ret](const ApplicationDomain::SinkResource::Ptr &resource) -> KAsync::Job { -- cgit v1.2.3