From 2e0dd7907fa9e2f845cbd86c247f8e68a1ecfb67 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Mon, 18 Dec 2017 17:37:16 +0100 Subject: [PATCH] feat(MainDb): enable legacy history import --- coreapi/linphonecore.c | 8 ++++++-- src/db/main-db.cpp | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 8fcbef6ac..183e7b892 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -6689,8 +6689,12 @@ int linphone_core_get_video_dscp(const LinphoneCore *lc){ return lp_config_get_int(lc->config,"rtp","video_dscp",0); } -void linphone_core_set_chat_database_path (LinphoneCore *, const char *) { - lError() << "Do not use `linphone_core_set_chat_database_path`. Not necessary."; +void linphone_core_set_chat_database_path (LinphoneCore *lc, const char *path) { + if ( + linphone_core_conference_server_enabled(lc) || + !L_GET_PRIVATE(lc->cppPtr)->mainDb->import(LinphonePrivate::MainDb::Sqlite3, path) + ) + lError() << "Do not use `linphone_core_set_chat_database_path`. Not necessary."; } const char *linphone_core_get_chat_database_path (const LinphoneCore *) { diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index c1bfe4fe4..c2f3e96ba 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -42,6 +42,7 @@ #include "main-db-p.h" #define DB_MODULE_VERSION_EVENTS L_VERSION(1, 0, 0) +#define DB_MODULE_VERSION_LEGACY_HISTORY_IMPORT L_VERSION(1, 0, 0) // ============================================================================= @@ -2242,10 +2243,15 @@ static constexpr string &blobToString (string &in) { // Import messages. try { + soci::transaction tr(*d->dbSession.getBackendSession()); + + unsigned int version = d->getModuleVersion("legacy-history-import"); + if (version >= L_VERSION(1, 0, 0)) + return false; + d->updateModuleVersion("legacy-history-import", DB_MODULE_VERSION_LEGACY_HISTORY_IMPORT); + soci::rowset messages = (inSession->prepare << "SELECT * FROM history"); try { - soci::transaction tr(*d->dbSession.getBackendSession()); - for (const auto &message : messages) { const int direction = message.get(LEGACY_MESSAGE_COL_DIRECTION); if (direction != 0 && direction != 1) {