From: Simon Brandhof Date: Fri, 28 Sep 2012 14:47:05 +0000 (+0200) Subject: SONAR-2602 Fix compatibility with Oracle X-Git-Tag: 3.3~174 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=358e30eaf1fb461650dd8f9ce26f9e4dc92bf0e2;p=sonarqube.git SONAR-2602 Fix compatibility with Oracle --- diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb index a9bb3d3a20e..397f70a7926 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/profile.rb @@ -23,9 +23,6 @@ class Profile < ActiveRecord::Base has_many :alerts, :dependent => :delete_all has_many :active_rules, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :dependent => :destroy, :include => ['rule'] has_many :active_rules_with_params, :class_name => 'ActiveRule', :foreign_key => 'profile_id', :include => ['active_rule_parameters', 'active_rule_note'] - has_many :projects, :class_name => 'Project', :finder_sql => %q( - select prj.* from projects prj, properties prop where prj.id=prop.resource_id and prop.resource_id is not null and prop.prop_key='sonar.profile.#{language}' and prop.text_value='#{name}' - ) has_many :changes, :class_name => 'ActiveRuleChange', :dependent => :destroy has_many :children, :class_name => 'Profile', :finder_sql => %q( select c.* from rules_profiles c where c.parent_name='#{name}' and c.language='#{language}' @@ -183,12 +180,30 @@ class Profile < ActiveRecord::Base self end + def projects? + !projects.empty? + end + + def projects + @projects ||= + begin + Project.find(:all, + :conditions => ['id in (select prop.resource_id from properties prop where prop.resource_id is not null and prop.prop_key=? and prop.text_value=?)', "sonar.profile.#{language}", name]) + end + end + + def sorted_projects + Api::Utils.insensitive_sort(projects){|p| p.name} + end + def add_project_id(project_id) Property.set("sonar.profile.#{language}", name, project_id) + @projects = nil end def remove_projects Property.clear_for_resources("sonar.profile.#{language}", name) + @projects = nil end def self.reset_default_profile_for_project_id(lang, project_id) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/projects.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/projects.html.erb index df77976eb84..fc19e5201a8 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/projects.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/profiles/projects.html.erb @@ -18,8 +18,8 @@ }) - <% unless @profile.projects.empty? %> - + <% if @profile.projects? %> +
@@ -27,7 +27,7 @@ - <% @profile.projects.each do |project| %> + <% @profile.sorted_projects.each do |project| %>
<%= link_to_action message('remove'), @@ -50,12 +50,10 @@
- - <% end %> <% else %> - <% if @profile.projects.empty? %> + <% if !@profile.projects? %>

<%= message('quality_profiles.no_projects_associated_to_profile_x', :params => @profile.name) -%>

<% else %>

<%= message('quality_profiles.projects_warning') -%>

@@ -67,7 +65,7 @@ - <% @profile.projects.each do |project| %> + <% @profile.sorted_projects.each do |project| %> <%= h project.name -%> <%= h project.key -%>