Merge branch 'develop' of git.znuny.com:zammad/zammad into develop
This commit is contained in:
commit
21206f2f62
1 changed files with 51 additions and 0 deletions
|
@ -59,6 +59,17 @@ class ImportJob < ApplicationModel
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Queues and starts all import backends as import jobs.
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# ImportJob.start_registered
|
||||||
|
#
|
||||||
|
# return [nil]
|
||||||
|
def self.start_registered
|
||||||
|
queue_registered
|
||||||
|
start
|
||||||
|
end
|
||||||
|
|
||||||
# Starts all import jobs that have not started yet and are no dry runs.
|
# Starts all import jobs that have not started yet and are no dry runs.
|
||||||
#
|
#
|
||||||
# @example
|
# @example
|
||||||
|
@ -68,4 +79,44 @@ class ImportJob < ApplicationModel
|
||||||
def self.start
|
def self.start
|
||||||
where(started_at: nil, dry_run: false).each(&:start)
|
where(started_at: nil, dry_run: false).each(&:start)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Queues all configured import backends from Setting 'import_backends' as import jobs
|
||||||
|
# that are not yet queued.
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# ImportJob.queue_registered
|
||||||
|
#
|
||||||
|
# return [nil]
|
||||||
|
def self.queue_registered
|
||||||
|
import_backends = Setting.get('import_backends')
|
||||||
|
return if import_backends.blank?
|
||||||
|
|
||||||
|
import_backends.each do |backend|
|
||||||
|
|
||||||
|
if !backend_valid?(backend)
|
||||||
|
Rails.logger.error "Invalid import backend '#{backend}'"
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
# skip if no entry exists
|
||||||
|
# skip if a not finished entry exists
|
||||||
|
next if ImportJob.exists?(name: backend, finished_at: nil)
|
||||||
|
|
||||||
|
ImportJob.create(name: backend)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Checks if the given import backend is valid.
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# ImportJob.backend_valid?('Import::Ldap')
|
||||||
|
# # => true
|
||||||
|
#
|
||||||
|
# return [Boolean]
|
||||||
|
def self.backend_valid?(backend)
|
||||||
|
backend.constantize
|
||||||
|
true
|
||||||
|
rescue NameError
|
||||||
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue