clone project plow though null doc/file/folders

https://sentry.io/sharelatex-1/sl-web-server-prod/issues/227107799/
This commit is contained in:
Henry Oswald 2017-03-17 13:21:30 +00:00
parent d453a4d5c7
commit e5468983ce
2 changed files with 16 additions and 9 deletions

View file

@ -15,9 +15,11 @@ module.exports = ProjectDuplicator =
_copyDocs: (newProject, originalRootDoc, originalFolder, desFolder, docContents, callback)->
setRootDoc = _.once (doc_id)->
projectEntityHandler.setRootDoc newProject._id, doc_id
jobs = originalFolder.docs.map (doc)->
docs = originalFolder.docs or []
jobs = docs.map (doc)->
return (cb)->
if !doc?._id?
return callback()
content = docContents[doc._id.toString()]
projectEntityHandler.addDocWithProject newProject, desFolder._id, doc.name, content.lines, (err, newDoc)->
if err?
@ -30,7 +32,8 @@ module.exports = ProjectDuplicator =
async.series jobs, callback
_copyFiles: (newProject, originalProject_id, originalFolder, desFolder, callback)->
jobs = originalFolder.fileRefs.map (file)->
fileRefs = originalFolder.fileRefs or []
jobs = fileRefs.map (file)->
return (cb)->
projectEntityHandler.copyFileFromExistingProjectWithProject newProject, desFolder._id, originalProject_id, file, cb
async.parallelLimit jobs, 5, callback
@ -40,10 +43,14 @@ module.exports = ProjectDuplicator =
ProjectGetter.getProject newProject_id, {rootFolder:true, name:true}, (err, newProject)->
if err?
logger.err project_id:newProject_id, "could not get project"
return cb(err)
return callback(err)
jobs = originalFolder.folders.map (childFolder)->
folders = originalFolder.folders or []
jobs = folders.map (childFolder)->
return (cb)->
if !childFolder?._id?
return cb()
projectEntityHandler.addFolderWithProject newProject, desFolder?._id, childFolder.name, (err, newFolder)->
return cb(err) if err?
ProjectDuplicator._copyFolderRecursivly newProject_id, originalProject_id, originalRootDoc, childFolder, newFolder, docContents, cb

View file

@ -9,7 +9,7 @@ describe 'ProjectDuplicator', ->
@level2folder =
name: "level2folderName"
_id:"level2folderId"
docs:[@doc2 = {_id: "doc2_id", name:"level2folderDocName"}]
docs:[@doc2 = {_id: "doc2_id", name:"level2folderDocName"}, undefined]
folders:[]
fileRefs:[{name:"file2", _id:"file2"}]
@level1folder =
@ -17,12 +17,12 @@ describe 'ProjectDuplicator', ->
_id:"level1folderId"
docs:[@doc1 = {_id: "doc1_id", name:"level1folderDocName"}]
folders:[@level2folder]
fileRefs:[{name:"file1", _id:"file1"}]
fileRefs:[{name:"file1", _id:"file1"}, null]
@rootFolder =
name:"rootFolder"
_id:"rootFolderId"
docs:[@doc0 = {_id: "doc0_id", name:"rootDocHere"}]
folders:[@level1folder]
folders:[@level1folder, {}]
fileRefs:[{name:"file0", _id:"file0"}]
@project =
_id: @old_project_id = "this_is_the_old_project_id"
@ -117,7 +117,7 @@ describe 'ProjectDuplicator', ->
@projectOptionsHandler.setCompiler.calledWith(@stubbedNewProject._id, @project.compiler).should.equal true
done()
it 'should use the same root docccccccc', (done)->
it 'should use the same root doc', (done)->
@entityHandler.addDocWithProject.callsArgWith(4, null, @rootFolder.docs[0])
@duplicator.duplicate @owner, @old_project_id, "", (err, newProject)=>
@entityHandler.setRootDoc.calledWith(@stubbedNewProject._id, @rootFolder.docs[0]._id).should.equal true