From 3cb05ecc3a61235379635680bdbd6f1d745265ae Mon Sep 17 00:00:00 2001
From: Sebastian Pongratz <s.pongratz@adito.de>
Date: Mon, 10 May 2021 09:19:28 +0000
Subject: [PATCH] =?UTF-8?q?[Projekt:=20xRM-ContactManagement][TicketNr.:?=
 =?UTF-8?q?=201074059][Email=5Flib:=20Parameter=20Anzahl=20/=20Reihenfolge?=
 =?UTF-8?q?=20f=C3=BCr=20EmailWritingUtils.openNewMail()=20und=20EmailWrit?=
 =?UTF-8?q?ingUtils.sendReportAsMail()=20falsch.]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../_____SYSTEMALIAS/basic/init/init.xml      |  5 ++++-
 .../basic/init/struct/create_asys_audit.xml   | 21 +++++++++++++++++++
 process/Email_lib/process.js                  | 14 +++++++------
 3 files changed, 33 insertions(+), 7 deletions(-)
 create mode 100644 .liquibase/_____SYSTEMALIAS/basic/init/struct/create_asys_audit.xml

diff --git a/.liquibase/_____SYSTEMALIAS/basic/init/init.xml b/.liquibase/_____SYSTEMALIAS/basic/init/init.xml
index 540e5ac077..a3ef461345 100644
--- a/.liquibase/_____SYSTEMALIAS/basic/init/init.xml
+++ b/.liquibase/_____SYSTEMALIAS/basic/init/init.xml
@@ -1,5 +1,7 @@
 <?xml version="1.1" encoding="UTF-8" standalone="no"?>
 <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
+    
+    <include relativeToChangelogFile="true" file="struct/create_asys_audit.xml"/>
     <include relativeToChangelogFile="true" file="struct/create_asys_aliasconfig.xml"/>
     <include relativeToChangelogFile="true" file="struct/create_asys_binaries.xml"/>
     <include relativeToChangelogFile="true" file="struct/create_asys_dashletconfigurations.xml"/>
@@ -29,5 +31,6 @@
     <include relativeToChangelogFile="true" file="data/insert_asys_system.xml"/>
     <include relativeToChangelogFile="true" file="data/insert_asys_permissionset.xml"/>
     <include relativeToChangelogFile="true" file="data/insert_asys_permission.xml"/>
-    <include relativeToChangelogFile="true" file="data/insert_asys_permissionaction.xml"/>
+    <include relativeToChangelogFile="true" file="data/insert_asys_permissionaction.xml"/> 
+   
 </databaseChangeLog>
diff --git a/.liquibase/_____SYSTEMALIAS/basic/init/struct/create_asys_audit.xml b/.liquibase/_____SYSTEMALIAS/basic/init/struct/create_asys_audit.xml
new file mode 100644
index 0000000000..925f1cc139
--- /dev/null
+++ b/.liquibase/_____SYSTEMALIAS/basic/init/struct/create_asys_audit.xml
@@ -0,0 +1,21 @@
+<?xml version="1.1" encoding="UTF-8" standalone="no"?>
+<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
+<changeSet author="m.schloder" id="Xcb1ff99-55bd-4ebc-8137-ec05b4cacbd7">
+    <createTable tableName="ASYS_AUDIT">
+        <column name="ACOLUMNNAME" type="VARCHAR(217)"/>
+		<column name="ALIAS" type="VARCHAR(255)"/>
+		<column name="ATABLENAME" type="VARCHAR(127)"/>
+		<column name="ATIMESTAMP" type="DATETIME"/>
+		<column name="AUSER" type="VARCHAR(255)"/>
+		<column name="DATASETID" type="VARCHAR(1023)"/>
+		<column name="DATASETNEWVALUE_BLOB" type="LONGBLOB"/>
+		<column name="DATASETNEWVALUE_CLOB" type="TEXT"/>
+		<column name="DATASETNEWVALUE_STRING" type="VARCHAR(1023)"/>
+		<column defaultValueComputed="CURRENT_TIMESTAMP" name="LOGTIME" type="TIMESTAMP" />
+		<column name="LOGTYPE" type="INT"/>
+		<column name="LOGWRITERUID" type="VARCHAR(127)"/>
+		<column name="SQLACTION" type="CHAR(1)"/>  
+    </createTable>
+     
+    </changeSet>
+</databaseChangeLog>
\ No newline at end of file
diff --git a/process/Email_lib/process.js b/process/Email_lib/process.js
index 2bb2c3d123..93e6008b16 100644
--- a/process/Email_lib/process.js
+++ b/process/Email_lib/process.js
@@ -41,15 +41,19 @@ EmailWritingUtils.openMailTemplate = function (pToRecipients, pSenderContactId,
     if (pToRecipients && typeof(pToRecipients) == "string")
         pToRecipients = [pToRecipients];
     
-    var email;
+    var email, retVal, isBinaryExistent;
+    isBinaryExistent = db.getBinaryCount("DOCUMENTTEMPLATE", "DOCUMENT", pTemplateId, SqlUtils.getBinariesAlias(), null);
     
-    if (pTemplateId || (pBindata.bindata != "" && pBindata.bindata != null))
+    if ((pTemplateId && isBinaryExistent > 0) || (pBindata.bindata != "" && pBindata.bindata != null))
     {
         email = Email.fromTemplate(pTemplateId, pRecipientContactId, pBindata, pAdditionalPlaceholders);
         if (!email)
             email = new Email();
     }    
-    else email = new Email();
+    else 
+    {
+        email = new Email();
+    }
     
     email.setSender(pSenderContactId);
     
@@ -72,9 +76,7 @@ EmailWritingUtils.openMailTemplate = function (pToRecipients, pSenderContactId,
         email.subject = pSubject;
     }
     
-    var isBinaryExistent = db.getBinaryCount("DOCUMENTTEMPLATE", "DOCUMENT", pTemplateId, SqlUtils.getBinariesAlias(), null);
-    
-    return isBinaryExistent > 0 ? email.downloadEML(pEmailFilename) : [];
+    return email.downloadEML(pEmailFilename);
 }
 
 
-- 
GitLab