Browse Source

Fixes #4438 - OTRS Import is not using (agent&customer) article creator information.

Dominik Klein 2 years ago
parent
commit
83ebd41027

+ 39 - 2
lib/import/otrs/article.rb

@@ -21,11 +21,12 @@ module Import
         ContentType: :content_type,
         ChangeTime:  :updated_at,
         CreateTime:  :created_at,
+        ChangeBy:    :updated_by_id,
+        CreateBy:    :created_by_id,
 
-        # Support also the legacy time key names (lower then OTRS 6)
+        # Support also the legacy key names (lower then OTRS 6)
         Changed:     :updated_at,
         Created:     :created_at,
-
         ChangedBy:   :updated_by_id,
         CreatedBy:   :created_by_id,
       }.freeze
@@ -91,6 +92,7 @@ module Import
           .merge(from_mapping(article))
           .merge(article_type(article))
           .merge(article_sender_type(article))
+          .merge(article_created_and_updated_by_id(article))
       end
 
       def map_content_type(mapped)
@@ -113,6 +115,41 @@ module Import
         }
       end
 
+      def article_created_and_updated_by_id(article)
+        return {} if article['SenderType'] != 'customer'
+
+        created_by_id = get_article_created_by_id(article)
+        return {} if get_article_created_by_id(article) != 1
+        return {} if article['From'].blank?
+
+        user = Import::OTRS::ArticleCustomer.find(article)
+        return {} if !user
+
+        mapping = {
+          created_by_id: user.id,
+        }
+
+        updated_by_id = get_article_updated_by_id(article)
+        if !updated_by_id || updated_by_id == created_by_id
+          mapping[:updated_by_id] = user.id
+        end
+
+        mapping
+      end
+
+      def get_article_created_by_id(article)
+        return article['CreatedBy'].to_i if article['CreatedBy'].present?
+
+        article['CreateBy'].to_i
+      end
+
+      def get_article_updated_by_id(article)
+        return article['UpdatedBy'].to_i if article['UpdatedBy'].present?
+        return article['UpdateBy'].to_i if article['UpdateBy'].present?
+
+        nil
+      end
+
       def initialize_article_sender_types
         @sender_type_id = {
           'customer' => article_sender_type_id_lookup('Customer'),

+ 9 - 1
lib/import/otrs/article_customer_factory.rb

@@ -7,11 +7,19 @@ module Import
 
       def skip?(record, *_args)
         return true if record['SenderType'] != 'customer'
-        return true if record['CreatedBy'].to_i != 1
+        return true if create_by_id(record) != 1
         return true if record['From'].blank?
 
         false
       end
+
+      private
+
+      def create_by_id(record)
+        return record['CreatedBy'].to_i if record['CreatedBy'].present?
+
+        record['CreateBy'].to_i
+      end
     end
   end
 end

+ 2 - 1
spec/fixtures/files/import/otrs/article/content_type_comma.json

@@ -82,7 +82,8 @@
   "DynamicField_SugarCRMCompanySelectedID": null,
   "UntilTime": 0,
   "EscalationUpdateTime": "0",
-  "CreatedBy": "3",
+  "CreateBy": "3",
+  "ChangeBy": "3",
   "Queue": "Postmaster",
   "DynamicField_ITSMRepairStartTime": null,
   "ToRealname": "Postmaster",

+ 100 - 0
spec/fixtures/files/import/otrs/article/customer_email.json

@@ -0,0 +1,100 @@
+{
+  "Age": 200536176,
+  "PriorityID": "3",
+  "ContentType": "text/plain; charset=utf-8",
+  "DynamicField_SugarCRMCompanySelection": [
+    "Firma 1 - 117c26c0-11d4-7b8b-cb8f-4f7cb6823dd8",
+    "Firma 2 - 1111111-11d4-7b8b-cb8f-4f7cb6823dd8",
+    "Firma 3 - 22222222-11d4-7b8b-cb8f-4f7cb6823dd8"
+  ],
+  "ServiceID": null,
+  "TicketFreeText11": null,
+  "DynamicField_ITSMDueDate": null,
+  "DynamicField_Topic": null,
+  "StateID": "1",
+  "DynamicField_Hostname": null,
+  "Body": "Welcome!\n\nThank you for installing OTRS.\n\nYou will find updates and patches at http://www.otrs.com/open-source/.\nOnline documentation is available at http://doc.otrs.org/.\nYou can also use our mailing lists http://lists.otrs.org/\nor our forums at http://forums.otrs.org/\n\nRegards,\n\nThe OTRS Project\n",
+  "DynamicField_ZammadMigratorChanged": null,
+  "EscalationTime": "0",
+  "ChangeTime": "2014-06-24 09:32:14",
+  "OwnerID": "1",
+  "DynamicField_ZarafaTN": null,
+  "DynamicField_ProcessManagementActivityID": null,
+  "DynamicField_TopicID": null,
+  "DynamicField_ScomHostname": null,
+  "Owner": "root@localhost",
+  "AgeTimeUnix": 82611378,
+  "TicketFreeKey11": null,
+  "ArticleID": "999",
+  "CreateTime": "2010-08-02 14:00:00",
+  "DynamicField_ScomUUID": null,
+  "DynamicField_TicketFreeText11": null,
+  "DynamicField_TicketFreeKey11": null,
+  "DynamicField_ITSMReviewRequired": null,
+  "DynamicField_OpenExchangeTicketNumber": null,
+  "DynamicField_ITSMDecisionDate": null,
+  "ArticleTypeID": "1",
+  "QueueID": "2",
+  "ReplyTo": null,
+  "DynamicField_ITSMImpact": null,
+  "TicketID": "999",
+  "DynamicField_ITSMRecoveryStartTime": null,
+  "Cc": null,
+  "EscalationResponseTime": "0",
+  "DynamicField_ProcessManagementProcessID": null,
+  "IncomingTime": "1280750400",
+  "Charset": "",
+  "DynamicField_CheckboxExample": null,
+  "DynamicField_Location": null,
+  "CustomerUserID": "1000001",
+  "DynamicField_Vertriebsweg": null,
+  "Attachments": [],
+  "DynamicField_CustomerLocation": null,
+  "DynamicField_SugarCRMRemoteID": null,
+  "DynamicField_OpenExchangeTN": null,
+  "Service": "",
+  "Type": "Incident",
+  "ContentCharset": "",
+  "DynamicField_TETest": ["test", "test1", "test3"],
+  "Responsible": "root@localhost",
+  "SenderType": "customer",
+  "ResponsibleID": "1",
+  "SLA": "",
+  "MimeType": "",
+  "DynamicField_Combine": "22222222-11d4-7b8b-cb8f-4f7cb6823dd8",
+  "Subject": "Welcome to OTRS!",
+  "InReplyTo": null,
+  "RealTillTimeNotUsed": "0",
+  "DynamicField_ScomService": null,
+  "CustomerID": "1000001",
+  "TypeID": null,
+  "MessageID": "<007@localhost>",
+  "Priority": "3 normal",
+  "To": "Your OTRS System <otrs@localhost>",
+  "DynamicField_SugarCRMCompanySelectedID": "22222222-11d4-7b8b-cb8f-4f7cb6823dd8",
+  "UntilTime": 0,
+  "EscalationUpdateTime": "0",
+  "CreateBy": "1",
+  "Queue": "Raw",
+  "DynamicField_ITSMRepairStartTime": null,
+  "ToRealname": "Your OTRS System",
+  "State": "new",
+  "SenderTypeID": "3",
+  "DynamicField_ZammadMigratorChangedOld": null,
+  "Title": "Welcome to OTRS!",
+  "DynamicField_ScomState": null,
+  "References": null,
+  "DynamicField_Department": null,
+  "ArticleType": "email-external",
+  "StateType": "new",
+  "FromRealname": "Betreuter Kunde",
+  "EscalationSolutionTime": "0",
+  "LockID": "2",
+  "TicketNumber": "2010080210123456",
+  "DynamicField_ITSMDecisionResult": null,
+  "Lock": "lock",
+  "CreateTimeUnix": "1280750400",
+  "SLAID": null,
+  "DynamicField_ITSMCriticality": null,
+  "From": "\"Betreuter Kunde\" <kunde2@kunde.de>"
+}

+ 1 - 1
spec/fixtures/files/import/otrs/article/customer_phone.json

@@ -71,7 +71,7 @@
   "DynamicField_SugarCRMCompanySelectedID": null,
   "UntilTime": 0,
   "EscalationUpdateTime": "0",
-  "CreatedBy": "3",
+  "CreateBy": "3",
   "Queue": "Postmaster",
   "DynamicField_ITSMRepairStartTime": null,
   "ToRealname": "Postmaster",

+ 2 - 1
spec/fixtures/files/import/otrs/article/customer_phone_attachment.json

@@ -14,6 +14,7 @@
   "DynamicField_ZammadMigratorChanged": null,
   "EscalationTime": "0",
   "ChangeTime": "2014-11-21 00:21:08",
+  "ChangeBy": "3",
   "OwnerID": "3",
   "DynamicField_ZarafaTN": null,
   "DynamicField_ProcessManagementActivityID": null,
@@ -82,7 +83,7 @@
   "DynamicField_SugarCRMCompanySelectedID": null,
   "UntilTime": 0,
   "EscalationUpdateTime": "0",
-  "CreatedBy": "3",
+  "CreateBy": "3",
   "Queue": "Postmaster",
   "DynamicField_ITSMRepairStartTime": null,
   "ToRealname": "Postmaster",

+ 1 - 1
spec/fixtures/files/import/otrs/article/customer_phone_no_body.json

@@ -71,7 +71,7 @@
   "DynamicField_SugarCRMCompanySelectedID": null,
   "UntilTime": 0,
   "EscalationUpdateTime": "0",
-  "CreatedBy": "3",
+  "CreateBy": "3",
   "Queue": "Postmaster",
   "DynamicField_ITSMRepairStartTime": null,
   "ToRealname": "Postmaster",

+ 1 - 1
spec/fixtures/files/import/otrs/article/customer_special_chars.json

@@ -71,7 +71,7 @@
   "DynamicField_SugarCRMCompanySelectedID": null,
   "UntilTime": 0,
   "EscalationUpdateTime": "0",
-  "CreatedBy": "3",
+  "CreateBy": "1",
   "Queue": "Postmaster",
   "DynamicField_ITSMRepairStartTime": null,
   "ToRealname": "Postmaster",

+ 1 - 1
spec/fixtures/files/import/otrs/article/from_capital_case.json

@@ -71,7 +71,7 @@
   "DynamicField_SugarCRMCompanySelectedID": null,
   "UntilTime": 0,
   "EscalationUpdateTime": "0",
-  "CreatedBy": "3",
+  "CreateBy": "3",
   "Queue": "Postmaster",
   "DynamicField_ITSMRepairStartTime": null,
   "ToRealname": "Postmaster",

+ 1 - 0
spec/fixtures/files/import/otrs/article/legacy_article_time_keys.json → spec/fixtures/files/import/otrs/article/legacy_article_keys.json

@@ -72,6 +72,7 @@
   "UntilTime": 0,
   "EscalationUpdateTime": "0",
   "CreatedBy": "3",
+  "ChangedBy": "3",
   "Queue": "Postmaster",
   "DynamicField_ITSMRepairStartTime": null,
   "ToRealname": "Postmaster",

Some files were not shown because too many files changed in this diff