Fixes #6259
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
parent
1b8ff1f6a2
commit
f6ad344ac6
@ -1,37 +1,45 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var db = require('../../database');
|
||||||
var meta = require('../../meta');
|
var meta = require('../../meta');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'Generate customHTML block from old customJS setting',
|
name: 'Generate customHTML block from old customJS setting',
|
||||||
timestamp: Date.UTC(2017, 9, 12),
|
timestamp: Date.UTC(2017, 9, 12),
|
||||||
method: function (callback) {
|
method: function (callback) {
|
||||||
var newHTML = meta.config.customJS;
|
db.getObjectField('config', 'customJS', function (err, newHTML) {
|
||||||
var newJS = [];
|
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...
|
while (match) {
|
||||||
var scriptMatch = /^<script\s?(?!async|deferred)?>([\s\S]+?)<\/script>/m;
|
if (match[1]) {
|
||||||
var match = scriptMatch.exec(newHTML);
|
// Append to newJS array
|
||||||
|
newJS.push(match[1].trim());
|
||||||
|
|
||||||
while (match) {
|
// Remove the match from the existing value
|
||||||
if (match[1]) {
|
newHTML = ((match.index > 0 ? newHTML.slice(0, match.index) : '') + newHTML.slice(match.index + match[0].length)).trim();
|
||||||
// Append to newJS array
|
}
|
||||||
newJS.push(match[1].trim());
|
|
||||||
|
|
||||||
// Remove the match from the existing value
|
match = scriptMatch.exec(newHTML);
|
||||||
newHTML = ((match.index > 0 ? newHTML.slice(0, match.index) : '') + newHTML.slice(match.index + match[0].length)).trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match = scriptMatch.exec(newHTML);
|
// Combine newJS array
|
||||||
}
|
newJS = newJS.join('\n\n');
|
||||||
|
|
||||||
// Combine newJS array
|
console.log('wut', newJS, 'and', newHTML);
|
||||||
newJS = newJS.join('\n\n');
|
|
||||||
|
|
||||||
// Write both values to config
|
// Write both values to config
|
||||||
meta.configs.setMultiple({
|
meta.configs.setMultiple({
|
||||||
customHTML: newHTML,
|
customHTML: newHTML,
|
||||||
customJS: newJS,
|
customJS: newJS,
|
||||||
}, callback);
|
}, callback);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue