+ waterfall([
+
+ function startTransaction (callback) {
+ db.sequelize.transaction().asCallback(function (err, t) {
+ return callback(err, t)
+ })
+ },
+
+ function findVideo (t, callback) {
+ db.Video.loadByHostAndRemoteId(fromPod.host, videoAttributesToUpdate.remoteId, function (err, videoInstance) {
+ if (err || !videoInstance) {
+ logger.error('Cannot load video from host and remote id.', { error: err.message })
+ return callback(err)
+ }
+
+ return callback(null, t, videoInstance)
+ })
+ },
+
+ function findOrCreateTags (t, videoInstance, callback) {
+ const tags = videoAttributesToUpdate.tags
+
+ db.Tag.findOrCreateTags(tags, t, function (err, tagInstances) {
+ return callback(err, t, videoInstance, tagInstances)
+ })
+ },
+
+ function updateVideoIntoDB (t, videoInstance, tagInstances, callback) {
+ const options = { transaction: t }
+
+ videoInstance.set('name', videoAttributesToUpdate.name)
+ videoInstance.set('description', videoAttributesToUpdate.description)
+ videoInstance.set('infoHash', videoAttributesToUpdate.infoHash)
+ videoInstance.set('duration', videoAttributesToUpdate.duration)
+ videoInstance.set('createdAt', videoAttributesToUpdate.createdAt)
+ videoInstance.set('updatedAt', videoAttributesToUpdate.updatedAt)
+ videoInstance.set('extname', videoAttributesToUpdate.extname)
+
+ videoInstance.save(options).asCallback(function (err) {
+ return callback(err, t, videoInstance, tagInstances)
+ })
+ },
+
+ function associateTagsToVideo (t, videoInstance, tagInstances, callback) {
+ const options = { transaction: t }
+
+ videoInstance.setTags(tagInstances, options).asCallback(function (err) {
+ return callback(err, t)
+ })