]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2496 Clean the version from snapshots when deleting a version
authorFabrice Bellingard <bellingard@gmail.com>
Tue, 10 Jul 2012 10:02:31 +0000 (12:02 +0200)
committerFabrice Bellingard <bellingard@gmail.com>
Thu, 12 Jul 2012 08:33:31 +0000 (10:33 +0200)
=> when deleting a version event, the 'version' property of a
   snapshot should be set to the version of the following snapshot
   to have a consistent and clean history of 'version' properties.

sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb

index cf5af3ed82da52d59e22c6adc2a84dca42136be6..de19cb7b14fdc2d121cc855e0e7dc32739c74341 100644 (file)
@@ -342,7 +342,16 @@ class ProjectController < ApplicationController
     snapshot=Snapshot.find(params[:sid])
     not_found("Snapshot not found") unless snapshot
     access_denied unless is_admin?(snapshot)
+    
+    # We update all the related snapshots to have the same version as the next snapshot
+    next_snapshot = Snapshot.find(:first, :conditions => ['created_at>? and project_id=?', snapshot.created_at, snapshot.project_id], :order => 'created_at asc')
+    snapshots = find_project_snapshots(snapshot.id)
+    snapshots.each do |snapshot|
+      snapshot.version = next_snapshot.version
+      snapshot.save!
+    end
 
+    # and we delete the events
     event = snapshot.event(EventCategory::KEY_VERSION)
     old_version_name = event.name
     events = find_events(event)