mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
#2749 upgrade plugins:active to zset
This commit is contained in:
2
app.js
2
app.js
@@ -323,7 +323,7 @@ function resetThemes(callback) {
|
||||
|
||||
function resetPlugin(pluginId) {
|
||||
var db = require('./src/database');
|
||||
db.setRemove('plugins:active', pluginId, function(err) {
|
||||
db.sortedSetRemove('plugins:active', pluginId, function(err) {
|
||||
if (err) {
|
||||
winston.error('[reset] Could not disable plugin: %s encountered error %s', pluginId, err.message);
|
||||
} else {
|
||||
|
||||
@@ -426,7 +426,10 @@ function enableDefaultPlugins(next) {
|
||||
'nodebb-plugin-soundpack-default'
|
||||
];
|
||||
var db = require('./database');
|
||||
db.setAdd('plugins:active', defaultEnabled, next);
|
||||
var order = defaultEnabled.map(function(plugin, index) {
|
||||
return index;
|
||||
});
|
||||
db.sortedSetAdd('plugins:active', order, defaultEnabled, next);
|
||||
}
|
||||
|
||||
function setCopyrightWidget(next) {
|
||||
|
||||
@@ -92,13 +92,12 @@ var fs = require('fs'),
|
||||
Plugins.clientScripts.length = 0;
|
||||
Plugins.libraryPaths.length = 0;
|
||||
|
||||
// Read the list of activated plugins and require their libraries
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
db.getSetMembers('plugins:active', next);
|
||||
db.getSortedSetRange('plugins:active', 0, -1, next);
|
||||
},
|
||||
function(plugins, next) {
|
||||
if (!plugins || !Array.isArray(plugins)) {
|
||||
if (!Array.isArray(plugins)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,16 @@ module.exports = function(Plugins) {
|
||||
},
|
||||
function(_isActive, next) {
|
||||
isActive = _isActive;
|
||||
db[isActive ? 'setRemove' : 'setAdd']('plugins:active', id, next);
|
||||
if (isActive) {
|
||||
db.sortedSetRemove('plugins:active', id, next);
|
||||
} else {
|
||||
db.sortedSetCard('plugins:active', function(err, count) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
db.sortedSetAdd('plugins:active', count, id, next);
|
||||
});
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
meta.reloadRequired = true;
|
||||
@@ -119,6 +128,6 @@ module.exports = function(Plugins) {
|
||||
};
|
||||
|
||||
Plugins.isActive = function(id, callback) {
|
||||
db.isSetMember('plugins:active', id, callback);
|
||||
db.isSortedSetMember('plugins:active', id, callback);
|
||||
};
|
||||
};
|
||||
@@ -21,7 +21,7 @@ var db = require('./database'),
|
||||
schemaDate, thisSchemaDate,
|
||||
|
||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||
latestSchema = Date.UTC(2015, 1, 17);
|
||||
latestSchema = Date.UTC(2015, 1, 23);
|
||||
|
||||
Upgrade.check = function(callback) {
|
||||
db.get('schemaDate', function(err, value) {
|
||||
@@ -859,6 +859,43 @@ Upgrade.upgrade = function(callback) {
|
||||
winston.info('[2015/02/17] renaming home.tpl to categories.tpl skipped');
|
||||
next();
|
||||
}
|
||||
},
|
||||
function(next) {
|
||||
thisSchemaDate = Date.UTC(2015, 1, 23);
|
||||
if (schemaDate < thisSchemaDate) {
|
||||
updatesMade = true;
|
||||
winston.info('[2015/02/23] Upgrading plugins:active to sorted set');
|
||||
|
||||
db.getSetMembers('plugins:active', function(err, activePlugins) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (!Array.isArray(activePlugins) || !activePlugins.length) {
|
||||
winston.info('[2015/02/23] Upgrading plugins:active to sorted set done');
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
}
|
||||
|
||||
db.delete('plugins:active', function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
var order = -1;
|
||||
async.eachSeries(activePlugins, function(plugin, next) {
|
||||
++order;
|
||||
db.sortedSetAdd('plugins:active', order, plugin, next);
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
winston.info('[2015/02/23] Upgrading plugins:active to sorted set done');
|
||||
Upgrade.update(thisSchemaDate, next);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
winston.info('[2015/02/23] Upgrading plugins:active to sorted set skipped');
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
// Add new schema updates here
|
||||
|
||||
Reference in New Issue
Block a user