20230330122449_relocate_unprocessable_mails.rb 744 B

123456789101112131415161718192021222324252627
  1. # Copyright (C) 2012-2024 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. begin
  14. # In case of readonly file systems (like in k8s), skip this migration.
  15. FileUtils.mkdir_p(new_dir)
  16. rescue
  17. return
  18. end
  19. FileUtils.cp_r(old_dir.children, new_dir)
  20. FileUtils.rm_r(old_dir)
  21. end
  22. end