summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2014-01-16 22:13:20 (GMT)
committerChristian Mollekopf <chrigi_1@fastmail.fm>2014-01-16 22:13:20 (GMT)
commita8fd4e617845e2fc94610f8a48ad8c623c7eb9f1 (patch)
tree6c1bffd56a658a9c71779159e9215ae473da1c9a
parent597668e55aed89e8c732aa1e017c056cf32633e1 (diff)
downloadkolab-utils-a8fd4e617845e2fc94610f8a48ad8c623c7eb9f1.tar.gz
A simple object type filter, so we can i.e. only migrate contacts.
Currently only implemented for the google migration.
-rw-r--r--migrationutility/googlesourceserver.cpp51
-rw-r--r--migrationutility/main.cpp4
-rw-r--r--migrationutility/sourceserver.cpp13
-rw-r--r--migrationutility/sourceserver.h6
4 files changed, 57 insertions, 17 deletions
diff --git a/migrationutility/googlesourceserver.cpp b/migrationutility/googlesourceserver.cpp
index f609c41..156ef81 100644
--- a/migrationutility/googlesourceserver.cpp
+++ b/migrationutility/googlesourceserver.cpp
@@ -27,9 +27,9 @@
GoogleSourceServer::GoogleSourceServer(QObject* parent)
: SourceServer(parent),
+ mPort(993),
mEncryptionMode(KIMAP::LoginJob::AnySslVersion),
- mAuthenticationMode(KIMAP::LoginJob::ClearText),
- mPort(993)
+ mAuthenticationMode(KIMAP::LoginJob::ClearText)
{
}
@@ -59,24 +59,41 @@ void GoogleSourceServer::setAuthentication(KIMAP::LoginJob::AuthenticationMode a
QList<SourceAccount*> GoogleSourceServer::getSourceAccountsImpl(const QString& user)
{
QList <SourceAccount*> sourceAccounts;
- GoogleContactsSourceAccount *contactsAccount = new GoogleContactsSourceAccount(this);
- contactsAccount->setUser(user);
- sourceAccounts << contactsAccount;
- GoogleCalendarSourceAccount *calendarAccount = new GoogleCalendarSourceAccount(this);
- calendarAccount->setAccount(contactsAccount->account());
- calendarAccount->setUser(user);
- sourceAccounts << calendarAccount;
+ KGAPI2::AccountPtr sharedAccount;
- GoogleTasksSourceAccount *tasksAccount = new GoogleTasksSourceAccount(this);
- tasksAccount->setAccount(contactsAccount->account());
- tasksAccount->setUser(user);
- sourceAccounts << tasksAccount;
+ if (shouldMigrateType("contacts")) {
+ GoogleContactsSourceAccount *contactsAccount = new GoogleContactsSourceAccount(this);
+ contactsAccount->setUser(user);
+ sourceAccounts << contactsAccount;
+ sharedAccount = contactsAccount->account();
+ }
- IMAPSourceAccount *imapAccount = new IMAPSourceAccount(this);
- imapAccount->prepareConnection(mHost, mPort, user, user, mPw, mEncryptionMode, mAuthenticationMode);
- imapAccount->setIgnoredFolders(ignoredFolders());
- sourceAccounts << imapAccount;
+ if (shouldMigrateType("events")) {
+ GoogleCalendarSourceAccount *calendarAccount = new GoogleCalendarSourceAccount(this);
+ if (sharedAccount) {
+ calendarAccount->setAccount(sharedAccount);
+ }
+ calendarAccount->setUser(user);
+ sourceAccounts << calendarAccount;
+ sharedAccount = calendarAccount->account();
+ }
+
+ if (shouldMigrateType("tasks")) {
+ GoogleTasksSourceAccount *tasksAccount = new GoogleTasksSourceAccount(this);
+ if (sharedAccount) {
+ tasksAccount->setAccount(sharedAccount);
+ }
+ tasksAccount->setUser(user);
+ sourceAccounts << tasksAccount;
+ }
+
+ if (shouldMigrateType("mail")) {
+ IMAPSourceAccount *imapAccount = new IMAPSourceAccount(this);
+ imapAccount->prepareConnection(mHost, mPort, user, user, mPw, mEncryptionMode, mAuthenticationMode);
+ imapAccount->setIgnoredFolders(ignoredFolders());
+ sourceAccounts << imapAccount;
+ }
return sourceAccounts;
} \ No newline at end of file
diff --git a/migrationutility/main.cpp b/migrationutility/main.cpp
index d501917..e9166b9 100644
--- a/migrationutility/main.cpp
+++ b/migrationutility/main.cpp
@@ -89,6 +89,7 @@ int main(int argc, char *argv[])
options.add("wipeTargetFolders", ki18n("Wipe and recreate target folders (Will only wipe folders in the personal namespace which are existing on the source server)."));
options.add("statefile", ki18n("Resume from migration-state file"), "/tmp/kolabmigration.state");
options.add("skipFolder <sourcefolder>", ki18n("Source-folders to skip. Uses a simple \"contains\"-filter."));
+ options.add("objectType <type>", ki18n("Objects types to migrate (MAIL, CONTACTS, EVENTS, TASKS). By default all types are migrated. Can be stated multiple times. Currently only implemented for the google source type."));
options.add("from <type>", ki18n("Source host type (kolab2, kolab3, exchangeimap, google)"));
@@ -217,6 +218,9 @@ int main(int argc, char *argv[])
if (!args->getOptionList("skipFolder").isEmpty()) {
sourceServer->setIgnoredFolders(args->getOptionList("skipFolder"));
}
+ if (!args->getOptionList("objectType").isEmpty()) {
+ sourceServer->setObjectTypesToMigrate(args->getOptionList("objectType"));
+ }
CoordinationJob *job = new CoordinationJob(sourceServer, kolabServer, &app);
QObject::connect(job, SIGNAL(finished(KJob*)), &app, SLOT(quit()));
job->start();
diff --git a/migrationutility/sourceserver.cpp b/migrationutility/sourceserver.cpp
index 47f60d1..e833f1a 100644
--- a/migrationutility/sourceserver.cpp
+++ b/migrationutility/sourceserver.cpp
@@ -103,6 +103,19 @@ QStringList SourceServer::ignoredFolders() const
return mIgnoredFolders;
}
+void SourceServer::setObjectTypesToMigrate(const QStringList &types)
+{
+ Debug() << "Migrating only types: " << types;
+ mObjectTypesToMigrate = types;
+}
+
+bool SourceServer::shouldMigrateType(const QString &type) const
+{
+ if (mObjectTypesToMigrate.isEmpty()) {
+ return true;
+ }
+ return mObjectTypesToMigrate.contains(type, Qt::CaseInsensitive);
+}
TestServer::TestServer(QObject* parent)
diff --git a/migrationutility/sourceserver.h b/migrationutility/sourceserver.h
index f3ab897..0ac6245 100644
--- a/migrationutility/sourceserver.h
+++ b/migrationutility/sourceserver.h
@@ -23,6 +23,7 @@
#include <qsharedpointer.h>
#include <QStringList>
#include "sourceaccount.h"
+#include <kolab/kolabdefinitions.h>
/**
* Job interface to retrieve users from a server.
@@ -72,6 +73,8 @@ public:
*/
void setIgnoredFolders(const QStringList &);
QStringList ignoredFolders() const;
+
+ void setObjectTypesToMigrate(const QStringList &);
protected:
virtual QList<SourceAccount*> getSourceAccountsImpl(const QString &user) = 0;
/**
@@ -79,10 +82,13 @@ protected:
* Note that the retrieved username is used to login to the users account on the source server.
*/
virtual UserListJob *retrieveUserList();
+
+ bool shouldMigrateType(const QString &type) const;
QStringList mExplicitUsers;
QString mStatefile;
private:
QStringList mIgnoredFolders;
+ QStringList mObjectTypesToMigrate;
};