[epiphany/wip/sync: 17/18] profile-migrator: Migrate history to Firefox Sync history
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/sync: 17/18] profile-migrator: Migrate history to Firefox Sync history
- Date: Sat, 27 May 2017 20:10:02 +0000 (UTC)
commit 3ba58a3fa8b8d15a52e47d395678a9f476f10cb6
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Sat May 27 23:04:51 2017 +0300
profile-migrator: Migrate history to Firefox Sync history
lib/ephy-profile-utils.h | 2 +-
src/profile-migrator/ephy-profile-migrator.c | 81 ++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 1 deletions(-)
---
diff --git a/lib/ephy-profile-utils.h b/lib/ephy-profile-utils.h
index ac4841d..ae1ecc8 100644
--- a/lib/ephy-profile-utils.h
+++ b/lib/ephy-profile-utils.h
@@ -24,7 +24,7 @@
G_BEGIN_DECLS
-#define EPHY_PROFILE_MIGRATION_VERSION 18
+#define EPHY_PROFILE_MIGRATION_VERSION 19
#define EPHY_INSECURE_PASSWORDS_MIGRATION_VERSION 11
#define EPHY_SETTINGS_MIGRATION_VERSION 16
#define EPHY_FIREFOX_SYNC_PASSWORDS_MIGRATION_VERSION 18
diff --git a/src/profile-migrator/ephy-profile-migrator.c b/src/profile-migrator/ephy-profile-migrator.c
index 1a3780a..0ae1b93 100644
--- a/src/profile-migrator/ephy-profile-migrator.c
+++ b/src/profile-migrator/ephy-profile-migrator.c
@@ -1050,6 +1050,86 @@ out:
}
static void
+migrate_history_to_firefox_sync_history (void)
+{
+ EphySQLiteConnection *history_db = NULL;
+ EphySQLiteStatement *statement = NULL;
+ GSList *urls = NULL;
+ GError *error = NULL;
+ char *history_filename;
+ const char *sql_query;
+ int id;
+
+ history_filename = g_build_filename (ephy_dot_dir (), EPHY_HISTORY_FILE, NULL);
+ if (!g_file_test (history_filename, G_FILE_TEST_EXISTS)) {
+ LOG ("There is no history to migrate...");
+ goto out;
+ }
+
+ history_db = ephy_sqlite_connection_new (EPHY_SQLITE_CONNECTION_MODE_READWRITE);
+ ephy_sqlite_connection_open (history_db, history_filename, &error);
+ if (error) {
+ g_warning ("Failed to open history database: %s\n", error->message);
+ goto out;
+ }
+
+ /* Get the ID for each row in table. */
+ sql_query = "SELECT DISTINCT urls.id FROM urls ORDER BY urls.id";
+ statement = ephy_sqlite_connection_create_statement (history_db, sql_query, &error);
+ if (error) {
+ g_warning ("Failed to create SQLite statement: %s", error->message);
+ goto out;
+ }
+
+ while (ephy_sqlite_statement_step (statement, &error)) {
+ if (error) {
+ g_warning ("Error in ephy_sqlite_statement_step: %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ } else {
+ id = ephy_sqlite_statement_get_column_as_int (statement, 0);
+ urls = g_slist_prepend (urls, GINT_TO_POINTER (id));
+ }
+ }
+
+ /* Add new column for sync ID. */
+ sql_query = "ALTER TABLE urls ADD COLUMN sync_id LONGVARCAR";
+ ephy_sqlite_connection_execute (history_db, sql_query, &error);
+ if (error) {
+ g_warning ("Failed to add new column to urls table: %s", error->message);
+ goto out;
+ }
+
+ /* Set sync ID for each row. */
+ for (GSList *l = urls; l && l->data; l = l->next) {
+ char *sync_id = ephy_sync_crypto_get_random_sync_id ();
+ char *sql = g_strdup_printf ("UPDATE urls SET sync_id=\"%s\" WHERE id=%d",
+ sync_id, GPOINTER_TO_INT (l->data));
+
+ ephy_sqlite_connection_execute (history_db, sql, &error);
+ if (error) {
+ g_warning ("Failed to set sync ID: %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+
+ g_free (sync_id);
+ g_free (sql);
+ }
+
+out:
+ g_free (history_filename);
+ if (history_db)
+ g_object_unref (history_db);
+ if (statement)
+ g_object_unref (statement);
+ if (urls)
+ g_slist_free (urls);
+ if (error)
+ g_error_free (error);
+}
+
+static void
migrate_nothing (void)
{
/* Used to replace migrators that have been removed. Only remove migrators
@@ -1081,6 +1161,7 @@ const EphyProfileMigrator migrators[] = {
/* 16 */ migrate_settings,
/* 17 */ migrate_search_engines,
/* 18 */ migrate_passwords_to_firefox_sync_passwords,
+ /* 19 */ migrate_history_to_firefox_sync_history,
};
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]