From 7f4e7c36373217b8e92cf227c71999a0ce9a15d9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 12 Jan 2017 09:47:21 +0100 Subject: Server: fix update remote video infohash --- server/controllers/api/videos.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'server/controllers/api') diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js index 55d671f5b..2c4af520e 100644 --- a/server/controllers/api/videos.js +++ b/server/controllers/api/videos.js @@ -259,6 +259,7 @@ function updateVideoRetryWrapper (req, res, next) { function updateVideo (req, res, finalCallback) { const videoInstance = res.locals.video + const videoFieldsSave = videoInstance.toJSON() const videoInfosToUpdate = req.body waterfall([ @@ -280,12 +281,13 @@ function updateVideo (req, res, finalCallback) { }, function updateVideoIntoDB (t, tagInstances, callback) { - const options = { transaction: t } + const options = { + transaction: t + } if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name) if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description) - // Add tags association videoInstance.save(options).asCallback(function (err) { return callback(err, t, tagInstances) }) @@ -321,6 +323,14 @@ function updateVideo (req, res, finalCallback) { // Abort transaction? if (t) t.rollback() + // Force fields we want to update + // If the transaction is retried, sequelize will think the object has not changed + // So it will skip the SQL request, even if the last one was ROLLBACKed! + Object.keys(videoFieldsSave).forEach(function (key) { + const value = videoFieldsSave[key] + videoInstance.set(key, value) + }) + return finalCallback(err) } -- cgit v1.2.3