[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ktp-common-internals/kde-telepathy-0.7] kpeople/nepomuk-feeder: Wipe all KTp contacts when we relea
From:       David Edmundson <kde () davidedmundson ! co ! uk>
Date:       2013-10-25 11:30:55
Message-ID: E1VZfbT-0003fj-Q9 () scm ! kde ! org
[Download RAW message or body]

Git commit 476bd2968a8196edd0c820f705b0ad5791660734 by David Edmundson.
Committed on 13/10/2013 at 19:23.
Pushed by davidedmundson into branch 'kde-telepathy-0.7'.

Wipe all KTp contacts when we release

REVIEW: 113235

M  +60   -4    kpeople/nepomuk-feeder/controller.cpp
M  +1    -0    kpeople/nepomuk-feeder/controller.h

http://commits.kde.org/telepathy-common-internals/476bd2968a8196edd0c820f705b0ad5791660734


diff --git a/kpeople/nepomuk-feeder/controller.cpp \
b/kpeople/nepomuk-feeder/controller.cpp index fa37b7e..5814c65 100644
--- a/kpeople/nepomuk-feeder/controller.cpp
+++ b/kpeople/nepomuk-feeder/controller.cpp
@@ -25,9 +25,21 @@
 #include "abstract-storage.h"
 
 #include <KDebug>
+#include <KJob>
+#include <KConfig>
+#include <KConfigGroup>
 
 #include <TelepathyQt/PendingReady>
 
+
+#include <Nepomuk2/DataManagement>
+#include <Nepomuk2/Resource>
+#include <Nepomuk2/ResourceManager>
+#include <Soprano/Model>
+#include <Soprano/QueryResultIterator>
+
+#define CURRENT_FEEDER_VERSION 1
+
 Controller::Controller(AbstractStorage *storage, QObject *parent)
  : QObject(parent),
    m_storage(storage)
@@ -46,6 +58,54 @@ void Controller::onStorageInitialised(bool success)
         return;
     }
 
+    QTimer::singleShot(0, this, SLOT(start()));
+}
+
+
+
+Controller::~Controller()
+{
+    kDebug();
+}
+
+void Controller::start()
+{
+    //if old data, wipe everything before we start
+    //wiping this file will trigger a re-import
+    KSharedConfigPtr config = KSharedConfig::openConfig("telepathyfeeder");
+    KConfigGroup configGroup = config->group("Feeder");
+
+    if (configGroup.readEntry<int>("feederVersion", 0) != CURRENT_FEEDER_VERSION) {
+        kDebug() << "wiping old data";
+        //wipe contacts
+        {
+            const QString query = QString::fromLatin1("select distinct ?uri where \
{?uri a nco:PersonContact. ?uri nco:hasIMAccount ?x. }"); +            Soprano::Model \
*model = Nepomuk2::ResourceManager::instance()->mainModel(); +            \
Soprano::QueryResultIterator it = model->executeQuery(query, \
Soprano::Query::QueryLanguageSparql); +            while (it.next()) {
+                KJob *job = Nepomuk2::removeResources(QList<QUrl>() << \
it["uri"].uri()); +                job->exec();
+            }
+            kDebug() << "wiping old contacts done";
+        }
+        //wipe people with no grounding occurences
+        {
+            const QString query = QString::fromLatin1("select ?uri ?where {?uri a \
pimo:Person. FILTER NOT EXISTS {?uri pimo:groundingOccurrence ?x}}"); +            \
Soprano::Model *model = Nepomuk2::ResourceManager::instance()->mainModel(); +         \
Soprano::QueryResultIterator it = model->executeQuery(query, \
Soprano::Query::QueryLanguageSparql); +            while (it.next()) {
+                KJob *job = Nepomuk2::removeResources(QList<QUrl>() << \
it["uri"].uri()); +                job->exec();
+            }
+            kDebug() << "wiping old pimo:Persons done";
+        }
+    }
+
+    //update config file so this is only run once
+    configGroup.writeEntry("feederVersion", CURRENT_FEEDER_VERSION);
+    config->sync();
+
+
     kDebug() << "Storage initialisation succeeded. Setting up Telepathy stuff now.";
 
     // Set up the Factories.
@@ -91,10 +151,6 @@ void Controller::onStorageInitialised(bool success)
     kDebug() << "Calling becomeReady on the AM.";
 }
 
-Controller::~Controller()
-{
-    kDebug();
-}
 
 void Controller::onAccountManagerReady(Tp::PendingOperation *op)
 {
diff --git a/kpeople/nepomuk-feeder/controller.h \
b/kpeople/nepomuk-feeder/controller.h index b358c8e..2190f28 100644
--- a/kpeople/nepomuk-feeder/controller.h
+++ b/kpeople/nepomuk-feeder/controller.h
@@ -54,6 +54,7 @@ Q_SIGNALS:
     void storageInitialisationFailed();
 
 private Q_SLOTS:
+    void start();
     void onAccountManagerReady(Tp::PendingOperation *op);
     void onNewAccount(const Tp::AccountPtr &account);
     void onStorageInitialised(bool success);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic