run.rb 848 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::System::Import::Run < Service::Base
  3. def initialize
  4. super
  5. configured!
  6. end
  7. def execute
  8. Setting.set('import_mode', true)
  9. source = Setting.get('import_backend')
  10. # Captain, oh my captain! I hate to do this, but we need to do it.
  11. return execute_otrs_import if source == 'otrs'
  12. job_name = "Import::#{source.camelize}"
  13. job = ImportJob.create(name: job_name)
  14. AsyncImportJob.perform_later(job)
  15. end
  16. private
  17. def execute_otrs_import
  18. AsyncOtrsImportJob.perform_later
  19. end
  20. def configured!
  21. raise ExecuteError if Setting.get('import_backend').empty?
  22. end
  23. class ExecuteError < StandardError
  24. def initialize(message = __('Please configure import source before running.'))
  25. super
  26. end
  27. end
  28. end