File indexing completed on 2025-01-05 04:46:51
0001 /* 0002 SPDX-FileCopyrightText: 2024 g10 Code GmbH 0003 SPDX-FileContributor: Daniel Vrátil <dvratil@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QObject> 0011 0012 #include <functional> 0013 #include <memory> 0014 #include <system_error> 0015 #include <variant> 0016 0017 class QThread; 0018 0019 namespace Akonadi::Server 0020 { 0021 0022 class DbConfig; 0023 class TableDescription; 0024 class DataStore; 0025 0026 class UIDelegate 0027 { 0028 public: 0029 enum class Result { 0030 Yes, 0031 No, 0032 Skip, 0033 }; 0034 0035 virtual ~UIDelegate() = default; 0036 virtual Result questionYesNo(const QString &question) = 0; 0037 virtual Result questionYesNoSkip(const QString &question) = 0; 0038 }; 0039 0040 class DbMigrator : public QObject 0041 { 0042 Q_OBJECT 0043 public: 0044 explicit DbMigrator(const QString &targetEngine, UIDelegate *delegate, QObject *parent = nullptr); 0045 ~DbMigrator() override; 0046 0047 void startMigration(); 0048 0049 Q_SIGNALS: 0050 void info(const QString &message); 0051 void error(const QString &message); 0052 void progress(const QString &message, int tablesDone, int tablesTotal); 0053 void tableProgress(const QString &table, int rowsDone, int rowsTotal); 0054 0055 void migrationCompleted(bool success); 0056 0057 private: 0058 bool runMigrationThread(); 0059 bool copyTable(DataStore *sourceStore, DataStore *destStore, const TableDescription &table); 0060 0061 bool migrateTables(DataStore *sourceStore, DataStore *destStore, DbConfig *destConfig); 0062 bool moveDatabaseToMainLocation(DbConfig *destConfig, const QString &destServerCfgFile); 0063 std::optional<QString> moveDatabaseToBackupLocation(DbConfig *config); 0064 std::optional<QString> backupAkonadiServerRc(); 0065 bool runStorageJanitor(DbConfig *sourceConfig); 0066 0067 void emitInfo(const QString &message); 0068 void emitError(const QString &message); 0069 void emitProgress(const QString &message, int tablesDone, int tablesTotal); 0070 void emitTableProgress(const QString &table, int done, int total); 0071 void emitCompletion(bool success); 0072 UIDelegate::Result questionYesNo(const QString &question); 0073 UIDelegate::Result questionYesNoSkip(const QString &question); 0074 0075 QString m_targetEngine; 0076 std::unique_ptr<QThread> m_thread; 0077 UIDelegate *m_uiDelegate = nullptr; 0078 }; 0079 0080 } // namespace Akonadi::Server