20230330122449_relocate_unprocessable_mails.rb 622 B

123456789101112131415161718192021
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class RelocateUnprocessableMails < ActiveRecord::Migration[6.1]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. relocate_files('unprocessable_mail')
  7. relocate_files('oversized_mail')
  8. end
  9. def relocate_files(type)
  10. old_dir = Rails.root.join('tmp', type)
  11. return if !old_dir.exist? || old_dir.children.empty?
  12. new_dir = Rails.root.join('var/spool', type)
  13. FileUtils.mkdir_p(new_dir)
  14. FileUtils.cp_r(old_dir.children, new_dir)
  15. FileUtils.rm_r(old_dir)
  16. end
  17. end