From: Julien Lancelot Date: Fri, 23 Nov 2012 09:24:14 +0000 (+0100) Subject: SONAR-3873 When deleting a manual metric all relating manual measures MUST be deleted X-Git-Tag: 3.4~293 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a82b5d0444d4db3ffc3f774cea7ff14ddc828dd7;p=sonarqube.git SONAR-3873 When deleting a manual metric all relating manual measures MUST be deleted --- diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb index 5d62418a77c..688d266a324 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb @@ -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 diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/metric.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/metric.rb index 82776685704..e36b21dabbf 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/metric.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/metric.rb @@ -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,