]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3873 When deleting a manual metric all relating manual measures MUST be deleted
authorJulien Lancelot <julien.lancelot@gmail.com>
Fri, 23 Nov 2012 09:24:14 +0000 (10:24 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Fri, 23 Nov 2012 09:24:14 +0000 (10:24 +0100)
sonar-server/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/metric.rb

index 5d62418a77cdf4b74758ebe64ffc97cfddbe9284..688d266a3245d801b0e5b898b1a62a3201247e24 100644 (file)
@@ -72,7 +72,7 @@ class MetricsController < ApplicationController
   def delete_from_web
     metric = Metric.by_id(params[:id].to_i) if params[:id] && params[:id].size > 0
     if metric
-      del_count = Metric.delete(params[:id].to_i)
+      del_count = Metric.delete_with_manual_measures(params[:id].to_i)
       flash[:notice] = 'Successfully deleted.' if del_count == 1
       flash[:error] = 'Unable to delete this metric.' if del_count != 1
       Metric.clear_cache
index 82776685704e3f5c4b7b04c2239bdcbfa0c7ef05..e36b21dabbfc944dae8fb67958d933b157110cb9 100644 (file)
@@ -246,6 +246,11 @@ class Metric < ActiveRecord::Base
     keys_array.collect{ |key| Metric.by_name(key).id if Metric.by_name(key) }
   end
 
+  def self.delete_with_manual_measures(id)
+    ManualMeasure.delete_all(["metric_id = ?", id])
+    self.delete(id)
+  end
+
   def to_hash_json(options={})
     return {'key' => name, 'name' => short_name, 'description' => description, 'domain' => domain,
       'qualitative' => qualitative, 'user_managed' => self.user_managed,