Added import check if features used in different approach.

This commit is contained in:
Martin Edenhofer 2017-01-15 11:47:20 +01:00
parent 7a3baa2574
commit 3fa9a45b8c
5 changed files with 118 additions and 19 deletions

View file

@ -2,13 +2,16 @@ class Index extends App.ControllerContent
className: 'getstarted fit'
elements:
'.input-feedback': 'urlStatus'
'[data-target=otrs-start-migration]': 'nextStartMigration'
'.js-migration-check': 'nextStartMigration'
'.otrs-link-error': 'linkErrorMessage'
events:
'click .js-otrs-link': 'showLink'
'click .js-download': 'startDownload'
'click .js-migration-start': 'startMigration'
'click .js-migration-check': 'checkMigration'
'keyup #otrs-link': 'updateUrl'
updateMigrationDisplayLoop: 0
constructor: ->
super
@ -61,6 +64,13 @@ class Index extends App.ControllerContent
@$('[data-slide=otrs-plugin]').addClass('hide')
@$('[data-slide=otrs-link]').addClass('hide')
@$('[data-slide=otrs-import]').removeClass('hide')
@$('[data-slide=otrs-import-notice]').addClass('hide')
showImportNotice: =>
@$('[data-slide=otrs-plugin]').addClass('hide')
@$('[data-slide=otrs-link]').addClass('hide')
@$('[data-slide=otrs-import]').addClass('hide')
@$('[data-slide=otrs-import-notice]').removeClass('hide')
updateUrl: (e) =>
url = $(e.target).val()
@ -86,11 +96,27 @@ class Index extends App.ControllerContent
@urlStatus.attr('data-state', 'error')
@linkErrorMessage.text(data.message_human || data.message)
@nextStartMigration.addClass('hide')
)
@delay(callback, 700, 'import_otrs_url')
checkMigration: (e) =>
e.preventDefault()
@ajax(
id: 'import_otrs_check'
type: 'POST'
url: "#{@apiPath}/import/otrs/import_check"
processData: true
success: (data, status, xhr) =>
if data.result is 'ok'
@startMigration()
return
for issue in data.issues
@$(".js-#{issue}").removeClass('hide')
@showImportNotice()
)
startMigration: (e) =>
if e
e.preventDefault()
@showImportState()
@ajax(
@ -100,10 +126,11 @@ class Index extends App.ControllerContent
processData: true
success: (data, status, xhr) =>
if data.result is 'ok'
@delay(@updateMigration, 3000)
@delay(@updateMigration, 2000)
)
updateMigration: =>
@updateMigrationDisplayLoop += 1
@showImportState()
@ajax(
id: 'import_status'
@ -122,6 +149,11 @@ class Index extends App.ControllerContent
else
@$('.js-error').addClass('hide')
if data.message is 'not running' && @updateMigrationDisplayLoop > 10
@$('.js-error').removeClass('hide')
@$('.js-error').html(App.i18n.translateContent('Background process did not start or has not finished! Please contact your support.'))
return
if data.result is 'in_progress'
for key, item of data.data
if item.done > item.total

View file

@ -37,14 +37,13 @@
</div>
<div class="wizard-controls horizontal center">
<a class="btn btn--text btn--secondary" href="#import"><%- @T('Go Back') %></a>
<div class="btn btn--primary align-right hide js-migration-start" data-target="otrs-start-migration"><%- @T('Migrate OTRS Data') %></div>
<div class="btn btn--primary align-right hide js-migration-check"><%- @T('Migrate OTRS Data') %></div>
</div>
</div>
<div class="wizard-slide vertical hide" data-slide="otrs-import">
<h2><%- @T('OTRS Migration') %></h2>
<div class="alert alert--danger hide js-error" role="alert"></div>
<div class="wizard-body flex vertical justified">
<table class="progressTable">
<tr class="js-config">
@ -90,5 +89,17 @@
</div>
</div>
<div class="wizard-slide vertical hide" data-slide="otrs-import-notice">
<h2><%- @T('Notice') %></h2>
<div class="wizard-body flex vertical justified">
<p class="js-otrsProcesses hide"><%- @T('We detected OTRS BPM processes which can\'t get imported into Zammad, since we currently don\'t support these kind of workflows.') %></p>
<p class="js-otrsDynamicFields hide"><%- @T('We found many dynamic fields. We use a different approach towards ticket attributes. Zammad uses also tags in addition to custom fields to classify tickets. This difference may conflict with your current use of dynamic fields in OTRS.') %></p>
</div>
<div class="wizard-controls horizontal center">
<a class="btn btn--text btn--secondary" href="#import"><%- @T('Go Back') %></a>
<a href="#" class="btn btn--primary align-right js-migration-start"><%- @T('Continue anyway') %></a>
</div>
</div>
</div>
</div>

View file

@ -22,8 +22,7 @@ class ImportOtrsController < ApplicationController
'Connection refused' => 'Connection refused!',
}
response = UserAgent.request( params[:url] )
response = UserAgent.request(params[:url])
if !response.success? && response.code.to_s !~ /^40.$/
message_human = ''
translation_map.each { |key, message|
@ -46,12 +45,36 @@ class ImportOtrsController < ApplicationController
if migrator_response['Success'] == 1
# set url and key for import endpoint
url = migrator_response['URL']
key = migrator_response['Key']
# get first part url, used for import_otrs_endpoint
if !url || !key
url_parts = params[:url].split(';')
if !url_parts[1] # in case of & instead of ;
url_parts = params[:url].split('&')
end
key_parts = url_parts[1].split('=')
if !key_parts[1]
render json: {
result: 'invalid',
message_human: 'Unable to get key from URL!'
}
return
end
if !url
url = url_parts[0]
end
if !key
key = key_parts[1]
end
end
Setting.set('import_backend', 'otrs')
Setting.set('import_otrs_endpoint', url_parts[0])
Setting.set('import_otrs_endpoint_key', key_parts[1])
Setting.set('import_otrs_endpoint', url)
Setting.set('import_otrs_endpoint_key', key)
result = {
result: 'ok',
@ -98,6 +121,38 @@ class ImportOtrsController < ApplicationController
}
end
def import_check
statistic = Import::OTRS::Requester.list
issues = []
# check count of dynamic fields
dynamic_field_count = 0
dynamic_fields = Import::OTRS::Requester.load('DynamicField')
dynamic_fields.each { |dynamic_field|
next if dynamic_field['ValidID'].to_i != 1
dynamic_field_count += 1
}
if dynamic_field_count > 20
issues.push 'otrsDynamicFields'
end
# check if process exsists
sys_configs = Import::OTRS::Requester.load('SysConfig')
sys_configs.each { |sys_config|
next if sys_config['Key'] != 'Process'
issues.push 'otrsProcesses'
}
result = 'ok'
if !issues.empty?
result = 'failed'
end
render json: {
result: result,
issues: issues,
}
end
def import_status
result = Import::OTRS.status_bg
if result[:result] == 'import_done'

View file

@ -3,6 +3,7 @@ Zammad::Application.routes.draw do
# import otrs
match api_path + '/import/otrs/url_check', to: 'import_otrs#url_check', via: :post
match api_path + '/import/otrs/import_check', to: 'import_otrs#import_check', via: :post
match api_path + '/import/otrs/import_start', to: 'import_otrs#import_start', via: :post
match api_path + '/import/otrs/import_status', to: 'import_otrs#import_status', via: :get

View file

@ -15,11 +15,8 @@ class OtrsImportBrowserTest < TestCase
location(url: browser_url)
click(css: 'a[href="#import"]')
click(css: 'a[href="#import/otrs"]')
click(css: '.js-download')
click(css: '.js-otrs-link')
invalid_key_url = "#{ENV['IMPORT_BT_OTRS_ENDPOINT']};Key=31337"
@ -28,7 +25,6 @@ class OtrsImportBrowserTest < TestCase
css: '#otrs-link',
value: invalid_key_url
)
sleep 5
watch_for(
@ -41,14 +37,18 @@ class OtrsImportBrowserTest < TestCase
css: '#otrs-link',
value: import_url
)
sleep 5
watch_for_disappear(
css: '.otrs-link-error',
value: 'Invalid API key.',
)
click(css: '.js-migration-check')
watch_for(
css: '.wizard-slide:not(.hide)',
value: 'Notice',
)
click(css: '.js-migration-start')
watch_for(