+
+ waterfall([
+
+ function startTransaction (callback) {
+ db.sequelize.transaction().asCallback(function (err, t) {
+ return callback(err, t)
+ })
+ },
+
+ function createAbuse (t, callback) {
+ db.VideoAbuse.create(abuse).asCallback(function (err, abuse) {
+ return callback(err, t, abuse)
+ })
+ },
+
+ function sendToFriendsIfNeeded (t, abuse, callback) {
+ // We send the information to the destination pod
+ if (videoInstance.isOwned() === false) {
+ const reportData = {
+ reporterUsername,
+ reportReason: abuse.reason,
+ videoRemoteId: videoInstance.remoteId
+ }
+
+ friends.reportAbuseVideoToFriend(reportData, videoInstance)
+ }
+
+ return callback(null, t)
+ }
+
+ ], function andFinally (err, t) {
+ if (err) {
+ logger.debug('Cannot update the video.', { error: err })
+
+ // Abort transaction?
+ if (t) t.rollback()
+
+ return finalCallback(err)
+ }
+
+ // Commit transaction
+ t.commit().asCallback(function (err) {
+ if (err) return finalCallback(err)
+
+ logger.info('Abuse report for video %s created.', videoInstance.name)
+ return finalCallback(null)
+ })
+ })