Browse Source

Merge branch 'develop' of github.com:martini/zammad into develop

Martin Edenhofer 9 years ago
parent
commit
edf565bd4d
1 changed files with 20 additions and 11 deletions
  1. 20 11
      app/controllers/import_otrs_controller.rb

+ 20 - 11
app/controllers/import_otrs_controller.rb

@@ -22,9 +22,7 @@ class ImportOtrsController < ApplicationController
       'Connection refused'                                        => 'Connection refused!',
     }
 
-    url_parts = params[:url].split(';')
-
-    response = UserAgent.request( url_parts[0] )
+    response = UserAgent.request( params[:url] )
 
     if !response.success? && response.code.to_s !~ /^40.$/
       message_human = ''
@@ -44,16 +42,27 @@ class ImportOtrsController < ApplicationController
     result = {}
     if response.body =~ /zammad migrator/
 
-      key_parts = url_parts[1].split('=')
+      migrator_response = JSON.parse(response.body)
 
-      Setting.set('import_backend', 'otrs')
-      Setting.set('import_otrs_endpoint', url_parts[0])
-      Setting.set('import_otrs_endpoint_key', key_parts[1])
+      if migrator_response['Success'] == 1
 
-      result = {
-        result: 'ok',
-        url: params[:url],
-      }
+        url_parts = params[:url].split(';')
+        key_parts = url_parts[1].split('=')
+
+        Setting.set('import_backend', 'otrs')
+        Setting.set('import_otrs_endpoint', url_parts[0])
+        Setting.set('import_otrs_endpoint_key', key_parts[1])
+
+        result = {
+          result: 'ok',
+          url: params[:url],
+        }
+      else
+        result = {
+          result: 'invalid',
+          message_human: migrator_response['Error']
+        }
+      end
     elsif response.body =~ /(otrs\sag|otrs\.com|otrs\.org)/i
       result = {
         result: 'invalid',