fix project structure version when deleting folder

This commit is contained in:
Brian Gough
2018-05-08 13:37:33 +01:00
parent 24764f66ff
commit 1278e2da45
2 changed files with 43 additions and 24 deletions
@@ -405,14 +405,37 @@ module.exports = ProjectEntityUpdateHandler = self =
DocumentUpdaterHandler.resyncProjectHistory project_id, projectHistoryId, docs, files, callback
_cleanUpEntity: (project, entity, entityType, path, userId, callback = (error) ->) ->
self._updateProjectStructure project, entity, entityType, path, userId, (error) ->
return callback(error) if error?
if(entityType.indexOf("file") != -1)
self._cleanUpFile project, entity, path, userId, callback
else if (entityType.indexOf("doc") != -1)
self._cleanUpDoc project, entity, path, userId, callback
else if (entityType.indexOf("folder") != -1)
self._cleanUpFolder project, entity, path, userId, callback
else
callback()
_updateProjectStructure: (project, entity, entityType, entityPath, userId, callback = (error) ->) ->
# compute the changes to the project structure
if(entityType.indexOf("file") != -1)
self._cleanUpFile project, entity, path, userId, callback
changes = oldFiles: [ {file: entity, path: entityPath} ]
else if (entityType.indexOf("doc") != -1)
self._cleanUpDoc project, entity, path, userId, callback
changes = oldDocs: [ {doc: entity, path: entityPath} ]
else if (entityType.indexOf("folder") != -1)
self._cleanUpFolder project, entity, path, userId, callback
else
callback()
changes = {oldDocs: [], oldFiles: []}
_recurseFolder = (folder, folderPath) ->
for doc in folder.docs
changes.oldDocs.push {doc, path: path.join(folderPath, doc.name)}
for file in folder.fileRefs
changes.oldFiles.push {file, path: path.join(folderPath, file.name)}
for childFolder in folder.folders
_recurseFolder(childFolder, path.join(folderPath, childFolder.name))
_recurseFolder entity, entityPath
# now send the project structure changes to the docupdater
project_id = project._id.toString()
projectHistoryId = project.overleaf?.history?.id
DocumentUpdaterHandler.updateProjectStructure project_id, projectHistoryId, userId, changes, callback
_cleanUpDoc: (project, doc, path, userId, callback = (error) ->) ->
project_id = project._id.toString()
@@ -429,21 +452,10 @@ module.exports = ProjectEntityUpdateHandler = self =
return callback(error) if error?
DocumentUpdaterHandler.deleteDoc project_id, doc_id, (error) ->
return callback(error) if error?
DocstoreManager.deleteDoc project_id, doc_id, (error) ->
return callback(error) if error?
changes = oldDocs: [ {doc, path} ]
projectHistoryId = project.overleaf?.history?.id
DocumentUpdaterHandler.updateProjectStructure project_id, projectHistoryId, userId, changes, callback
DocstoreManager.deleteDoc project_id, doc_id, callback
_cleanUpFile: (project, file, path, userId, callback = (error) ->) ->
ProjectEntityMongoUpdateHandler._insertDeletedFileReference project._id, file, (error) ->
return callback(error) if error?
project_id = project._id.toString()
projectHistoryId = project.overleaf?.history?.id
changes = oldFiles: [ {file, path} ]
# we are now keeping a copy of every file versio so we no longer delete
# the file from the filestore
DocumentUpdaterHandler.updateProjectStructure project_id, projectHistoryId, userId, changes, callback
ProjectEntityMongoUpdateHandler._insertDeletedFileReference project._id, file, callback
_cleanUpFolder: (project, folder, folderPath, userId, callback = (error) ->) ->
jobs = []