+ try {
+ 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
+ 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)
+ })
+ } catch (err) {