diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rb index 6474618d76e..58f1f2063a3 100644 --- a/app/jobs/regular/export_csv_file.rb +++ b/app/jobs/regular/export_csv_file.rb @@ -106,7 +106,6 @@ module Jobs def user_list_export return enum_for(:user_list_export) unless block_given? - user_array = [] user_field_ids = UserField.pluck(:id) condition = {} diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake index 776aa5fb85f..186e6564377 100644 --- a/lib/tasks/posts.rake +++ b/lib/tasks/posts.rake @@ -493,3 +493,35 @@ task 'posts:missing_uploads', [:single_site] => :environment do |_, args| end end end + +def destroy_old_user_data_exports + topics = Topic.with_deleted.where(<<~SQL, 2.days.ago) + slug = 'user-archive-data-export-complete' AND + archetype = 'private_message' AND + posts_count = 1 AND + created_at < ? AND + user_id = -1 + SQL + + puts "Found #{topics.count} old user data exports on #{RailsMultisite::ConnectionManagement.current_db}, destroying" + puts + topics.each do |t| + Topic.transaction do + t.posts.first.destroy! + t.destroy! + print "." + end + end + puts "done" +end + +desc 'destroys all user archive PMs (they may contain broken images)' +task 'posts:destroy_old_user_data_exports' => :environment do + if RailsMultisite::ConnectionManagement.current_db != "default" + destroy_old_user_data_exports + else + RailsMultisite::ConnectionManagement.each_connection do + destroy_old_user_data_exports + end + end +end