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

preserve existing history when user upgrades

Brian Gough 10 лет назад
Родитель
Сommit
fd49601716

+ 13 - 0
services/track-changes/app/coffee/MongoManager.coffee

@@ -64,6 +64,19 @@ module.exports = MongoManager =
 			upsert: true
 		}, callback
 
+	upgradeHistory: (project_id, callback = (error) ->) ->
+		# preserve the project's existing history
+		db.docHistory.update {
+			project_id: ObjectId(project_id)
+			temporary: true
+			expiresAt: {$exists: true}
+		}, {
+			$set: {temporary: false}
+			$unset: {expiresAt: ""}
+		}, {
+			multi: true
+		}, callback
+
 	ensureIndices: () ->
 		# For finding all updates that go into a diff for a doc
 		db.docHistory.ensureIndex { doc_id: 1, v: 1 }, { background: true }

+ 3 - 1
services/track-changes/app/coffee/UpdateTrimmer.coffee

@@ -15,7 +15,9 @@ module.exports = UpdateTrimmer =
 					if details?.features?.versioning
 						MongoManager.setProjectMetaData project_id, preserveHistory: true, (error) ->
 							return callback(error) if error?
-							callback null, false
+							MongoManager.upgradeHistory project_id, (error) ->
+								return callback(error) if error?
+								callback null, false
 					else
 						callback null, true
 

+ 11 - 0
services/track-changes/test/unit/coffee/UpdateTrimmer/UpdateTrimmerTests.coffee

@@ -29,6 +29,7 @@ describe "UpdateTrimmer", ->
 				features: {}
 			@MongoManager.getProjectMetaData = sinon.stub().callsArgWith(1, null, @metadata)
 			@MongoManager.setProjectMetaData = sinon.stub().callsArgWith(2)
+			@MongoManager.upgradeHistory = sinon.stub().callsArgWith(1)
 			@WebApiManager.getProjectDetails = sinon.stub().callsArgWith(1, null, @details)
 
 		describe "with preserveHistory set in the project meta data", ->
@@ -73,6 +74,11 @@ describe "UpdateTrimmer", ->
 						.calledWith(@project_id, {preserveHistory: true})
 						.should.equal true
 
+				it "should upgrade any existing history", ->
+					@MongoManager.upgradeHistory
+						.calledWith(@project_id)
+						.should.equal true
+
 				it "should return false", ->
 					@callback.calledWith(null, false).should.equal true
 
@@ -98,6 +104,11 @@ describe "UpdateTrimmer", ->
 						.calledWith(@project_id, {preserveHistory: true})
 						.should.equal true
 
+				it "should upgrade any existing history", ->
+					@MongoManager.upgradeHistory
+						.calledWith(@project_id)
+						.should.equal true
+
 				it "should return false", ->
 					@callback.calledWith(null, false).should.equal true