From e1d6bfbdcc1de030a4ae59e6f5a80f3d003cabe0 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Tue, 17 May 2022 20:50:37 +0000 Subject: Adds projects bulk delete (#36691). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Jens Krämer. git-svn-id: https://svn.redmine.org/redmine/trunk@21592 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/jobs/destroy_projects_job.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 app/jobs/destroy_projects_job.rb (limited to 'app/jobs') diff --git a/app/jobs/destroy_projects_job.rb b/app/jobs/destroy_projects_job.rb new file mode 100644 index 000000000..dba1213dc --- /dev/null +++ b/app/jobs/destroy_projects_job.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class DestroyProjectsJob < ApplicationJob + include Redmine::I18n + + def self.schedule(projects_to_delete, user: User.current) + # make the projects disappear immediately + projects_to_delete.each do |project| + project.self_and_descendants.update_all status: Project::STATUS_SCHEDULED_FOR_DELETION + end + perform_later(projects_to_delete.map(&:id), user.id, user.remote_ip) + end + + def perform(project_ids, user_id, remote_ip) + user = User.active.find_by_id(user_id) + unless user&.admin? + info "[DestroyProjectsJob] --- User check failed: User #{user_id} triggering projects destroy does not exist anymore or isn't admin/active." + return + end + + project_ids.each do |project_id| + DestroyProjectJob.perform_now(project_id, user_id, remote_ip) + end + end + + private + + def info(*msg) + Rails.logger.info(*msg) + end +end -- cgit v1.2.3