nodebb-plugin-import
Version:
Import your forum data to nodebb
99 lines (80 loc) • 3.08 kB
JavaScript
(function (module) {
const nbbRequire = require('nodebb-plugin-require');
const db = require('./database');
const async = require('async');
const extend = require('extend');
const Data = require('../helpers/data');
// nbb-core
const Groups = nbbRequire('src/groups');
Groups.import = function () {
throw new Error('not implemented');
};
Groups.batchImport = function (array, options, progressCallback, batchCallback) {
let index = 0;
options = extend(true, {}, options);
async.eachSeries(
array,
(record, next) => {
Groups.import(record, options, (err, data) => {
progressCallback(err, { data, index: ++index });
// ignore errors:
// let progressCallback throw an error or log a warning if it wants to.
next();
});
},
(err) => {
batchCallback(err);
},
);
};
Groups.setImported = function (_gid, gidOrGname, group, callback) {
return Data.setImported('_imported:_groups', '_imported_group:', _gid, gidOrGname, group, callback);
};
Groups.getImported = function (_gid, callback) {
return Data.getImported('_imported:_groups', '_imported_group:', _gid, callback);
};
Groups.deleteImported = function (_gid, callback) {
return Data.deleteImported('_imported:_groups', '_imported_group:', _gid, callback);
};
Groups.deleteEachImported = function (onProgress, callback) {
return Data.deleteEachImported('_imported:_groups', '_imported_group:', onProgress, callback);
};
Groups.isImported = function (_gid, callback) {
return Data.isImported('_imported:_groups', _gid, callback);
};
Groups.eachImported = function (iterator, options, callback) {
return Data.each('_imported:_groups', '_imported_group:', iterator, options, callback);
};
Groups.countImported = function (callback) {
Data.count('_imported:_groups', callback);
};
// [potential-nodebb-core]
Groups.count = function (callback) {
Data.count('groups:createtime', callback);
};
// [potential-nodebb-core]
Groups.each = function (iterator, options, callback) {
return Data.each('groups:createtime', 'group:', iterator, options, callback);
};
// [potential-nodebb-core]
Groups.processNamesSet = function (process, options, callback) {
return Data.processIdsSet('groups:createtime', process, options, callback);
};
// [potential-nodebb-core]
Groups.processSet = function (process, options, callback) {
return Data.processSet('groups:createtime', 'group:', process, options, callback);
};
// join with passed-in timestamp
// [potential-nodebb-core]
Groups.joinAt = function (name, uid, timestamp, callback) {
Groups.join(name, uid, (err, ret) => {
if (err) {
return callback(err);
}
// partially undo what Group.join by replacing the timestamp
// obviously if this was moved to core, we would re-write Group.join
db.sortedSetAdd(`group:${name}:members`, timestamp, uid, callback);
});
};
module.exports = Groups;
}(module));