- if (videoInfosToUpdate.name !== undefined) videoInstance.set('name', videoInfosToUpdate.name)
- if (videoInfosToUpdate.category !== undefined) videoInstance.set('category', videoInfosToUpdate.category)
- if (videoInfosToUpdate.licence !== undefined) videoInstance.set('licence', videoInfosToUpdate.licence)
- if (videoInfosToUpdate.language !== undefined) videoInstance.set('language', videoInfosToUpdate.language)
- if (videoInfosToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfosToUpdate.nsfw)
- if (videoInfosToUpdate.description !== undefined) videoInstance.set('description', videoInfosToUpdate.description)
-
- return videoInstance.save(options).then(() => tagInstances)
- })
- .then(tagInstances => {
- if (!tagInstances) return
-
- const options = { transaction: t }
- return videoInstance.setTags(tagInstances, options)
- .then(() => {
- videoInstance.Tags = tagInstances
-
- return
- })
- })
- .then(() => {
- const json = videoInstance.toUpdateRemoteJSON()
-
- // Now we'll update the video's meta data to our friends
- return updateVideoToFriends(json, t)
- })
- })
- .then(() => {
- logger.info('Video with name %s updated.', videoInstance.name)
- })
- .catch(err => {
- logger.debug('Cannot update the video.', err)
+ try {
+ const videoInstanceUpdated = await sequelizeTypescript.transaction(async t => {
+ const sequelizeOptions = { transaction: t }
+ const oldVideoChannel = videoInstance.VideoChannel
+
+ if (videoInfoToUpdate.name !== undefined) videoInstance.set('name', videoInfoToUpdate.name)
+ if (videoInfoToUpdate.category !== undefined) videoInstance.set('category', videoInfoToUpdate.category)
+ if (videoInfoToUpdate.licence !== undefined) videoInstance.set('licence', videoInfoToUpdate.licence)
+ if (videoInfoToUpdate.language !== undefined) videoInstance.set('language', videoInfoToUpdate.language)
+ if (videoInfoToUpdate.nsfw !== undefined) videoInstance.set('nsfw', videoInfoToUpdate.nsfw)
+ if (videoInfoToUpdate.waitTranscoding !== undefined) videoInstance.set('waitTranscoding', videoInfoToUpdate.waitTranscoding)
+ if (videoInfoToUpdate.support !== undefined) videoInstance.set('support', videoInfoToUpdate.support)
+ if (videoInfoToUpdate.description !== undefined) videoInstance.set('description', videoInfoToUpdate.description)
+ if (videoInfoToUpdate.commentsEnabled !== undefined) videoInstance.set('commentsEnabled', videoInfoToUpdate.commentsEnabled)
+ if (videoInfoToUpdate.privacy !== undefined) {
+ const newPrivacy = parseInt(videoInfoToUpdate.privacy.toString(), 10)
+ videoInstance.set('privacy', newPrivacy)
+
+ if (wasPrivateVideo === true && newPrivacy !== VideoPrivacy.PRIVATE) {
+ videoInstance.set('publishedAt', new Date())
+ }
+ }
+
+ const videoInstanceUpdated = await videoInstance.save(sequelizeOptions)
+
+ // Video tags update?
+ if (videoInfoToUpdate.tags !== undefined) {
+ const tagInstances = await TagModel.findOrCreateTags(videoInfoToUpdate.tags, t)
+
+ await videoInstanceUpdated.$set('Tags', tagInstances, sequelizeOptions)
+ videoInstanceUpdated.Tags = tagInstances
+ }
+
+ // Video channel update?
+ if (res.locals.videoChannel && videoInstanceUpdated.channelId !== res.locals.videoChannel.id) {
+ await videoInstanceUpdated.$set('VideoChannel', res.locals.videoChannel, { transaction: t })
+ videoInstanceUpdated.VideoChannel = res.locals.videoChannel
+
+ if (wasPrivateVideo === false) await changeVideoChannelShare(videoInstanceUpdated, oldVideoChannel, t)
+ }
+
+ // Schedule an update in the future?
+ if (videoInfoToUpdate.scheduleUpdate) {
+ await ScheduleVideoUpdateModel.upsert({
+ videoId: videoInstanceUpdated.id,
+ updateAt: videoInfoToUpdate.scheduleUpdate.updateAt,
+ privacy: videoInfoToUpdate.scheduleUpdate.privacy || null
+ }, { transaction: t })
+ } else if (videoInfoToUpdate.scheduleUpdate === null) {
+ await ScheduleVideoUpdateModel.deleteByVideoId(videoInstanceUpdated.id, t)
+ }
+
+ const isNewVideo = wasPrivateVideo && videoInstanceUpdated.privacy !== VideoPrivacy.PRIVATE
+
+ // Don't send update if the video was unfederated
+ if (!videoInstanceUpdated.VideoBlacklist || videoInstanceUpdated.VideoBlacklist.unfederated === false) {
+ await federateVideoIfNeeded(videoInstanceUpdated, isNewVideo, t)
+ }
+
+ auditLogger.update(
+ getAuditIdFromRes(res),
+ new VideoAuditView(videoInstanceUpdated.toFormattedDetailsJSON()),
+ oldVideoAuditView
+ )
+ logger.info('Video with name %s and uuid %s updated.', videoInstance.name, videoInstance.uuid)
+
+ return videoInstanceUpdated
+ })