From 387339db449c4f1984e0af1fe8d14ee9d9479db5 Mon Sep 17 00:00:00 2001 From: Volker Krause Date: Fri, 15 Jan 2010 15:19:02 +0000 Subject: [PATCH] Run the migrator if needed. svn path=/branches/work/akonadi-ports/kdepim/; revision=1075120 --- kmkernel.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/kmkernel.cpp b/kmkernel.cpp index 27a3c79d9..89badac1a 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -60,6 +60,7 @@ using KMail::TemplateParser; #include #include #include +#include #include #include @@ -109,6 +110,37 @@ KMKernel::KMKernel (QObject *parent, const char *name) : mIdentityManager(0), mConfigureDialog(0), mMailService(0), mContextMenuShown( false ) { + // Akonadi migration + KConfig config( "kmail-migratorrc" ); + KConfigGroup migrationCfg( &config, "Migration" ); + const bool enabled = migrationCfg.readEntry( "Enabled", false ); + const int currentVersion = migrationCfg.readEntry( "Version", 0 ); + const int targetVersion = migrationCfg.readEntry( "TargetVersion", 1 ); + if ( enabled && currentVersion < targetVersion ) { + kDebug() << "Performing Akonadi migration. Good luck!"; + KProcess proc; + QStringList args = QStringList() << "--interactive-on-change"; + proc.setProgram( "kmail-migrator", args ); + proc.start(); + bool result = proc.waitForStarted(); + if ( result ) { + result = proc.waitForFinished(); + } + if ( result && proc.exitCode() == 0 ) { + kDebug() << "Akonadi migration has been successful"; + migrationCfg.writeEntry( "Version", targetVersion ); + migrationCfg.sync(); + } else { + // exit code 1 means it is already running, so we are probably called by a migrator instance + kError() << "Akonadi migration failed!"; + kError() << "command was: " << proc.program(); + kError() << "exit code: " << proc.exitCode(); + kError() << "stdout: " << proc.readAllStandardOutput(); + kError() << "stderr: " << proc.readAllStandardError(); + exit( 42 ); + } + } + #ifdef __GNUC__ #warning Remove before the 4.5 release #endif