diff options
author | Fabrice Bellingard <fabrice.bellingard@sonarsource.com> | 2013-02-18 12:33:43 +0100 |
---|---|---|
committer | Fabrice Bellingard <fabrice.bellingard@sonarsource.com> | 2013-02-18 14:59:58 +0100 |
commit | 83bf1ca64ef122141722342ef4d45493f1c0aab7 (patch) | |
tree | a29db3828f161e05d240c9f2ba373c8f6337c450 /sonar-server | |
parent | 7975f4777901956c93ca2f08606415840a682816 (diff) | |
download | sonarqube-83bf1ca64ef122141722342ef4d45493f1c0aab7.tar.gz sonarqube-83bf1ca64ef122141722342ef4d45493f1c0aab7.zip |
SONAR-4138 Do not delete manual metrics, just deactivate them
=> Deleting a manual metric should lead to deactivate the metric in
the Sonar DB and not to fully drop it
Diffstat (limited to 'sonar-server')
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/app/controllers/metrics_controller.rb | 17 | ||||
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/app/models/metric.rb | 8 |
2 files changed, 19 insertions, 6 deletions
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 f1aa452e304..80633a21687 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 @@ -36,10 +36,18 @@ class MetricsController < ApplicationController end def save_from_web + short_name = params[:metric][:short_name] + metric_name = short_name.downcase.gsub(/\s/, '_')[0..59] + if params[:id] metric = Metric.find(params[:id].to_i) else - metric = Metric.new + metric = Metric.find(:first, :conditions => ["name = ?", metric_name]) + if metric + reactivate_metric = true + else + metric = Metric.new + end end metric.attributes=params[:metric] @@ -55,7 +63,7 @@ class MetricsController < ApplicationController metric.origin = Metric::ORIGIN_GUI begin - new_rec = metric.new_record? + new_rec = metric.new_record? || reactivate_metric metric.save! Metric.clear_cache if new_rec @@ -72,9 +80,8 @@ 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_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.delete_with_manual_measures(params[:id].to_i) + flash[:notice] = 'Successfully deleted.' Metric.clear_cache end redirect_to :action => 'index' 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 a345b2204e7..0e54111c09a 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 @@ -254,7 +254,13 @@ class Metric < ActiveRecord::Base def self.delete_with_manual_measures(id) ManualMeasure.delete_all(["metric_id = ?", id]) - self.delete(id) + self.deactivate(id) + end + + def self.deactivate(id) + metric = by_id(id) + metric.enabled = false + metric.save! end def to_hash_json(options={}) |