Fixed issue that would cause the upgrade script to completely
wipe your customJS. This was caused by meta.config not being
populated during upgrade scripts (but only when run with
./nodebb upgrade... odd.)
v1.18.x
Julian Lam 7 years ago
parent 1b8ff1f6a2
commit f6ad344ac6

@ -1,37 +1,45 @@
'use strict';
var db = require('../../database');
var meta = require('../../meta');
module.exports = {
name: 'Generate customHTML block from old customJS setting',
timestamp: Date.UTC(2017, 9, 12),
method: function (callback) {
var newHTML = meta.config.customJS;
var newJS = [];
db.getObjectField('config', 'customJS', function (err, newHTML) {
if (err) {
return callback(err);
}
var newJS = [];
// Forgive me for parsing HTML with regex...
var scriptMatch = /^<script\s?(?!async|deferred)?>([\s\S]+?)<\/script>/m;
var match = scriptMatch.exec(newHTML);
// Forgive me for parsing HTML with regex...
var scriptMatch = /^<script\s?(?!async|deferred)?>([\s\S]+?)<\/script>/m;
var match = scriptMatch.exec(newHTML);
while (match) {
if (match[1]) {
// Append to newJS array
newJS.push(match[1].trim());
while (match) {
if (match[1]) {
// Append to newJS array
newJS.push(match[1].trim());
// Remove the match from the existing value
newHTML = ((match.index > 0 ? newHTML.slice(0, match.index) : '') + newHTML.slice(match.index + match[0].length)).trim();
}
// Remove the match from the existing value
newHTML = ((match.index > 0 ? newHTML.slice(0, match.index) : '') + newHTML.slice(match.index + match[0].length)).trim();
match = scriptMatch.exec(newHTML);
}
match = scriptMatch.exec(newHTML);
}
// Combine newJS array
newJS = newJS.join('\n\n');
// Combine newJS array
newJS = newJS.join('\n\n');
console.log('wut', newJS, 'and', newHTML);
// Write both values to config
meta.configs.setMultiple({
customHTML: newHTML,
customJS: newJS,
}, callback);
// Write both values to config
meta.configs.setMultiple({
customHTML: newHTML,
customJS: newJS,
}, callback);
});
},
};

Loading…
Cancel
Save