Commit c9847400 authored by Martin Kozub's avatar Martin Kozub

Important first-run fixes, app could not be initialized on first-run and...

Important first-run fixes, app could not be initialized on first-run and nobody (including me) noticed that :(
parent 67b5d1bd
......@@ -23,14 +23,14 @@ DBConnection.prototype.open = function() {
if(this.db) {
if(!this.db.version || Number(this.db.version) !== Number(this.version)) {
console.log("Changing DB version:", this.db.version, this.version);
this.enabled = true;
this.getAllData(function(data) {
this.getAllData(this.db, function(data) {
self.enabled = false;
self.dropTables();
self.createTables(function() {
self.db.changeVersion(self.db.version, self.version, function(tx) {
self.migrate(tx, oldData);
self.migrate(tx, data);
self.enabled = true;
self.runCallbacks();
});
......@@ -76,14 +76,18 @@ DBConnection.prototype.runCallbacks = function() {
/* Old data migration where applicable */
DBConnection.prototype.getAllData = function(db, callback) {
if(this.enabled && this.db) {
if(db) {
var data = {};
this.db.transaction(function(tx) {
db.transaction(function(tx) {
var settings = tx.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name='settings'");
var datajson = tx.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name='datajson'");
var stops = tx.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name='stops'");
var recent = tx.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name='recent'");
data = {
settings: tx.executeSql("SELECT * FROM settings"),
datajson: tx.executeSql("SELECT * FROM datajson"),
stops: tx.executeSql("SELECT * FROM stops"),
recent: tx.executeSql("SELECT * FROM recent")
settings: settings.rows.length ? tx.executeSql("SELECT * FROM settings") : null,
datajson: datajson.rows.length ? tx.executeSql("SELECT * FROM datajson") : null,
stops: stops.rows.length ? tx.executeSql("SELECT * FROM stops") : null,
recent: recent.rows.length ? tx.executeSql("SELECT * FROM recent") : null
};
callback && callback(data);
});
......@@ -95,28 +99,30 @@ DBConnection.prototype.getAllData = function(db, callback) {
/* Fill table with passed data */
DBConnection.prototype.fillTableWithData = function(tx, tableName, data) {
var errorOccured = false;
console.log("Migrating data to table", tableName);
for(var i = 0; i < data.rs.rows.length; i++) {
var itemData = data.rs.rows.item(i);
var keys = Object.keys(itemData);
var values = Object.values(itemData);
var lines = tx.executeSql("INSERT INTO " + tableName + " VALUES(" + keys.join(",") + ")", values.join(","));
if(lines <= 0) {
errorOccured = true;
console.log("Failed inserting old data into a new table", tableName, "on migration.", JSON.stringify(keys), JSON.stringify(values));
}
else {
console.log("Inserted old data into a new table", tableName, "on migration.", JSON.stringify(keys), JSON.stringify(values));
if(tx && tableName && data) {
console.log("Migrating data to table", tableName);
for(var i = 0; i < data.rs.rows.length; i++) {
var itemData = data.rs.rows.item(i);
var keys = Object.keys(itemData);
var values = Object.values(itemData);
var lines = tx.executeSql("INSERT INTO " + tableName + " VALUES(" + keys.join(",") + ")", values.join(","));
if(lines <= 0) {
errorOccured = true;
console.log("Failed inserting old data into a new table", tableName, "on migration.", JSON.stringify(keys), JSON.stringify(values));
}
else {
console.log("Inserted old data into a new table", tableName, "on migration.", JSON.stringify(keys), JSON.stringify(values));
}
}
}
return errorOccured;
}
/* Old data migration where applicable */
DBConnection.prototype.migrate = function(tx, data) {
DBConnection.prototype.migrate = function(tx, data) {
var databaseNames = Object.keys(data);
for(var i = 0; i < databaseNames.length; i++) {
fillTableWithData(tx, databaseNames[i], data[databaseNames[i]]);
this.fillTableWithData(tx, databaseNames[i], data[databaseNames[i]]);
}
}
......
......@@ -42,7 +42,7 @@ TransportOptions.prototype.refreshLocal = function() {
}
}
TransportOptions.prototype.fetchTrasports = function(forceServer, callback) {
TransportOptions.prototype.fetchTrasports = function(forceServer, callback) {
var transportOptions = null;
if(this.dbConnection) {
transportOptions = this.dbConnection.getDataJSON("transportOptions");
......@@ -69,9 +69,10 @@ TransportOptions.prototype.fetchTrasports = function(forceServer, callback) {
}
if(forceServer || checkServer) {
var self = this;
this.fetchDBTransports(transportOptions, function(obj, status) {
callback(obj, status);
this.fetchServerTransports(callback);
callback && callback(obj, status);
self.fetchServerTransports(callback);
});
}
else {
......@@ -111,7 +112,7 @@ TransportOptions.prototype.fetchDBTransports = function(transportOptions, callba
}
if(callback) {
callback(self);
callback(this);
}
}
......@@ -170,7 +171,6 @@ TransportOptions.prototype.parseAllTransports = function() {
this.saveNewConnectionInfo(workingID, newConnectionData);
}
}
return this;
}
......@@ -286,6 +286,9 @@ TransportOptions.prototype.getNearbyStopsOnline = function(coords, limit, callba
if(transport) {
return this.getSelectedTransport().getNearbyStopsOnline(coords, limit, callback);
}
else {
callback(false);
}
return false;
}
......
......@@ -9,7 +9,7 @@
"desktop": "Transport/Transport.desktop"
}
},
"version": "1.8.2",
"version": "1.8.3",
"maintainer": "Martin Kozub <zubozrout@gmail.com>",
"framework": "ubuntu-sdk-16.04"
}
......@@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-02-08 20:53+0000\n"
"POT-Creation-Date: 2019-02-22 15:43+0000\n"
"PO-Revision-Date: 2017-05-31 21:58+0000\n"
"Last-Translator: Martin Kozub <zubozrout@gmail.com>, 2019\n"
"Language-Team: Czech (https://www.transifex.com/zubozrout/teams/75311/cs/)\n"
......
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-02-08 20:53+0000\n"
"POT-Creation-Date: 2019-02-22 15:43+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment