feat(MainDb): enable legacy history import

This commit is contained in:
Ronan Abhamon 2017-12-18 17:37:16 +01:00
parent c89611f47a
commit 2e0dd7907f
2 changed files with 14 additions and 4 deletions

View file

@ -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 *) {

View file

@ -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<soci::session>());
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<soci::row> messages = (inSession->prepare << "SELECT * FROM history");
try {
soci::transaction tr(*d->dbSession.getBackendSession<soci::session>());
for (const auto &message : messages) {
const int direction = message.get<int>(LEGACY_MESSAGE_COL_DIRECTION);
if (direction != 0 && direction != 1) {