diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2022-05-17 20:50:37 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2022-05-17 20:50:37 +0000 |
commit | e1d6bfbdcc1de030a4ae59e6f5a80f3d003cabe0 (patch) | |
tree | 31683b98b2301e7bbd89059edcba8489258ab95f /app/jobs | |
parent | 883aa3b5cca1645f2aae353f4f180f77c5693c7e (diff) | |
download | redmine-e1d6bfbdcc1de030a4ae59e6f5a80f3d003cabe0.tar.gz redmine-e1d6bfbdcc1de030a4ae59e6f5a80f3d003cabe0.zip |
Adds projects bulk delete (#36691).
Patch by Jens Krämer.
git-svn-id: https://svn.redmine.org/redmine/trunk@21592 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/jobs')
-rw-r--r-- | app/jobs/destroy_projects_job.rb | 31 |
1 files changed, 31 insertions, 0 deletions
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 |