mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
30b4eb07f7
- This is a first pass at getting a more logical structure. The focus is on moving from admin/frontend to client/server. - The location of the databases is highly important, this isn't expected to change again In the future - client/assets should probably become public/ - more stuff should be shared (helpers etc) - cleanup some confusion around tpl and views
54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
var when = require("when"),
|
|
_ = require("underscore"),
|
|
knex = require('../../models/base').Knex,
|
|
Importer001;
|
|
|
|
Importer001 = function () {
|
|
_.bindAll(this, "importFrom001");
|
|
|
|
this.version = "001";
|
|
|
|
this.importFrom = {
|
|
"001": this.importFrom001
|
|
};
|
|
};
|
|
|
|
Importer001.prototype.importData = function (data) {
|
|
return this.canImport(data)
|
|
.then(function (importerFunc) {
|
|
return importerFunc(data);
|
|
}, function (reason) {
|
|
return when.reject(reason);
|
|
});
|
|
};
|
|
|
|
Importer001.prototype.canImport = function (data) {
|
|
if (data.meta && data.meta.version && this.importFrom[data.meta.version]) {
|
|
return when.resolve(this.importFrom[data.meta.version]);
|
|
}
|
|
|
|
return when.reject("Unsupported version of data");
|
|
};
|
|
|
|
Importer001.prototype.importFrom001 = function (data) {
|
|
var insertOps = [];
|
|
|
|
_.each(data.data, function (tableData, name) {
|
|
if (tableData && tableData.length) {
|
|
insertOps.push(knex(name).insert(tableData));
|
|
}
|
|
});
|
|
|
|
return when.all(insertOps).then(function (results) {
|
|
return when.resolve(results);
|
|
}, function (err) {
|
|
console.log("Error inserting imported data: ", err.message || err, err.stack);
|
|
});
|
|
};
|
|
|
|
module.exports = {
|
|
Importer001: Importer001,
|
|
importData: function (data) {
|
|
new Importer001().importData(data);
|
|
}
|
|
}; |