]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4979 Fix migration on MySQL
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 10 Apr 2014 13:39:30 +0000 (15:39 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 10 Apr 2014 13:39:39 +0000 (15:39 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/dashboards_controller.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/526_remove_active_dashboards_linked_on_unshared_dashboards.rb

index d5f42cf60271d9d099fe1f7ec7889e700c8f8f8d..06b4e593a4fd6fa4678b61a245c4283e37d41cff 100644 (file)
@@ -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
index 804c2d1c0dd26adc0c340c8f2d80396865f01cbc..57945d2d499966b0bbeba2119f930dd81a2f9782 100644 (file)
 #
 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