Fix custom embeds in user_playlists; add NEWS.md

Server administrators should check NEWS.md before updating for
information about important changes or required administrator
intervention.
This commit is contained in:
calzoneman 2015-07-06 12:29:40 -07:00
parent 83e3c44a6d
commit a6ddebbec3
4 changed files with 91 additions and 6 deletions

View file

@ -2,7 +2,7 @@ var db = require("../database");
var Logger = require("../logger");
var Q = require("q");
const DB_VERSION = 6;
const DB_VERSION = 7;
var hasUpdates = [];
module.exports.checkVersion = function () {
@ -56,6 +56,8 @@ function update(version, cb) {
fixUtf8mb4(cb);
} else if (version < 6) {
fixCustomEmbeds(cb);
} else if (version < 7) {
fixCustomEmbedsInUserPlaylists(cb);
}
}
@ -270,3 +272,61 @@ function fixCustomEmbeds(cb) {
});
});
}
function fixCustomEmbedsInUserPlaylists(cb) {
var CustomEmbedFilter = require("../customembed").filter;
Q.nfcall(db.query, "SELECT * FROM `user_playlists` WHERE `contents` LIKE '%\"type\":\"cu\"%'")
.then(function (rows) {
var all = [];
rows.forEach(function (row) {
var data;
try {
data = JSON.parse(row.contents);
} catch (e) {
return;
}
var updated = [];
var item;
while ((item = data.shift()) !== undefined) {
if (item.type !== "cu") {
updated.push(item);
continue;
}
if (/^cu:/.test(item.id)) {
updated.push(item);
continue;
}
var media;
try {
media = CustomEmbedFilter(item.id);
} catch (e) {
Logger.syslog.log("WARNING: Unable to convert " + item.id);
continue;
}
updated.push({
id: media.id,
title: item.title,
seconds: media.seconds,
type: media.type,
meta: {
embed: media.meta.embed
}
});
all.push(Q.nfcall(db.query, "UPDATE `user_playlists` SET `contents`=?, `count`=? WHERE `user`=? AND `name`=?",
[JSON.stringify(updated), updated.length, row.user, row.name]));
}
});
Q.allSettled(all).then(function () {
Logger.syslog.log('Fixed custom embeds in user_playlists');
cb();
});
}).catch(function (err) {
Logger.errlog.log(err.stack);
});
}