From 388fcc65271ced879bbace02350644e495d02ea6 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 13 Jan 2016 22:21:34 +0100 Subject: [PATCH] Improved import workflow. --- .../app/controllers/import_otrs.coffee | 5 ++- app/controllers/import_otrs_controller.rb | 7 ++--- lib/import/otrs.rb | 31 +++++++++---------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/app/controllers/import_otrs.coffee b/app/assets/javascripts/app/controllers/import_otrs.coffee index da6e8f92c..01097e8dd 100644 --- a/app/assets/javascripts/app/controllers/import_otrs.coffee +++ b/app/assets/javascripts/app/controllers/import_otrs.coffee @@ -114,9 +114,8 @@ class Index extends App.ControllerContent processData: true, success: (data, status, xhr) => - if data.setup_done - @Config.set('system_init_done', true) - @navigate '#' + if data.result is 'import_done' + window.location.reload() return if data.result is 'error' diff --git a/app/controllers/import_otrs_controller.rb b/app/controllers/import_otrs_controller.rb index b92625a8d..42f4434f3 100644 --- a/app/controllers/import_otrs_controller.rb +++ b/app/controllers/import_otrs_controller.rb @@ -91,10 +91,7 @@ class ImportOtrsController < ApplicationController end # start migration - Import::OTRS.delay.start_bg( - import_otrs_endpoint: Setting.get('import_otrs_endpoint'), - import_otrs_endpoint_key: Setting.get('import_otrs_endpoint_key'), - ) + Import::OTRS.delay.start_bg render json: { result: 'ok', @@ -103,7 +100,7 @@ class ImportOtrsController < ApplicationController def import_status result = Import::OTRS.status_bg - if result[:setup_done] == true + if result[:result] == 'import_done' Setting.reload end render json: result diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index 50b084d26..b3e33d754 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -415,19 +415,15 @@ module Import::OTRS =begin start import in background - Import::OTRS.start_bg( - import_otrs_endpoint: 'http://vz599.demo.znuny.com/otrs/public.pl?Action=ZammadMigrator -', - import_otrs_endpoint_key: '01234567899876543210', - ) + Import::OTRS.start_bg =end - def self.start_bg(params) - Setting.set('import_mode', 'true') - Setting.set('import_backend', 'otrs') - Setting.set('import_otrs_endpoint', params[:import_otrs_endpoint]) - Setting.set('import_otrs_endpoint_key', params[:import_otrs_endpoint_key]) + def self.start_bg + Setting.reload + Import::OTRS.connection_test + + # start thread to observe current state status_update_thread = Thread.new { loop do result = { @@ -438,9 +434,9 @@ module Import::OTRS sleep 8 end } + sleep 2 - sleep 5 - + # start thread to import data begin import_thread = Thread.new { Import::OTRS.start @@ -455,11 +451,17 @@ module Import::OTRS result: 'error', } Cache.write('import:state', result, expires_in: 10.hours) + return false end import_thread.join status_update_thread.exit status_update_thread.join + result = { + result: 'import_done', + } + Cache.write('import:state', result, expires_in: 10.hours) + Setting.set('system_init_done', true) Setting.set('import_mode', false) end @@ -473,11 +475,6 @@ module Import::OTRS =end def self.status_bg - if !Setting.get('import_mode') - return { - setup_done: true, - } - end state = Cache.get('import:state') return state if state {