0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00
ghost/core/shared/data/export/001.js
2013-06-15 20:52:32 +00:00

49 lines
No EOL
1.3 KiB
JavaScript

(function () {
"use strict";
var _ = require("underscore"),
when = require("when"),
knex = require('../../models/base').Knex,
Exporter001;
Exporter001 = function () {
this.version = "001";
};
Exporter001.prototype.exportData = function () {
var self = this,
tables = ['posts', 'users', 'roles', 'roles_users', 'permissions', 'permissions_roles', 'settings'],
selectOps = _.map(tables, function (name) {
return knex(name).select();
});
return when.all(selectOps).then(function (tableData) {
var exportData = {
meta: {
exported_on: new Date().getTime(),
version: self.version
},
data: {
// Filled below
}
};
_.each(tables, function (name, i) {
exportData.data[name] = tableData[i];
});
return when.resolve(exportData);
}, function (err) {
console.log("Error exporting data: " + err);
});
};
module.exports = {
// Make available for unit tests
Exporter001: Exporter001,
exportData: function () {
return new Exporter001().exportData();
}
};
}());