@HasMany(() => VideoAbuseModel, {
foreignKey: {
name: 'videoId',
- allowNull: false
+ allowNull: true
},
- onDelete: 'cascade'
+ onDelete: 'set null'
})
VideoAbuses: VideoAbuseModel[]
ModelCache.Instance.invalidateCache('video', instance.id)
}
+ @BeforeDestroy
+ static async saveEssentialDataToAbuses (instance: VideoModel, options) {
+ const tasks: Promise<any>[] = []
+
+ logger.info('Saving video abuses details of video %s.', instance.url)
+
+ if (!Array.isArray(instance.VideoAbuses)) {
+ instance.VideoAbuses = await instance.$get('VideoAbuses')
+
+ if (instance.VideoAbuses.length === 0) return undefined
+ }
+
+ const details = instance.toFormattedDetailsJSON()
+
+ for (const abuse of instance.VideoAbuses) {
+ abuse.deletedVideo = details
+ tasks.push(abuse.save({ transaction: options.transaction }))
+ }
+
+ Promise.all(tasks)
+ .catch(err => {
+ logger.error('Some errors when saving details of video %s in its abuses before destroy hook.', instance.uuid, { err })
+ })
+
+ return undefined
+ }
+
static listLocal (): Bluebird<MVideoWithAllFiles[]> {
const query = {
where: {