2020-02-17 12:34:21 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
handle-callback-err,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
2020-02-17 12:34:04 -05:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-02-17 12:34:28 -05:00
|
|
|
let RestoreManager
|
|
|
|
const DocumentUpdaterManager = require('./DocumentUpdaterManager')
|
|
|
|
const DiffManager = require('./DiffManager')
|
|
|
|
const logger = require('logger-sharelatex')
|
2014-03-10 12:58:26 -04:00
|
|
|
|
2020-02-17 12:34:28 -05:00
|
|
|
module.exports = RestoreManager = {
|
|
|
|
restoreToBeforeVersion(project_id, doc_id, version, user_id, callback) {
|
|
|
|
if (callback == null) {
|
2020-06-04 04:24:21 -04:00
|
|
|
callback = function (error) {}
|
2020-02-17 12:34:28 -05:00
|
|
|
}
|
|
|
|
logger.log({ project_id, doc_id, version, user_id }, 'restoring document')
|
|
|
|
return DiffManager.getDocumentBeforeVersion(
|
|
|
|
project_id,
|
|
|
|
doc_id,
|
|
|
|
version,
|
2020-06-04 04:24:21 -04:00
|
|
|
function (error, content) {
|
2020-02-17 12:34:28 -05:00
|
|
|
if (error != null) {
|
|
|
|
return callback(error)
|
|
|
|
}
|
|
|
|
return DocumentUpdaterManager.setDocument(
|
|
|
|
project_id,
|
|
|
|
doc_id,
|
|
|
|
content,
|
|
|
|
user_id,
|
2020-06-04 04:24:21 -04:00
|
|
|
function (error) {
|
2020-02-17 12:34:28 -05:00
|
|
|
if (error != null) {
|
|
|
|
return callback(error)
|
|
|
|
}
|
|
|
|
return callback()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2021-07-13 07:04:43 -04:00
|
|
|
},
|
2020-02-17 12:34:28 -05:00
|
|
|
}
|