Просмотр исходного кода

Don't error if the rootDoc_id no longer exists in the project when copying

James Allen 10 лет назад
Родитель
Сommit
887631e661

+ 1 - 1
services/web/app/coffee/Features/Project/ProjectDuplicator.coffee

@@ -75,7 +75,7 @@ module.exports = ProjectDuplicator =
 				return callback(err)
 				return callback(err)
 			{originalProject, newProject, originalRootDoc, docContentsArray} = results
 			{originalProject, newProject, originalRootDoc, docContentsArray} = results
 
 
-			originalRootDoc = originalRootDoc[0]
+			originalRootDoc = originalRootDoc?[0]
 
 
 			docContents = {}
 			docContents = {}
 			for docContent in docContentsArray
 			for docContent in docContentsArray

+ 7 - 1
services/web/app/coffee/Features/Project/ProjectLocator.coffee

@@ -61,7 +61,13 @@ module.exports = ProjectLocator =
 	findRootDoc : (opts, callback)->
 	findRootDoc : (opts, callback)->
 		getRootDoc = (project)=>
 		getRootDoc = (project)=>
 			if project.rootDoc_id?
 			if project.rootDoc_id?
-				@findElement {project:project, element_id:project.rootDoc_id, type:"docs"}, callback
+				@findElement {project:project, element_id:project.rootDoc_id, type:"docs"}, (error, args...) ->
+					if error?
+						if error instanceof Errors.NotFoundError
+							return callback null, null
+						else
+							return callback error
+					return callback null, args...
 			else
 			else
 				callback null, null
 				callback null, null
 		{project, project_id} = opts
 		{project, project_id} = opts

+ 7 - 0
services/web/test/UnitTests/coffee/Project/ProjectLocatorTests.coffee

@@ -169,6 +169,13 @@ describe 'ProjectLocator', ->
 				assert !err?
 				assert !err?
 				expect(doc).to.equal null
 				expect(doc).to.equal null
 				done()
 				done()
+		
+		it 'should return null when the rootDoc_id no longer exists', (done) ->
+			project.rootDoc_id = "doesntexist"
+			@locator.findRootDoc project, (err, doc)->
+				assert !err?
+				expect(doc).to.equal null
+				done()
 
 
 	describe 'findElementByPath', ->
 	describe 'findElementByPath', ->