aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2012-07-05 10:27:58 +0200
committerFabrice Bellingard <bellingard@gmail.com>2012-07-05 10:30:34 +0200
commit1bab9db0c398f5fc7571409e4ae4967c45c5c855 (patch)
treed16ccf694e456ab5b2f7206227d1a655a96a6dd4
parente8f9f465365d336d69276cd392262b64a1516501 (diff)
downloadsonarqube-1bab9db0c398f5fc7571409e4ae4967c45c5c855.tar.gz
sonarqube-1bab9db0c398f5fc7571409e4ae4967c45c5c855.zip
SONAR-3570 Project "deletion" should run asynchronously
=> To prevent HTTP timeout.
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties5
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb45
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/resource_deletion_manager.rb9
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/_pending_deletions_screen.html.erb35
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/pending_deletions.html.erb36
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/project/deletion.html.erb9
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/views/project/pending_deletion.html.erb2
8 files changed, 92 insertions, 51 deletions
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
index fdec6a9f57f..e3bd591bf6a 100644
--- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/core.properties
@@ -1275,6 +1275,11 @@ bulk_deletion.clear_selection=Clear selection of all {0} resources
bulk_deletion.following_deletions_failed=The following resources could not be deleted. Please check the logs to know more about it.
bulk_deletion.hide_message=Hide message
bulk_deletion.sure_to_delete_the_resources=Are you sure you want to delete the selected resources?
+bulk_deletion.deletion_manager.deleting_resources=Deleting resources...
+bulk_deletion.deletion_manager.no_resource_to_delete=No resource to delete.
+bulk_deletion.deletion_manager.currently_deleting_x_out_of_x=Currently deleting resources... ({0} out of {1})
+bulk_deletion.deletion_manager.deletion_completed=Resource deletion completed.
+bulk_deletion.deletion_manager.however_failures_occurred=However, some failures occurred.
#------------------------------------------------------------------------------
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb
index a7d74f7887d..46a8055b268 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/bulk_deletion_controller.rb
@@ -76,7 +76,7 @@ class BulkDeletionController < ApplicationController
if deletion_manager.currently_deleting_resources? ||
(!deletion_manager.currently_deleting_resources? && deletion_manager.deletion_failures_occured?)
# display the same page again and again
- @deletion_manager = deletion_manager
+ # => implicit render "pending_deletions.html.erb"
else
redirect_to :action => 'index'
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
index 1391edd4ac0..cf5af3ed82d 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/project_controller.rb
@@ -31,21 +31,48 @@ class ProjectController < ApplicationController
def deletion
@project = get_current_project(params[:id])
- unless java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'deletable')
+ if java_facade.getResourceTypeBooleanProperty(@project.qualifier, 'deletable')
+ deletion_manager = ResourceDeletionManager.instance
+ if deletion_manager.currently_deleting_resources? ||
+ (!deletion_manager.currently_deleting_resources? && deletion_manager.deletion_failures_occured?)
+ # a deletion is happening or it has just finished with errors => display the message from the Resource Deletion Manager
+ render :template => 'project/pending_deletion'
+ else
+ @snapshot=@project.last_snapshot
+ end
+ else
redirect_to :action => 'index', :id => params[:id]
end
-
- @snapshot=@project.last_snapshot
end
def delete
- if params[:id]
- @project = Project.by_key(params[:id])
- if @project && is_admin?(@project)
- Project.delete_resource_tree(@project)
- end
+ @project = get_current_project(params[:id])
+
+ # Ask the resource deletion manager to start the migration
+ # => this is an asynchronous AJAX call
+ ResourceDeletionManager.instance.delete_resources([@project.id])
+
+ # and return some text that will actually never be displayed
+ render :text => ResourceDeletionManager.instance.message
+ end
+
+ def pending_deletion
+ deletion_manager = ResourceDeletionManager.instance
+
+ if deletion_manager.currently_deleting_resources? ||
+ (!deletion_manager.currently_deleting_resources? && deletion_manager.deletion_failures_occured?)
+ # display the same page again and again
+ # => implicit render "pending_deletion.html.erb"
+ else
+ redirect_to_default
end
- redirect_to_default
+ end
+
+ def dismiss_deletion_message
+ # It is important to reinit the ResourceDeletionManager so that the deletion screens can be available again
+ ResourceDeletionManager.instance.reinit
+
+ redirect_to :action => 'deletion', :id => params[:id]
end
def quality_profile
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/resource_deletion_manager.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/resource_deletion_manager.rb
index f828cc3e085..dbdcd73a348 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/resource_deletion_manager.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/resource_deletion_manager.rb
@@ -75,7 +75,7 @@ class ResourceDeletionManager
unless currently_deleting_resources?
reinit()
@status = WORKING
- @message = "Deleting resources..."
+ @message = Api::Utils.message('bulk_deletion.deletion_manager.deleting_resources')
can_start_deletion = true
end
end
@@ -83,13 +83,13 @@ class ResourceDeletionManager
if can_start_deletion
if resource_ids.empty?
@status = AVAILABLE
- @message = "No resource to delete."
+ @message = Api::Utils.message('bulk_deletion.deletion_manager.no_resource_to_delete')
else
java_facade = Java::OrgSonarServerUi::JRubyFacade.getInstance()
# launch the deletion
resource_ids.each_with_index do |resource_id, index|
resource = Project.find(:first, :conditions => {:id => resource_id.to_i})
- @message = "Currently deleting resources... (" + (index+1).to_s + " out of " + resource_ids.size.to_s + ")"
+ @message = Api::Utils.message('bulk_deletion.deletion_manager.currently_deleting_x_out_of_x', :params => [(index+1).to_s, resource_ids.size.to_s])
if resource &&
# next line add 'VW' and 'DEV' tests because those resource types don't have the 'deletable' property yet...
(java_facade.getResourceTypeBooleanProperty(resource.qualifier, 'deletable') || resource.qualifier=='VW' || resource.qualifier=='DEV')
@@ -102,7 +102,8 @@ class ResourceDeletionManager
end
end
@status = AVAILABLE
- @message = "Resource deletion completed."
+ @message = Api::Utils.message('bulk_deletion.deletion_manager.deletion_completed')
+ @message += ' ' + Api::Utils.message('bulk_deletion.deletion_manager.however_failures_occurred') unless @failed_deletions.empty?
end
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/_pending_deletions_screen.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/_pending_deletions_screen.html.erb
new file mode 100644
index 00000000000..27895ebe7dc
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/_pending_deletions_screen.html.erb
@@ -0,0 +1,35 @@
+<%
+ deletion_manager = ResourceDeletionManager.instance
+ pending_deletions = deletion_manager.currently_deleting_resources?
+ failed_deletions = deletion_manager.failed_deletions
+%>
+
+<% if pending_deletions %>
+ <meta http-equiv='refresh' content='5;'>
+<% end %>
+
+<h1 class="marginbottom10"><%= message('bulk_deletion.page') -%></h1>
+
+<div class="<%= pending_deletions ? 'admin' : 'error' -%>" style="padding:10px">
+ <% if pending_deletions %>
+ <%= image_tag 'loading.gif' -%>
+ <% end %>
+
+ <b><%= deletion_manager.message -%></b>
+ <br/>
+ <br/>
+
+ <% if !pending_deletions && !failed_deletions.empty? %>
+ <p>
+ <%= message('bulk_deletion.following_deletions_failed') -%>
+ <ul style="list-style: none outside; padding-left: 30px;">
+ <% failed_deletions.each do |name| %>
+ <li style="list-style: disc outside; padding: 2px;"><%= name -%></li>
+ <% end %>
+ </ul>
+ </p>
+ <p>
+ <a href="<%= url_after_dismiss -%>"><%= message('bulk_deletion.hide_message') -%></a>
+ </p>
+ <% end %>
+</div> \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/pending_deletions.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/pending_deletions.html.erb
index e5e67a6d57d..505c243e48a 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/pending_deletions.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/bulk_deletion/pending_deletions.html.erb
@@ -1,34 +1,2 @@
-<%
- pending_deletions = @deletion_manager.currently_deleting_resources?
- failed_deletions = @deletion_manager.failed_deletions
-%>
-
-<% if pending_deletions %>
- <meta http-equiv='refresh' content='5;'>
-<% end %>
-
-<h1 class="marginbottom10"><%= message('bulk_deletion.page') -%></h1>
-
-<div class="<%= pending_deletions ? 'admin' : 'error' -%>" style="padding:10px">
- <% if pending_deletions %>
- <%= image_tag 'loading.gif' -%>
- <% end %>
-
- <b><%= @deletion_manager.message -%></b>
- <br/>
- <br/>
-
- <% if !pending_deletions && !failed_deletions.empty? %>
- <p>
- <%= message('bulk_deletion.following_deletions_failed') -%>
- <ul style="list-style: none outside; padding-left: 30px;">
- <% failed_deletions.each do |name| %>
- <li style="list-style: disc outside; padding: 2px;"><%= name -%></li>
- <% end %>
- </ul>
- </p>
- <p>
- <%= link_to message('bulk_deletion.hide_message'), :action => 'dismiss_message' -%>
- </p>
- <% end %>
-</div> \ No newline at end of file
+<%= render :partial => 'pending_deletions_screen',
+ :locals => {:url_after_dismiss => url_for(:action => 'dismiss_message')} -%> \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/deletion.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/deletion.html.erb
index ea5493f8a4b..fb02aa93915 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/views/project/deletion.html.erb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/deletion.html.erb
@@ -7,10 +7,13 @@
<br/>
<div class="yui-g widget" id="widget_delete_project">
<div class="warning">
+ <% form_remote_tag( :url => {:action => 'delete', :id => @project.id}, :method => :delete,
+ :loading => "window.location='#{url_for :action => 'pending_deletion', :id => @project.id}';") do %>
<%= message('project_deletion.operation_cannot_be_undone') -%>
- <%= button_to( delete_resource_message, { :action => "delete", :id => @project.id },
- :class => 'action red-button', :method => :delete,
- :confirm => message('project_deletion.delete_resource_confirmation', :params => resource_name)) %>
+ <br/>
+ <%= submit_tag delete_resource_message, :id => 'delete_resource', :class => 'action red-button',
+ :confirm => message('project_deletion.delete_resource_confirmation', :params => resource_name) %>
+ <% end %>
</div>
</div>
<% end %> \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/project/pending_deletion.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/project/pending_deletion.html.erb
new file mode 100644
index 00000000000..7d96f93b194
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/app/views/project/pending_deletion.html.erb
@@ -0,0 +1,2 @@
+<%= render :partial => 'bulk_deletion/pending_deletions_screen',
+ :locals => {:url_after_dismiss => url_for(:action => 'dismiss_deletion_message', :id => params[:id])} -%> \ No newline at end of file