diff options
author | David Gageot <david@gageot.net> | 2012-09-21 11:31:49 +0200 |
---|---|---|
committer | David Gageot <david@gageot.net> | 2012-09-21 12:17:57 +0200 |
commit | 2b7540abc629bdb71430a454da36552d3cc0cf13 (patch) | |
tree | 298797b51e6be060b6895c1e4335ce67cb35d816 | |
parent | dae6f20d214fc46b16bd82c16f7ba9bd928dcb73 (diff) | |
download | sonarqube-2b7540abc629bdb71430a454da36552d3cc0cf13.tar.gz sonarqube-2b7540abc629bdb71430a454da36552d3cc0cf13.zip |
SONAR-3754 Fix property change notification
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb | 3 | ||||
-rw-r--r-- | sonar-server/src/main/webapp/WEB-INF/app/models/property.rb | 39 |
2 files changed, 26 insertions, 16 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb index 69206f8d16a..d0d1791bf3f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/settings_controller.rb @@ -42,6 +42,9 @@ class SettingsController < ApplicationController @updated_properties = {} @definitions.map(&:key).each do |key| value = params[key] + if value.kind_of? Array + value = value.reverse.drop_while(&:blank?).reverse + end if value.blank? Property.clear(key, resource_id) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb index 483a3f6628e..71481f44ba0 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/property.rb @@ -39,8 +39,11 @@ class Property < ActiveRecord::Base end def self.clear(key, resource_id=nil, user_id=nil) - all(key, resource_id, user_id).delete_all - Java::OrgSonarServerUi::JRubyFacade.getInstance().setGlobalProperty(key, nil) unless resource_id + prop = by_key(key, resource_id, user_id) + if prop + all(key, resource_id, user_id).delete_all + Java::OrgSonarServerUi::JRubyFacade.getInstance().setGlobalProperty(key, nil) unless resource_id + end end def self.by_key(key, resource_id=nil, user_id=nil) @@ -68,25 +71,29 @@ class Property < ActiveRecord::Base definition = Java::OrgSonarServerUi::JRubyFacade.getInstance().propertyDefinitions.get(key) if definition && definition.multi_values if value.kind_of? Array - values = value.map { |v| v.gsub(',', '%2C') } - values = values.reverse.drop_while(&:blank?).reverse - value = values.join(',') - end - else - if value.kind_of? Array - value = value.first + value = value.map { |v| v.gsub(',', '%2C') }.join(',') end + elsif value.kind_of? Array + value = value.first end - text_value = (value.nil? ? nil : value.to_s) - prop = Property.new(:prop_key => key, :text_value => text_value, :resource_id => resource_id, :user_id => user_id) - if prop.valid? - Property.transaction do - Property.delete_all(:prop_key => key, :resource_id => resource_id, :user_id => user_id) - prop.save + text_value = (value.blank? ? nil : value.to_s) + + prop = by_key(key, resource_id, user_id) + if prop + if prop.text_value != text_value + prop.text_value = text_value + if prop.save + Java::OrgSonarServerUi::JRubyFacade.getInstance().setGlobalProperty(key, text_value) unless resource_id + end + end + else + prop = Property.new(:prop_key => key, :text_value => text_value, :resource_id => resource_id, :user_id => user_id) + if prop.save + Java::OrgSonarServerUi::JRubyFacade.getInstance().setGlobalProperty(key, text_value) unless resource_id end - Java::OrgSonarServerUi::JRubyFacade.getInstance().setGlobalProperty(key, text_value) unless resource_id end + prop end |