From 7ef20bed762e53c69dfbb4d2abbfcaf5f70bd091 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 10 Apr 2014 15:39:30 +0200 Subject: [PATCH] SONAR-4979 Fix migration on MySQL --- .../WEB-INF/app/controllers/dashboards_controller.rb | 8 ++++---- ...ove_active_dashboards_linked_on_unshared_dashboards.rb | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb index d5f42cf6027..06b4e593a4f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb @@ -90,10 +90,10 @@ class DashboardsController < ApplicationController if @dashboard.save # SONAR-4979 If the dashboard is no more shared, current user has to unfollow it if he was following it - # unless @dashboard.shared - # active = current_user.active_dashboards.to_a.find { |a| (a.user_id == dashboard_owner.id) && (a.dashboard_id == @dashboard.id)} - # active.destroy if active - # end + unless @dashboard.shared + active = current_user.active_dashboards.to_a.find { |a| (a.user_id == dashboard_owner.id) && (a.dashboard_id == @dashboard.id)} + active.destroy if active + end render :text => CGI.escapeHTML(params[:resource]), :status => 200 else diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/526_remove_active_dashboards_linked_on_unshared_dashboards.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/526_remove_active_dashboards_linked_on_unshared_dashboards.rb index 804c2d1c0dd..57945d2d499 100644 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/526_remove_active_dashboards_linked_on_unshared_dashboards.rb +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/526_remove_active_dashboards_linked_on_unshared_dashboards.rb @@ -24,14 +24,18 @@ # class RemoveActiveDashboardsLinkedOnUnsharedDashboards < ActiveRecord::Migration + class Dashboard < ActiveRecord::Base + end + class ActiveDashboard < ActiveRecord::Base + belongs_to :dashboard end def self.up ActiveDashboard.reset_column_information # Delete every active_dashboards linked on unshared dashboard not owned by the user - ActiveDashboard.delete_all(['dashboard_id in (SELECT d.id FROM dashboards d INNER JOIN active_dashboards ad on ad.dashboard_id=d.id WHERE ad.user_id<>d.user_id AND d.shared=?)', false]) + ActiveDashboard.all(:include => :dashboard, :conditions => ['dashboards.shared=? AND active_dashboards.user_id<>dashboards.user_id', false]).each {|ad| ad.delete} end end -- 2.39.5