diff --git a/README.md b/README.md index 1013ba0..7a8160d 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,22 @@ The tool provides the ability to analyze the source items in the source Sitecore The tool offers the users the choice to migrate saved WFFM forms data from a SQL database or from a MongoDB database source to the destination Sitecore Experience Forms SQL database. -**NEW** - Starting from release 1.3.0, the tool migrates WFFM File Upload form field files (stored in the Media Library) to the new `FileStorage` table in the Experience Forms SQL database (introduced with Sitecore 9.3 Initial Release version). +Starting from release 1.3.0, the tool migrates WFFM File Upload form field files (stored in the Media Library) to the new `FileStorage` table in the Experience Forms SQL database (introduced with Sitecore 9.3 Initial Release version). + +**NEW** - Starting from release 1.4.0, the tool migrates WFFM Send Email save actions to the new out-of-the-box Sitecore Forms Send Email submit action (introduced with Sitecore 10.1 version). ## Sitecore Compatibility -The tool has been designed to support the migration of sitecore items from any version of Sitecore to Sitecore 9.1+. If migrating to Sitecore 9.3+, use the latest release of the tool that can be downloaded [here](https://github.com/afaniuolo/WFFM-Conversion-Tool/releases/latest). -If migrating to a version of Sitecore prior to 9.3, use the 1.2.x release of the tool that can be downloaded [here](https://github.com/afaniuolo/WFFM-Conversion-Tool/releases/tag/v1.2.0). -The tool has been tested migrating WFFM forms items and data starting from Sitecore version 6.5. +The tool has been designed to support the migration of sitecore items from any version of Sitecore to Sitecore 9.1 or later version. The tool has been tested migrating WFFM forms items and data starting from Sitecore version 6.5. + +The following compatibility table lists the correct version of the tool that should be used based on the version of the destination Sitecore instance: + +| Destination Sitecore Version | WFFM Conversion Tool Version | | +|:------------------------------:|:------------------------------:|---------------| +| Sitecore 9.1.x
Sitecore 9.2 | v1.2.2 | [download](https://github.com/afaniuolo/WFFM-Conversion-Tool/releases/tag/v1.2.2) | +| Sitecore 9.3 | v1.3.4 | [download](https://github.com/afaniuolo/WFFM-Conversion-Tool/releases/tag/v1.3.4) | +| Sitecore 10.0.x | v1.4.0 | [download](https://github.com/afaniuolo/WFFM-Conversion-Tool/releases/tag/v1.4.0) | +| Sitecore 10.1+ | v1.5.0 | [download](https://github.com/afaniuolo/WFFM-Conversion-Tool/releases/tag/v1.5.0) | + ## Technical Requirements ### Software: @@ -20,13 +30,12 @@ The tool has been tested migrating WFFM forms items and data starting from Sitec - No particular hardware requirement ## How to Install the Tool -The tool is distributed in a ZIP archive. If migrating to Sitecore 9.3+, use the latest release of the tool that can be downloaded [here](https://github.com/afaniuolo/WFFM-Conversion-Tool/releases/latest). -If migrating to a version of Sitecore prior to 9.3, use the 1.2.x release of the tool that can be downloaded [here](https://github.com/afaniuolo/WFFM-Conversion-Tool/releases/tag/v1.2.0). +The tool is distributed in a ZIP archive. Refer to the tool compatibility table above to download the correct version of the tool based on the destination Sitecore version. The tool can be installed in any server or local machine that has access to the databases involved in the conversion and migration process. The tool doesn't require the source and destination Sitecore instances to run in IIS while the conversion process occurs, because the tool connects directly to the Sitecore databases, without using Sitecore APIs or other Sitecore modules. ### Installation Steps -1) Download the correct release of the tool. If migrating to Sitecore 9.3+, download the [latest release](https://github.com/afaniuolo/WFFM-Conversion-Tool/releases/latest) of the tool. If migrating to a version of Sitecore prior to 9.3, download the [1.2.x release](https://github.com/afaniuolo/WFFM-Conversion-Tool/releases/tag/v1.2.0) of the tool. +1) Download the correct release of the tool. Refer to the tool compatibility table above to download the correct version of the tool based on the destination Sitecore version. 2) Extract the ZIP archive in a folder on the machine where the tool will be executed. 3) Assign read-write permissions to the folder and its subitems for the user that will execute the tool. @@ -148,8 +157,8 @@ The *extension* plugin for the [Sitecore Forms Extensions](https://github.com/ba NOTE: The data of the File Upload field is converted and migrated using the storage format of the File System storage provider (`FileSystemFileUploadStorageProvider` class). -### Sitecore Forms Send Email Submit Action -The *extension* plugin for the [Sitecore Forms Send Email Submit Action](https://marketplace.sitecore.net/Modules/S/Sitecore_Forms_Send_Email_Submit_Action.aspx) module developed by Byron Calisto adds the support for the conversion of the *Send Email* submit action. +### Sitecore Forms Send Email Submit Action (only for Sitecore 10.0 or prior - removed in latest version for SC 10.1+) +The *extension* plugin for the [Sitecore Forms Send Email Submit Action](https://marketplace.sitecore.net/Modules/S/Sitecore_Forms_Send_Email_Submit_Action.aspx) module developed by Byron Calisto adds the support for the conversion of the *Send Email* submit action for destination Sitecore versions prior to Sitecore 10.1. ## How to Expand the WFFM Conversion Tool to Convert Custom Entities Some of the items or fields that cannot be mapped could be custom items created to expand the out-of-the-box functionality of the Sitecore WFFM module. For example, custom entities could be custom form field types or custom save actions. To help developers to automate the conversion and migration of custom entities, the tool allows to expand its default mapping capabilities, as described in the next three sections. diff --git a/WFFM.ConversionTool.sln b/WFFM.ConversionTool.sln index 2505955..42ac163 100644 --- a/WFFM.ConversionTool.sln +++ b/WFFM.ConversionTool.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27703.2018 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30104.148 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WFFM.ConversionTool.Library", "src\WFFM.ConversionTool.Library\WFFM.ConversionTool.Library.csproj", "{670AD498-F9F3-45BC-81A5-4C5841249298}" EndProject @@ -9,8 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WFFM.ConversionTool", "src\ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Extensions", "Extensions", "{A8AB7F81-859B-4B4C-84B3-08FD913AEC9C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction", "src\WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction\WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction.csproj", "{0EA8EAA3-981A-4525-AFD5-6A539FDED0C1}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WFFM.ConversionTool.Extensions.SitecoreFormsExtensions", "src\WFFM.ConversionTool.Extensions.SitecoreFormsExtensions\WFFM.ConversionTool.Extensions.SitecoreFormsExtensions.csproj", "{B0F28BBF-BCDF-491B-A6D3-406F7B042C24}" EndProject Global @@ -27,10 +25,6 @@ Global {49CD87DD-7950-4296-87B0-D5495D7A3A5A}.Debug|Any CPU.Build.0 = Debug|Any CPU {49CD87DD-7950-4296-87B0-D5495D7A3A5A}.Release|Any CPU.ActiveCfg = Release|Any CPU {49CD87DD-7950-4296-87B0-D5495D7A3A5A}.Release|Any CPU.Build.0 = Release|Any CPU - {0EA8EAA3-981A-4525-AFD5-6A539FDED0C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0EA8EAA3-981A-4525-AFD5-6A539FDED0C1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0EA8EAA3-981A-4525-AFD5-6A539FDED0C1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0EA8EAA3-981A-4525-AFD5-6A539FDED0C1}.Release|Any CPU.Build.0 = Release|Any CPU {B0F28BBF-BCDF-491B-A6D3-406F7B042C24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B0F28BBF-BCDF-491B-A6D3-406F7B042C24}.Debug|Any CPU.Build.0 = Debug|Any CPU {B0F28BBF-BCDF-491B-A6D3-406F7B042C24}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -40,7 +34,6 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {0EA8EAA3-981A-4525-AFD5-6A539FDED0C1} = {A8AB7F81-859B-4B4C-84B3-08FD913AEC9C} {B0F28BBF-BCDF-491B-A6D3-406F7B042C24} = {A8AB7F81-859B-4B4C-84B3-08FD913AEC9C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/src/WFFM.ConversionTool.Extensions.SitecoreFormsExtensions/Properties/AssemblyInfo.cs b/src/WFFM.ConversionTool.Extensions.SitecoreFormsExtensions/Properties/AssemblyInfo.cs index 787f9c7..7556f78 100644 --- a/src/WFFM.ConversionTool.Extensions.SitecoreFormsExtensions/Properties/AssemblyInfo.cs +++ b/src/WFFM.ConversionTool.Extensions.SitecoreFormsExtensions/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.0")] -[assembly: AssemblyFileVersion("1.4.0.0")] +[assembly: AssemblyVersion("1.5.0.0")] +[assembly: AssemblyFileVersion("1.5.0.0")] diff --git a/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/Properties/AssemblyInfo.cs b/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/Properties/AssemblyInfo.cs deleted file mode 100644 index 1354b50..0000000 --- a/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction")] -[assembly: AssemblyCopyright("Copyright © 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("0ea8eaa3-981a-4525-afd5-6a539fded0c1")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.0")] -[assembly: AssemblyFileVersion("1.4.0.0")] diff --git a/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction.csproj b/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction.csproj deleted file mode 100644 index 710aab4..0000000 --- a/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction.csproj +++ /dev/null @@ -1,67 +0,0 @@ - - - - - Debug - AnyCPU - {0EA8EAA3-981A-4525-AFD5-6A539FDED0C1} - Library - Properties - WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction - WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction - v4.7.1 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - {670ad498-f9f3-45bc-81a5-4c5841249298} - WFFM.ConversionTool.Library - - - - - Always - - - - - - - - - - \ No newline at end of file diff --git a/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/packages.config b/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/packages.config deleted file mode 100644 index 7edba42..0000000 --- a/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/readme_SitecoreFormsSendEmailSubmitAction.txt b/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/readme_SitecoreFormsSendEmailSubmitAction.txt deleted file mode 100644 index f4a69c3..0000000 --- a/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/readme_SitecoreFormsSendEmailSubmitAction.txt +++ /dev/null @@ -1,14 +0,0 @@ -+------------------------------------------------------+ -| Installation Instructions | -+------------------------------------------------------+ - -1) Copy the entire module extension folder in the WFFM Conversion Tool root folder. When prompted, choose to merge the existing folders. - -2) Open the AppSettings.json file located in the WFFM Conversion Tool root folder and uncomment the following JSON object in the "submitActions" property: - -{ - "sourceSaveActionId": "{D4502A11-9417-4479-9F2A-485F45D2E2D0}", - "destSubmitActionItemName": "Send Email", - "destSubmitActionFieldValue": "{065C982A-BA27-45E6-BC9B-F2821D904021}", - "destParametersConverterType": "WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction.Converters.SendEmailConverter, WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction" -} \ No newline at end of file diff --git a/src/WFFM.ConversionTool.Library/Constants/EmailAddressConstants.cs b/src/WFFM.ConversionTool.Library/Constants/EmailAddressConstants.cs new file mode 100644 index 0000000..6cb7cdf --- /dev/null +++ b/src/WFFM.ConversionTool.Library/Constants/EmailAddressConstants.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WFFM.ConversionTool.Library.Constants +{ + public class EmailAddressConstants + { + // Senders Setting Folder + public const string EmailAddressSendersFolderId = "{E52AB5AD-3202-4B6F-9BAD-80B049C403EA}"; + + // FieldId + public const string EmailAddressValueFieldId = "{49DC3FF7-C17D-4574-B88E-2418DCE1315F}"; + } +} diff --git a/src/WFFM.ConversionTool.Library/Constants/FormConstants.cs b/src/WFFM.ConversionTool.Library/Constants/FormConstants.cs index deeae93..2e6c667 100644 --- a/src/WFFM.ConversionTool.Library/Constants/FormConstants.cs +++ b/src/WFFM.ConversionTool.Library/Constants/FormConstants.cs @@ -34,5 +34,6 @@ public class FormConstants public const string FormSubmitModeField_ShowMessageValue = "{3B8369A0-CC1A-4E9A-A3DB-7B086379C53B}"; public const string FormSaveAction_RegisterCampaignValue = "{AD26FE98-EED1-45C8-95AE-F2714EE33C62}"; public const string FormSaveAction_SaveToDatabaseValue = "{F03608CC-559B-451E-BC5B-6A7ADFF32C94}"; + public const string FormSaveAction_SendEmailValue = "{D4502A11-9417-4479-9F2A-485F45D2E2D0}"; } } diff --git a/src/WFFM.ConversionTool.Library/Constants/SubmitActionConstants.cs b/src/WFFM.ConversionTool.Library/Constants/SubmitActionConstants.cs index 074de9a..edbf7b8 100644 --- a/src/WFFM.ConversionTool.Library/Constants/SubmitActionConstants.cs +++ b/src/WFFM.ConversionTool.Library/Constants/SubmitActionConstants.cs @@ -17,5 +17,6 @@ public class SubmitActionConstants public const string SubmitActionField_RedirectToPageActionValue = "{3F3E2093-9DEA-4199-86CA-44FC69EF624D}"; public const string SubmitActionField_TriggerGoalActionValue = "{106587B9-1B9C-4DDB-AE96-BAC8416C21B5}"; public const string SubmitActionField_TriggerCampaignActivityActionValue = "{4A937D74-7986-4E19-9D8E-EC14675B17F0}"; + public const string SubmitActionField_SendEmailActionValue = "{A082C3F9-D90F-4825-8A38-8D2BE7653FC0}"; } } diff --git a/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/Converters/SendEmailConverter.cs b/src/WFFM.ConversionTool.Library/Converters/SubmitActionConverters/SendEmailConverter.cs similarity index 87% rename from src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/Converters/SendEmailConverter.cs rename to src/WFFM.ConversionTool.Library/Converters/SubmitActionConverters/SendEmailConverter.cs index 70a0239..783f9f7 100644 --- a/src/WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction/Converters/SendEmailConverter.cs +++ b/src/WFFM.ConversionTool.Library/Converters/SubmitActionConverters/SendEmailConverter.cs @@ -1,82 +1,85 @@ -using Newtonsoft.Json; -using System; -using System.Text.RegularExpressions; -using WFFM.ConversionTool.Library.Converters; -using WFFM.ConversionTool.Library.Helpers; -using WFFM.ConversionTool.Library.Logging; -using WFFM.ConversionTool.Library.Repositories; - -namespace WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction.Converters -{ - public class SendEmailConverter : BaseFieldConverter - { - private IDestMasterRepository _destMasterRepository; - private ILogger _logger; - - public SendEmailConverter(IDestMasterRepository destMasterRepository, ILogger logger) - { - _destMasterRepository = destMasterRepository; - _logger = logger; - } - - public override string ConvertValue(string sourceValue) - { - // example of sourceValue - // example.hostexample@mail.nettrueto@example.comcc@example.combcc@example.comexample@mail.netThis is the subject of the email.

This is the body of the email.

[]

- var host = XmlHelper.GetXmlElementValue(sourceValue, "host", true); - var from = XmlHelper.GetXmlElementValue(sourceValue, "from", true); - var isbodyhtml = XmlHelper.GetXmlElementValue(sourceValue, "isbodyhtml", true); - var to = XmlHelper.GetXmlElementValue(sourceValue, "to", true); - var cc = XmlHelper.GetXmlElementValue(sourceValue, "cc", true); - var bcc = XmlHelper.GetXmlElementValue(sourceValue, "bcc", true); - var localfrom = XmlHelper.GetXmlElementValue(sourceValue, "localfrom", true); - var subject = ConvertFieldTokens(XmlHelper.GetXmlElementValue(sourceValue, "subject", true)); - var mail = ConvertFieldTokens(XmlHelper.GetXmlElementValue(sourceValue, "mail", true)); - - var fromValue = !string.IsNullOrEmpty(from) ? from : localfrom; - - return JsonConvert.SerializeObject(new { - from = fromValue, - to = to, - cc = cc, - bcc = bcc, - subject = subject, - message = mail, - isHtml = isbodyhtml, - customSmtpConfig = $"{host}" - }); - } - - private string ConvertFieldTokens(string fieldText) - { - // Find all tokens - var matches = Regex.Matches(fieldText, @"\[(.*?)\]", RegexOptions.IgnoreCase); - - foreach (Match match in matches) - { - Guid fieldId; - var fieldName = string.Empty; - var matchValue = match.Value.Replace("[", "").Replace("]", ""); - if (Guid.TryParse(matchValue, out fieldId)) // case of token in subject field - { - // find field name - fieldName = _destMasterRepository.GetSitecoreItem(fieldId)?.Name; - - } - else // case of token in message field - { - // get field label value - fieldName = XmlHelper.GetXmlElementValue(matchValue, "label", true); - } - - if (!string.IsNullOrEmpty(fieldName)) - { - // replace token with label value - fieldText = fieldText.Replace(matchValue, fieldName); - } - } - - return fieldText; - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using Newtonsoft.Json; +using WFFM.ConversionTool.Library.Helpers; +using WFFM.ConversionTool.Library.Logging; +using WFFM.ConversionTool.Library.Models.Form; +using WFFM.ConversionTool.Library.Repositories; + +namespace WFFM.ConversionTool.Library.Converters.SubmitActionConverters +{ + public class SendEmailConverter : BaseFieldConverter + { + private IDestMasterRepository _destMasterRepository; + private ILogger _logger; + + public SendEmailConverter(IDestMasterRepository destMasterRepository, ILogger logger) + { + _destMasterRepository = destMasterRepository; + _logger = logger; + } + + public override string ConvertValue(string sourceValue) + { + // example of sourceValue + // example.hostexample@mail.nettrueto@example.comcc@example.combcc@example.comexample@mail.netThis is the subject of the email.

This is the body of the email.

[]

+ var host = XmlHelper.GetXmlElementValue(sourceValue, "host", true); + var from = XmlHelper.GetXmlElementValue(sourceValue, "from", true); + var isbodyhtml = XmlHelper.GetXmlElementValue(sourceValue, "isbodyhtml", true); + var to = XmlHelper.GetXmlElementValue(sourceValue, "to", true); + var cc = XmlHelper.GetXmlElementValue(sourceValue, "cc", true); + var bcc = XmlHelper.GetXmlElementValue(sourceValue, "bcc", true); + var localfrom = XmlHelper.GetXmlElementValue(sourceValue, "localfrom", true); + var subject = ConvertFieldTokens(XmlHelper.GetXmlElementValue(sourceValue, "subject", true)); + var mail = ConvertFieldTokens(XmlHelper.GetXmlElementValue(sourceValue, "mail", true)); + + var fromValue = !string.IsNullOrEmpty(from) ? from : localfrom; + + return JsonConvert.SerializeObject(new + SendEmailAction() { + from = fromValue, + to = to, + cc = cc, + bcc = bcc, + subject = subject, + body = mail + }); + } + + private string ConvertFieldTokens(string fieldText) + { + // Find all tokens + var matches = Regex.Matches(fieldText, @"\[(.*?)\]", RegexOptions.IgnoreCase); + + foreach (Match match in matches) + { + Guid fieldId; + var fieldName = string.Empty; + var matchValue = match.Value.Replace("[", "").Replace("]", ""); + if (Guid.TryParse(matchValue, out fieldId)) // case of token in subject field + { + // find field name + fieldName = _destMasterRepository.GetSitecoreItem(fieldId)?.Name; + + } + else // case of token in message field + { + // get field label value + fieldName = XmlHelper.GetXmlElementValue(matchValue, "label", true); + } + + if (!string.IsNullOrEmpty(fieldName)) + { + // replace token with label value + fieldText = fieldText.Replace(matchValue, fieldName); + } + } + + return fieldText; + } + } +} diff --git a/src/WFFM.ConversionTool.Library/Converters/SubmitConverter.cs b/src/WFFM.ConversionTool.Library/Converters/SubmitConverter.cs index 07db195..580dd01 100644 --- a/src/WFFM.ConversionTool.Library/Converters/SubmitConverter.cs +++ b/src/WFFM.ConversionTool.Library/Converters/SubmitConverter.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using System.Web; using System.Xml; +using Newtonsoft.Json; using WFFM.ConversionTool.Library.Constants; using WFFM.ConversionTool.Library.Factories; using WFFM.ConversionTool.Library.Helpers; @@ -278,7 +279,13 @@ private void ConvertSaveActions(SCItem form, string tracking, SCItem buttonItem, form.ID, formSaveActionField.Id, saveActionItem.Parameters), ex)); } - ConvertFieldsToSubmitActionItem(submitAction.destSubmitActionItemName, submitActionValues, buttonItem); + var destSubmitActionItemId = ConvertFieldsToSubmitActionItem(submitAction.destSubmitActionItemName, submitActionValues, buttonItem); + + // Only if Save Action is Send Email + if (submitAction.sourceSaveActionId == Guid.Parse(FormConstants.FormSaveAction_SendEmailValue)) + { + CreateAddressBookSender(destSubmitActionItemId); + } } else { @@ -290,6 +297,42 @@ private void ConvertSaveActions(SCItem form, string tracking, SCItem buttonItem, } } + private void CreateAddressBookSender(Guid destSubmitActionItemId) + { + var destItem = _destMasterRepository.GetSitecoreItem(destSubmitActionItemId); + if (destItem != null && + destItem.Fields.FirstOrDefault(f => f.FieldId == Guid.Parse(SubmitActionConstants.SubmitActionFieldId))?.Value == + SubmitActionConstants.SubmitActionField_SendEmailActionValue) + { + var sendEmail = JsonConvert.DeserializeObject(destItem.Fields + .First(f => f.FieldId == new Guid(SubmitActionConstants.ParametersFieldId)).Value); + + var emailFromValue = sendEmail.from; + + if (!string.IsNullOrEmpty(emailFromValue) && emailFromValue.IndexOf('@') > 0) + { + var emailAddressMetadata = _metadataProvider.GetItemMetadataByTemplateName("Email Address"); + var senderItems = _destMasterRepository.GetSitecoreDescendantsItems( + emailAddressMetadata.destTemplateId, + new Guid(EmailAddressConstants.EmailAddressSendersFolderId)); + + + if (!senderItems.Any(item => item.Fields.FirstOrDefault(f => f.FieldId == Guid.Parse(EmailAddressConstants.EmailAddressValueFieldId)) != null + && string.Equals(item.Fields.First(f => f.FieldId == Guid.Parse(EmailAddressConstants.EmailAddressValueFieldId)).Value, emailFromValue, StringComparison.InvariantCultureIgnoreCase))) + { + var addressSenderItemName = emailFromValue.Substring(0, emailFromValue.IndexOf('@')); + + // Set Email Address item fields + var addressSenderItemFieldValues = new Dictionary(); + addressSenderItemFieldValues.Add(new Guid(EmailAddressConstants.EmailAddressValueFieldId), + emailFromValue); // Value field + + CreateEmailAddressItem("Email Address", addressSenderItemName, addressSenderItemFieldValues); + } + } + } + } + private Guid ConvertTextField(SCItem form, Guid parentId) { var parentItem = _destMasterRepository.GetSitecoreItem(parentId); @@ -321,7 +364,7 @@ private Guid ConvertSubmitFields(SCItem form, Guid parentId) return WriteNewItem(_metadataProvider.GetItemMetadataByTemplateName("Button").destTemplateId, parentItem, "Submit", buttonMetadata); } - private void CreateItem(string metadataTemplateName, string destItemName, Dictionary destFieldValues, SCItem buttonItem) + private Guid CreateSubmitActionItem(string metadataTemplateName, string destItemName, Dictionary destFieldValues, SCItem buttonItem) { var metadataTemplate = _metadataProvider.GetItemMetadataByTemplateName(metadataTemplateName); @@ -339,7 +382,37 @@ private void CreateItem(string metadataTemplateName, string destItemName, Dictio metadataTemplate.fields.newFields.First(field => field.destFieldId == destFieldValue.Key).value = destFieldValue.Value; } // Create item - WriteNewItem(metadataTemplate.destTemplateId, submitActionsFolder, destItemName, metadataTemplate); + return WriteNewItem(metadataTemplate.destTemplateId, submitActionsFolder, destItemName, metadataTemplate); + } + + private Guid CreateEmailAddressItem(string metadataTemplateName, string destItemName, + Dictionary destFieldValues) + { + var metadataTemplate = _metadataProvider.GetItemMetadataByTemplateName(metadataTemplateName); + + // Create Email Address Senders Folder (not in SQL anymore) with dummy field + var addressSendersFolder = new SCItem() + { + ID = Guid.Parse(EmailAddressConstants.EmailAddressSendersFolderId), + Fields = new List() + { + new SCField() + { + Language = "en", + Version = 1 + } + } + }; + + + + foreach (var destFieldValue in destFieldValues) + { + metadataTemplate.fields.newFields.First(field => field.destFieldId == destFieldValue.Key).value = destFieldValue.Value; + } + + // Create item + return WriteNewItem(metadataTemplate.destTemplateId, addressSendersFolder, destItemName, metadataTemplate); } private bool ConvertSourceFieldToSubmitActionItem(SCItem form, Guid sourceFieldId, @@ -353,16 +426,16 @@ private bool ConvertSourceFieldToSubmitActionItem(SCItem form, Guid sourceFieldI if (sourceFieldToConvert == null || sourceFieldToConvert.Value == sourceFieldValue) { - CreateItem("SubmitActionDefinition", destItemName, destFieldValues, buttonItem); + CreateSubmitActionItem("SubmitActionDefinition", destItemName, destFieldValues, buttonItem); return true; } return false; } - private void ConvertFieldsToSubmitActionItem(string destItemName, Dictionary destFieldValues, SCItem buttonItem) + private Guid ConvertFieldsToSubmitActionItem(string destItemName, Dictionary destFieldValues, SCItem buttonItem) { - CreateItem("SubmitActionDefinition", destItemName, destFieldValues, buttonItem); + return CreateSubmitActionItem("SubmitActionDefinition", destItemName, destFieldValues, buttonItem); } } } diff --git a/src/WFFM.ConversionTool.Library/Models/Form/SendEmailAction.cs b/src/WFFM.ConversionTool.Library/Models/Form/SendEmailAction.cs new file mode 100644 index 0000000..fa3f42d --- /dev/null +++ b/src/WFFM.ConversionTool.Library/Models/Form/SendEmailAction.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WFFM.ConversionTool.Library.Models.Form +{ + public class SendEmailAction + { + public string from { get; set; } + public string to { get; set; } + public string cc { get; set; } + public string bcc { get; set; } + public string subject { get; set; } + public string body { get; set; } + } +} diff --git a/src/WFFM.ConversionTool.Library/Properties/AssemblyInfo.cs b/src/WFFM.ConversionTool.Library/Properties/AssemblyInfo.cs index 2285136..d5cc553 100644 --- a/src/WFFM.ConversionTool.Library/Properties/AssemblyInfo.cs +++ b/src/WFFM.ConversionTool.Library/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.0")] -[assembly: AssemblyFileVersion("1.4.0.0")] +[assembly: AssemblyVersion("1.5.0.0")] +[assembly: AssemblyFileVersion("1.5.0.0")] diff --git a/src/WFFM.ConversionTool.Library/Providers/MetadataProvider.cs b/src/WFFM.ConversionTool.Library/Providers/MetadataProvider.cs index 790e1ec..2766aef 100644 --- a/src/WFFM.ConversionTool.Library/Providers/MetadataProvider.cs +++ b/src/WFFM.ConversionTool.Library/Providers/MetadataProvider.cs @@ -26,10 +26,7 @@ public MetadataProvider(AppSettings appSettings, IDestMasterRepository destMaste foreach (string filePath in _metadataFiles) { var metadataTemplate = GetItemMetadataByFilePath(filePath); - if (destMasterRepository.ItemExists(metadataTemplate.destTemplateId)) - { - _metadataTemplates.Add(metadataTemplate); - } + _metadataTemplates.Add(metadataTemplate); } } diff --git a/src/WFFM.ConversionTool.Library/WFFM.ConversionTool.Library.csproj b/src/WFFM.ConversionTool.Library/WFFM.ConversionTool.Library.csproj index ef27e0b..7082111 100644 --- a/src/WFFM.ConversionTool.Library/WFFM.ConversionTool.Library.csproj +++ b/src/WFFM.ConversionTool.Library/WFFM.ConversionTool.Library.csproj @@ -87,6 +87,7 @@ + @@ -107,6 +108,7 @@ + @@ -134,6 +136,7 @@ + @@ -172,6 +175,7 @@ + \ No newline at end of file diff --git a/src/WFFM.ConversionTool/AppSettings.json b/src/WFFM.ConversionTool/AppSettings.json index 49681fb..3662677 100644 --- a/src/WFFM.ConversionTool/AppSettings.json +++ b/src/WFFM.ConversionTool/AppSettings.json @@ -42,12 +42,12 @@ } ], "submitActions": [ - //{ - // "sourceSaveActionId": "{D4502A11-9417-4479-9F2A-485F45D2E2D0}", - // "destSubmitActionItemName": "Send Email", - // "destSubmitActionFieldValue": "{065C982A-BA27-45E6-BC9B-F2821D904021}", - // "destParametersConverterType": "WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction.Converters.SendEmailConverter, WFFM.ConversionTool.Extensions.SitecoreFormsSendEmailSubmitAction" - //} + { + "sourceSaveActionId": "{D4502A11-9417-4479-9F2A-485F45D2E2D0}", + "destSubmitActionItemName": "Send Email", + "destSubmitActionFieldValue": "{A082C3F9-D90F-4825-8A38-8D2BE7653FC0}", + "destParametersConverterType": "WFFM.ConversionTool.Library.Converters.SubmitActionConverters.SendEmailConverter, WFFM.ConversionTool.Library" + } ], "enableOnlyAnalysisByDefault": true, // Default value: true. If true, the console application executed without the 'convert' parameter will not migrate forms items and data in the destination databases. "metadataFolderRelativePath": "Metadata", diff --git a/src/WFFM.ConversionTool/Metadata/EmailAddress.json b/src/WFFM.ConversionTool/Metadata/EmailAddress.json new file mode 100644 index 0000000..42f96ab --- /dev/null +++ b/src/WFFM.ConversionTool/Metadata/EmailAddress.json @@ -0,0 +1,43 @@ +{ + "destTemplateId": "{DD91460C-D205-4D4B-8F87-D7980C8BA9F6}", + "destTemplateName": "Email Address", + "fields": { + "newFields": [ + { + "fieldType": "versioned", + "destFieldId": "{BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A}", // __Updated by + "value": "sitecore\\Admin" + }, + { + "fieldType": "versioned", + "destFieldId": "{5DD74568-4D4B-44C1-B513-0AF5F4CDA34F}", // __Created by + "value": "sitecore\\Admin" + }, + { + "fieldType": "versioned", + "destFieldId": "{8CDC337E-A112-42FB-BBB4-4143751E123F}", // __Revision + "valueType": "System.Guid" + }, + { + "fieldType": "versioned", + "destFieldId": "{25BED78C-4957-4165-998A-CA1B52F67497}", // __Created + "valueType": "System.DateTime" + }, + { + "fieldType": "versioned", + "destFieldId": "{52807595-0F8F-4B20-8D2A-CB71D28C6103}", // __Owner + "value": "sitecore\\Admin" + }, + { + "fieldType": "versioned", + "destFieldId": "{D9CF14B1-FA16-4BA6-9288-E8A174D4D522}", // __Updated + "valueType": "System.DateTime" + }, + { + "fieldType": "versioned", + "destFieldId": "{49DC3FF7-C17D-4574-B88E-2418DCE1315F}", // Value + "valueType": "System.String" + } + ] + } +} diff --git a/src/WFFM.ConversionTool/Program.cs b/src/WFFM.ConversionTool/Program.cs index 087dde7..aba2b61 100644 --- a/src/WFFM.ConversionTool/Program.cs +++ b/src/WFFM.ConversionTool/Program.cs @@ -62,7 +62,7 @@ static void Main(string[] args) System.Console.WriteLine(); System.Console.WriteLine(" ***********************************************************************"); System.Console.WriteLine(" * *"); - System.Console.WriteLine(" * WFFM Conversion Tool - v1.4.0 *"); + System.Console.WriteLine(" * WFFM Conversion Tool - v1.5.0 *"); System.Console.WriteLine(" * *"); System.Console.WriteLine(" ***********************************************************************"); System.Console.WriteLine(); diff --git a/src/WFFM.ConversionTool/Properties/AssemblyInfo.cs b/src/WFFM.ConversionTool/Properties/AssemblyInfo.cs index 048a4ab..4e714ef 100644 --- a/src/WFFM.ConversionTool/Properties/AssemblyInfo.cs +++ b/src/WFFM.ConversionTool/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.0")] -[assembly: AssemblyFileVersion("1.4.0.0")] +[assembly: AssemblyVersion("1.5.0.0")] +[assembly: AssemblyFileVersion("1.5.0.0")] diff --git a/src/WFFM.ConversionTool/WFFM.ConversionTool.csproj b/src/WFFM.ConversionTool/WFFM.ConversionTool.csproj index 5c8d80c..f11c66c 100644 --- a/src/WFFM.ConversionTool/WFFM.ConversionTool.csproj +++ b/src/WFFM.ConversionTool/WFFM.ConversionTool.csproj @@ -68,6 +68,9 @@ Always + + Always + Always