diff options
-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={}) |