mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 17:46:16 +01:00
fix: don't move theme/plugin to top if its already active
This commit is contained in:
@@ -63,9 +63,19 @@ function activate(plugin) {
|
||||
if (!isInstalled) {
|
||||
return next(new Error('plugin not installed'));
|
||||
}
|
||||
plugins.isActive(plugin, next);
|
||||
},
|
||||
function (isActive, next) {
|
||||
if (isActive) {
|
||||
winston.info('Plugin `%s` already active', plugin);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
db.sortetSetCard('plugins:active', next);
|
||||
},
|
||||
function (numPlugins, next) {
|
||||
winston.info('Activating plugin `%s`', plugin);
|
||||
db.sortedSetAdd('plugins:active', 0, plugin, next);
|
||||
db.sortedSetAdd('plugins:active', numPlugins, plugin, next);
|
||||
},
|
||||
function (next) {
|
||||
events.log({
|
||||
|
||||
@@ -86,39 +86,37 @@ async function getThemes(themePath) {
|
||||
}
|
||||
|
||||
Themes.set = async (data) => {
|
||||
const themeData = {
|
||||
'theme:type': data.type,
|
||||
'theme:id': data.id,
|
||||
'theme:staticDir': '',
|
||||
'theme:templates': '',
|
||||
'theme:src': '',
|
||||
};
|
||||
|
||||
switch (data.type) {
|
||||
case 'local': {
|
||||
const current = await Meta.configs.get('theme:id');
|
||||
var config = await fsReadfile(path.join(nconf.get('themes_path'), data.id, 'theme.json'), 'utf8');
|
||||
config = JSON.parse(config);
|
||||
await db.sortedSetRemove('plugins:active', current);
|
||||
await db.sortedSetAdd('plugins:active', 0, data.id);
|
||||
if (current !== data.id) {
|
||||
let config = await fsReadfile(path.join(nconf.get('themes_path'), data.id, 'theme.json'), 'utf8');
|
||||
config = JSON.parse(config);
|
||||
|
||||
// Re-set the themes path (for when NodeBB is reloaded)
|
||||
Themes.setPath(config);
|
||||
await db.sortedSetRemove('plugins:active', current);
|
||||
const numPlugins = await db.sortedSetCard('plugins:active');
|
||||
await db.sortedSetAdd('plugins:active', numPlugins, data.id);
|
||||
// Re-set the themes path (for when NodeBB is reloaded)
|
||||
Themes.setPath(config);
|
||||
|
||||
themeData['theme:staticDir'] = config.staticDir ? config.staticDir : '';
|
||||
themeData['theme:templates'] = config.templates ? config.templates : '';
|
||||
themeData['theme:src'] = '';
|
||||
themeData.bootswatchSkin = '';
|
||||
await Meta.configs.setMultiple({
|
||||
'theme:type': data.type,
|
||||
'theme:id': data.id,
|
||||
'theme:staticDir': config.staticDir ? config.staticDir : '',
|
||||
'theme:templates': config.templates ? config.templates : '',
|
||||
'theme:src': '',
|
||||
bootswatchSkin: '',
|
||||
});
|
||||
|
||||
await Meta.configs.setMultiple(themeData);
|
||||
await events.log({
|
||||
type: 'theme-set',
|
||||
uid: parseInt(data.uid, 10) || 0,
|
||||
ip: data.ip || '127.0.0.1',
|
||||
text: data.id,
|
||||
});
|
||||
await events.log({
|
||||
type: 'theme-set',
|
||||
uid: parseInt(data.uid, 10) || 0,
|
||||
ip: data.ip || '127.0.0.1',
|
||||
text: data.id,
|
||||
});
|
||||
|
||||
Meta.reloadRequired = true;
|
||||
Meta.reloadRequired = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'bootswatch':
|
||||
|
||||
@@ -106,27 +106,18 @@ SocketAdmin.themes.getInstalled = function (socket, data, callback) {
|
||||
meta.themes.get(callback);
|
||||
};
|
||||
|
||||
SocketAdmin.themes.set = function (socket, data, callback) {
|
||||
SocketAdmin.themes.set = async function (socket, data) {
|
||||
if (!data) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
if (data.type === 'local') {
|
||||
await widgets.reset();
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
if (data.type === 'bootswatch') {
|
||||
setImmediate(next);
|
||||
} else {
|
||||
widgets.reset(next);
|
||||
}
|
||||
},
|
||||
function (next) {
|
||||
// Add uid and ip data
|
||||
data.ip = socket.ip;
|
||||
data.uid = socket.uid;
|
||||
data.ip = socket.ip;
|
||||
data.uid = socket.uid;
|
||||
|
||||
meta.themes.set(data, next);
|
||||
},
|
||||
], callback);
|
||||
await meta.themes.set(data);
|
||||
};
|
||||
|
||||
SocketAdmin.plugins.toggleActive = async function (socket, plugin_id) {
|
||||
|
||||
Reference in New Issue
Block a user