public ImportXml ( int zoneId, int appId, System.Xml.Linq.XDocument doc, bool leaveExistingValuesUntouched = true ) : bool | ||
zoneId | int | |
appId | int | |
doc | System.Xml.Linq.XDocument | |
leaveExistingValuesUntouched | bool | |
Résultat | bool |
internal static void ImportXmlSchemaOfVersion(string version, bool leaveOriginalsUntouched) { var userName = "******" + version; var xmlToImport = File.ReadAllText( HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/" + version + ".xml")); var xmlImport = new XmlImport("en-US", userName, true); var success = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport), leaveOriginalsUntouched); if (!success) { var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray()); throw new Exception("The 2sxc module upgrade to " + version + " failed: " + messages); } }
internal void Version080004() { logger.LogStep("08.00.04", "Start", false); var userName = "******"; // Fix AddressMask field in GPS settings content type var xmlToImport = File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/08.00.04.xml")); var xmlImport = new XmlImport("en-US", userName, true); var success = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport), false); // special note - change existing values if (!success) { var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray()); throw new Exception("The 2sxc module upgrade to 08.00.04 failed: " + messages); } logger.LogStep("08.00.02", "Done", false); }
protected void ImportFromStream(Stream importStream, bool isZip) { var messages = new List<ExportImportMessage>(); var success = false; if (isZip) { success = new ZipImport(ZoneId.Value, AppId.Value, UserInfo.IsSuperUser).ImportZip(importStream, Server, PortalSettings, messages); } else { var xml = new StreamReader(importStream).ReadToEnd(); var doc = XDocument.Parse(xml); var import = new XmlImport(PortalSettings.Current.DefaultLanguage, PortalSettings.Current.UserInfo.Username); success = import.ImportXml(ZoneId.Value, AppId.Value, doc); messages = import.ImportLog; } lstvSummary.DataSource = messages; lstvSummary.DataBind(); pnlSummary.Visible = true; pnlUpload.Visible = false; }
/// <summary> /// Imports a ZIP file (from stream) /// </summary> /// <param name="zipStream"></param> /// <param name="server"></param> /// <param name="portalSettings"></param> /// <param name="messages"></param> /// <returns></returns> public bool ImportZip(Stream zipStream, HttpServerUtility server, PortalSettings portalSettings, List <ExportImportMessage> messages, bool isAppImport) { if (!isAppImport && !_appId.HasValue) { throw new Exception("Could not import zip: No valid app id"); } if (messages == null) { messages = new List <ExportImportMessage>(); } var temporaryDirectory = server.MapPath(Path.Combine(SexyContent.TemporaryDirectory, System.Guid.NewGuid().ToString())); var success = true; try { if (!Directory.Exists(temporaryDirectory)) { Directory.CreateDirectory(temporaryDirectory); } // Extract ZIP archive to the temporary folder ExtractZipFile(zipStream, temporaryDirectory); string currentWorkingDir = temporaryDirectory; string[] baseDirectories = Directory.GetDirectories(currentWorkingDir); // Loop through each root-folder. For now only contains the "Apps" folder. foreach (var directoryPath in baseDirectories) { switch (Path.GetFileName(directoryPath)) { // Handle the App folder case "Apps": currentWorkingDir = Path.Combine(currentWorkingDir, "Apps"); // Loop through each app directory foreach (var appDirectory in Directory.GetDirectories(currentWorkingDir)) { var appId = new int?(); var xmlSearchPattern = isAppImport ? "App.xml" : "*.xml"; // Stores the number of the current xml file to process var xmlIndex = 0; // Import XML file(s) foreach (var xmlFileName in Directory.GetFiles(appDirectory, "*.xml")) { var fileContents = File.ReadAllText(Path.Combine(appDirectory, xmlFileName)); var import = new XmlImport(); if (isAppImport) { if (!import.IsCompatible(_zoneId, fileContents)) { throw new Exception("The " + (isAppImport ? "app" : "package") + " is not compatible with this version of 2sxc."); } var folder = XDocument.Parse(fileContents).Element("SexyContent") .Element("Entities").Elements("Entity").Single(e => e.Attribute("AttributeSetStaticName").Value == "2SexyContent-App") .Elements("Value").First(v => v.Attribute("Key").Value == "Folder").Attribute("Value").Value; var appPath = System.IO.Path.Combine(SexyContent.AppBasePath(PortalSettings.Current), folder); // Do not import (throw error) if the app directory already exists if (Directory.Exists(HttpContext.Current.Server.MapPath(appPath))) { throw new Exception("The app could not be installed because the app-folder '" + appPath + "' already exists. Please remove or rename the folder and install the app again."); } if (xmlIndex == 0) { // Handle PortalFiles folder string portalTempRoot = Path.Combine(appDirectory, "PortalFiles"); if (Directory.Exists(portalTempRoot)) { CopyAllFilesDnnPortal(portalTempRoot, "", false, messages); } } import.ImportApp(_zoneId, fileContents, out appId); } else { appId = _appId.Value; if (xmlIndex == 0 && import.IsCompatible(_zoneId, fileContents)) { // Handle PortalFiles folder string portalTempRoot = Path.Combine(appDirectory, "PortalFiles"); if (Directory.Exists(portalTempRoot)) { CopyAllFilesDnnPortal(portalTempRoot, "", false, messages); } } import.ImportXml(_zoneId, appId.Value, fileContents); } messages.AddRange(import.ImportLog); xmlIndex++; } var sexy = new SexyContent(_zoneId, appId.Value); // Copy all files in 2sexy folder to (portal file system) 2sexy folder string templateRoot = server.MapPath(SexyContent.GetTemplatePathRoot(SexyContent.TemplateLocations.PortalFileSystem, sexy.App)); string appTemplateRoot = Path.Combine(appDirectory, "2sexy"); if (Directory.Exists(appTemplateRoot)) { ImportExportHelpers.CopyAllFiles(appTemplateRoot, templateRoot, false, messages); } } // Reset CurrentWorkingDir currentWorkingDir = temporaryDirectory; break; } } } catch (Exception e) { // Add error message and return false messages.Add(new ExportImportMessage("Could not import the " + (isAppImport ? "app" : "package") + ": " + e.Message, ExportImportMessage.MessageTypes.Error)); Exceptions.LogException(e); success = false; } finally { try { // Finally delete the temporary directory Directory.Delete(temporaryDirectory, true); } catch (IOException e) { // The folder itself or files inside may be used by other processes. // Deleting the folder recursively will fail in such cases // If deleting is not possible, just leave the temporary folder as it is } } return(success); }
/// <summary> /// Imports a ZIP file (from stream) /// </summary> /// <param name="zipStream"></param> /// <param name="server"></param> /// <param name="portalSettings"></param> /// <param name="messages"></param> /// <returns></returns> public bool ImportZip(Stream zipStream, HttpServerUtility server, PortalSettings portalSettings, List<ExportImportMessage> messages) { if (messages == null) messages = new List<ExportImportMessage>(); var temporaryDirectory = server.MapPath(Path.Combine(Settings.TemporaryDirectory, Guid.NewGuid().ToString())); var success = true; try { if (!Directory.Exists(temporaryDirectory)) Directory.CreateDirectory(temporaryDirectory); // Extract ZIP archive to the temporary folder ExtractZipFile(zipStream, temporaryDirectory); var currentWorkingDir = temporaryDirectory; var baseDirectories = Directory.GetDirectories(currentWorkingDir); // Loop through each root-folder. For now only contains the "Apps" folder. foreach (var directoryPath in baseDirectories) { switch (Path.GetFileName(directoryPath)) { // Handle the App folder case "Apps": currentWorkingDir = Path.Combine(currentWorkingDir, "Apps"); // Loop through each app directory foreach (var appDirectory in Directory.GetDirectories(currentWorkingDir)) { var appId = new int?(); // Stores the number of the current xml file to process var xmlIndex = 0; // Import XML file(s) foreach (var xmlFileName in Directory.GetFiles(appDirectory, "*.xml")) { var fileContents = File.ReadAllText(Path.Combine(appDirectory, xmlFileName)); var doc = XDocument.Parse(fileContents); var import = new XmlImport(PortalSettings.Current.DefaultLanguage, Environment.Dnn7.UserIdentity.CurrentUserIdentityToken /*PortalSettings.Current.UserInfo.Username*/); if (!import.IsCompatible(doc)) throw new Exception("The app / package is not compatible with this version of 2sxc."); var isAppImport = doc.Element("SexyContent").Element("Header").Elements("App").Any() && doc.Element("SexyContent").Element("Header").Element("App").Attribute("Guid").Value != "Default"; if (!isAppImport && !_appId.HasValue) _appId = ((BaseCache) DataSource.GetCache(_zoneId)).ZoneApps[_zoneId].DefaultAppId; if (isAppImport) { var appConfig = XDocument.Parse(fileContents).Element("SexyContent") .Element("Entities") .Elements("Entity") .Single(e => e.Attribute("AttributeSetStaticName").Value == "2SexyContent-App"); #region Version Checks (new in 08.03.03) var reqVersionNode = appConfig.Elements("Value")?.FirstOrDefault(v => v.Attribute("Key").Value == "RequiredVersion")?.Attribute("Value")?.Value; var reqVersionNodeDnn = appConfig.Elements("Value")?.FirstOrDefault(v => v.Attribute("Key").Value == "RequiredDnnVersion")?.Attribute("Value")?.Value; CheckRequiredEnvironmentVersions(reqVersionNode, reqVersionNodeDnn); #endregion var folder = appConfig.Elements("Value").First(v => v.Attribute("Key").Value == "Folder").Attribute("Value").Value; var appPath = Path.Combine(AppHelpers.AppBasePath(PortalSettings.Current), folder); // Do not import (throw error) if the app directory already exists if(Directory.Exists(HttpContext.Current.Server.MapPath(appPath))) { throw new Exception("The app could not be installed because the app-folder '" + appPath + "' already exists. Please remove or rename the folder and install the app again."); } if (xmlIndex == 0) { // Handle PortalFiles folder var portalTempRoot = Path.Combine(appDirectory, "PortalFiles"); if (Directory.Exists(portalTempRoot)) CopyAllFilesDnnPortal(portalTempRoot, "", false, messages); } import.ImportApp(_zoneId, doc, out appId); } else { appId = _appId.Value; if (xmlIndex == 0 && import.IsCompatible(doc)) { // Handle PortalFiles folder var portalTempRoot = Path.Combine(appDirectory, "PortalFiles"); if (Directory.Exists(portalTempRoot)) CopyAllFilesDnnPortal(portalTempRoot, "", false, messages); } import.ImportXml(_zoneId, appId.Value, doc); } messages.AddRange(import.ImportLog); xmlIndex++; } //var sexy = new SxcInstance(_zoneId, appId.Value); var app = new App(_zoneId, appId.Value, PortalSettings.Current, false); // Copy all files in 2sexy folder to (portal file system) 2sexy folder var templateRoot = server.MapPath(Internal.TemplateManager.GetTemplatePathRoot(Settings.TemplateLocations.PortalFileSystem, app)); var appTemplateRoot = Path.Combine(appDirectory, "2sexy"); if (Directory.Exists(appTemplateRoot)) (new FileManager(appTemplateRoot)).CopyAllFiles(templateRoot, false, messages); } // Reset CurrentWorkingDir currentWorkingDir = temporaryDirectory; break; } } } catch (Exception e) { // Add error message and return false messages.Add(new ExportImportMessage("Could not import the app / package: " + e.Message, ExportImportMessage.MessageTypes.Error)); Exceptions.LogException(e); success = false; } finally { try { // Finally delete the temporary directory Directory.Delete(temporaryDirectory, true); } catch(Exception ex) when (ex is FormatException || ex is OverflowException) { // The folder itself or files inside may be used by other processes. // Deleting the folder recursively will fail in such cases // If deleting is not possible, just leave the temporary folder as it is } } return success; }
/// <summary> /// Imports a ZIP file (from stream) /// </summary> /// <param name="zipStream"></param> /// <param name="server"></param> /// <param name="portalSettings"></param> /// <param name="messages"></param> /// <returns></returns> public bool ImportZip(Stream zipStream, HttpServerUtility server, PortalSettings portalSettings, List <ExportImportMessage> messages) { if (messages == null) { messages = new List <ExportImportMessage>(); } var temporaryDirectory = server.MapPath(Path.Combine(Settings.TemporaryDirectory, Guid.NewGuid().ToString())); var success = true; try { if (!Directory.Exists(temporaryDirectory)) { Directory.CreateDirectory(temporaryDirectory); } // Extract ZIP archive to the temporary folder ExtractZipFile(zipStream, temporaryDirectory); var currentWorkingDir = temporaryDirectory; var baseDirectories = Directory.GetDirectories(currentWorkingDir); // Loop through each root-folder. For now only contains the "Apps" folder. foreach (var directoryPath in baseDirectories) { switch (Path.GetFileName(directoryPath)) { // Handle the App folder case "Apps": currentWorkingDir = Path.Combine(currentWorkingDir, "Apps"); // Loop through each app directory foreach (var appDirectory in Directory.GetDirectories(currentWorkingDir)) { var appId = new int?(); // Stores the number of the current xml file to process var xmlIndex = 0; // Import XML file(s) foreach (var xmlFileName in Directory.GetFiles(appDirectory, "*.xml")) { var fileContents = File.ReadAllText(Path.Combine(appDirectory, xmlFileName)); var doc = XDocument.Parse(fileContents); var import = new XmlImport(PortalSettings.Current.DefaultLanguage, Environment.Dnn7.UserIdentity.CurrentUserIdentityToken /*PortalSettings.Current.UserInfo.Username*/); if (!import.IsCompatible(doc)) { throw new Exception("The app / package is not compatible with this version of 2sxc."); } var isAppImport = doc.Element("SexyContent").Element("Header").Elements("App").Any() && doc.Element("SexyContent").Element("Header").Element("App").Attribute("Guid").Value != "Default"; if (!isAppImport && !_appId.HasValue) { _appId = ((BaseCache)DataSource.GetCache(_zoneId)).ZoneApps[_zoneId].DefaultAppId; } if (isAppImport) { var appConfig = XDocument.Parse(fileContents).Element("SexyContent") .Element("Entities") .Elements("Entity") .Single(e => e.Attribute("AttributeSetStaticName").Value == "2SexyContent-App"); #region Version Checks (new in 08.03.03) var reqVersionNode = appConfig.Elements("Value")?.FirstOrDefault(v => v.Attribute("Key").Value == "RequiredVersion")?.Attribute("Value")?.Value; var reqVersionNodeDnn = appConfig.Elements("Value")?.FirstOrDefault(v => v.Attribute("Key").Value == "RequiredDnnVersion")?.Attribute("Value")?.Value; CheckRequiredEnvironmentVersions(reqVersionNode, reqVersionNodeDnn); #endregion var folder = appConfig.Elements("Value").First(v => v.Attribute("Key").Value == "Folder").Attribute("Value").Value; var appPath = Path.Combine(AppHelpers.AppBasePath(PortalSettings.Current), folder); // Do not import (throw error) if the app directory already exists if (Directory.Exists(HttpContext.Current.Server.MapPath(appPath))) { throw new Exception("The app could not be installed because the app-folder '" + appPath + "' already exists. Please remove or rename the folder and install the app again."); } if (xmlIndex == 0) { // Handle PortalFiles folder var portalTempRoot = Path.Combine(appDirectory, "PortalFiles"); if (Directory.Exists(portalTempRoot)) { CopyAllFilesDnnPortal(portalTempRoot, "", false, messages); } } import.ImportApp(_zoneId, doc, out appId); } else { appId = _appId.Value; if (xmlIndex == 0 && import.IsCompatible(doc)) { // Handle PortalFiles folder var portalTempRoot = Path.Combine(appDirectory, "PortalFiles"); if (Directory.Exists(portalTempRoot)) { CopyAllFilesDnnPortal(portalTempRoot, "", false, messages); } } import.ImportXml(_zoneId, appId.Value, doc); } messages.AddRange(import.ImportLog); xmlIndex++; } //var sexy = new SxcInstance(_zoneId, appId.Value); var app = new App(_zoneId, appId.Value, PortalSettings.Current, false); // Copy all files in 2sexy folder to (portal file system) 2sexy folder var templateRoot = server.MapPath(Internal.TemplateManager.GetTemplatePathRoot(Settings.TemplateLocations.PortalFileSystem, app)); var appTemplateRoot = Path.Combine(appDirectory, "2sexy"); if (Directory.Exists(appTemplateRoot)) { (new FileManager(appTemplateRoot)).CopyAllFiles(templateRoot, false, messages); } } // Reset CurrentWorkingDir currentWorkingDir = temporaryDirectory; break; } } } catch (Exception e) { // Add error message and return false messages.Add(new ExportImportMessage("Could not import the app / package: " + e.Message, ExportImportMessage.MessageTypes.Error)); Exceptions.LogException(e); success = false; } finally { try { // Finally delete the temporary directory Directory.Delete(temporaryDirectory, true); } catch (Exception ex) when(ex is FormatException || ex is OverflowException) { // The folder itself or files inside may be used by other processes. // Deleting the folder recursively will fail in such cases // If deleting is not possible, just leave the temporary folder as it is } } return(success); }
public ImportResult ImportContent() { var result = new ImportResult(); var request = HttpContext.Current.Request; var allowSystemChanges = UserInfo.IsSuperUser; var appId = int.Parse(request["AppId"]); var zoneId = int.Parse(request["ZoneId"]); if (request.Files.Count > 0) { var file = request.Files[0]; if (file.FileName.EndsWith(".zip")) { // ZIP var zipImport = new ZipImport(zoneId, appId, PortalSettings.UserInfo.IsSuperUser); result.Succeeded = zipImport.ImportZip(file.InputStream, HttpContext.Current.Server, PortalSettings, result.Messages); } else { // XML using (var fileStreamReader = new StreamReader(file.InputStream)) { var xmlImport = new XmlImport(PortalSettings.DefaultLanguage, UserIdentity.CurrentUserIdentityToken, allowSystemChanges); var xmlDocument = XDocument.Parse(fileStreamReader.ReadToEnd()); result.Succeeded = xmlImport.ImportXml(zoneId, appId, xmlDocument); result.Messages = xmlImport.ImportLog; } } } return result; }
/// <summary> /// Add ContentTypes for ContentGroup and move all 2sxc data to EAV /// </summary> internal void Version070000() { logger.LogStep("07.00.00", "Start", false); var userName = "******"; #region 1. Import new ContentTypes for ContentGroups and Templates logger.LogStep("07.00.00", "1. Import new ContentTypes for ContentGroups and Templates", false); if (DataSource.GetCache(Constants.DefaultZoneId, Constants.MetaDataAppId).GetContentType("2SexyContent-Template") == null) { var xmlToImport = File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/07.00.00.xml")); //var xmlToImport = File.ReadAllText("../../../../Upgrade/07.00.00.xml"); var xmlImport = new XmlImport("en-US", userName, true); var success = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport)); if (!success) { var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray()); throw new Exception("The 2sxc module upgrade to 07.00.00 failed: " + messages); } } #endregion // 2. Move all existing data to the new ContentTypes - Append new IDs to old data (ensures that we can fix things that went wrong after upgrading the module) #region Prepare Templates logger.LogStep("07.00.00", "2. Move all existing data to the new ContentTypes - Append new IDs to old data (ensures that we can fix things that went wrong after upgrading the module)", false); var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString); var templates = new DataTable(); const string sqlCommand = @"SELECT ToSIC_SexyContent_Templates.TemplateID, ToSIC_SexyContent_Templates.PortalID, ToSIC_SexyContent_Templates.Name, ToSIC_SexyContent_Templates.Path, ToSIC_SexyContent_Templates.AttributeSetID, ToSIC_SexyContent_Templates.DemoEntityID, ToSIC_SexyContent_Templates.Script, ToSIC_SexyContent_Templates.IsFile, ToSIC_SexyContent_Templates.Type, ToSIC_SexyContent_Templates.IsHidden, ToSIC_SexyContent_Templates.Location, ToSIC_SexyContent_Templates.UseForList, ToSIC_SexyContent_Templates.UseForItem, ToSIC_SexyContent_Templates.SysCreated, ToSIC_SexyContent_Templates.SysCreatedBy, ToSIC_SexyContent_Templates.SysModified, ToSIC_SexyContent_Templates.SysModifiedBy, ToSIC_SexyContent_Templates.SysDeleted, ToSIC_SexyContent_Templates.SysDeletedBy, ToSIC_SexyContent_Templates.AppID, ToSIC_SexyContent_Templates.PublishData, ToSIC_SexyContent_Templates.StreamsToPublish, ToSIC_SexyContent_Templates.PipelineEntityID, ToSIC_SexyContent_Templates.ViewNameInUrl, ToSIC_SexyContent_Templates.Temp_PresentationTypeID, ToSIC_SexyContent_Templates.Temp_PresentationDemoEntityID, ToSIC_SexyContent_Templates.Temp_ListContentTypeID, ToSIC_SexyContent_Templates.Temp_ListContentDemoEntityID, ToSIC_SexyContent_Templates.Temp_ListPresentationTypeID, ToSIC_SexyContent_Templates.Temp_ListPresentationDemoEntityID, ToSIC_SexyContent_Templates.Temp_NewTemplateGuid, ToSIC_EAV_Apps.ZoneID, ToSIC_EAV_Entities_1.EntityGUID AS ContentDemoEntityGuid, ToSIC_EAV_Entities_2.EntityGUID AS PresentationDemoEntityGuid, ToSIC_EAV_Entities_3.EntityGUID AS ListContentDemoEntityGuid, ToSIC_EAV_Entities_4.EntityGUID AS ListPresentationDemoEntityGuid, ToSIC_EAV_Entities.EntityGUID AS PipelineEntityGuid FROM ToSIC_SexyContent_Templates INNER JOIN ToSIC_EAV_Apps ON ToSIC_SexyContent_Templates.AppID = ToSIC_EAV_Apps.AppID LEFT OUTER JOIN ToSIC_EAV_Entities ON ToSIC_SexyContent_Templates.PipelineEntityID = ToSIC_EAV_Entities.EntityID LEFT OUTER JOIN ToSIC_EAV_Entities AS ToSIC_EAV_Entities_3 ON ToSIC_SexyContent_Templates.Temp_ListContentDemoEntityID = ToSIC_EAV_Entities_3.EntityID LEFT OUTER JOIN ToSIC_EAV_Entities AS ToSIC_EAV_Entities_1 ON ToSIC_SexyContent_Templates.DemoEntityID = ToSIC_EAV_Entities_1.EntityID LEFT OUTER JOIN ToSIC_EAV_Entities AS ToSIC_EAV_Entities_2 ON ToSIC_SexyContent_Templates.Temp_PresentationDemoEntityID = ToSIC_EAV_Entities_2.EntityID LEFT OUTER JOIN ToSIC_EAV_Entities AS ToSIC_EAV_Entities_4 ON ToSIC_SexyContent_Templates.Temp_ListPresentationDemoEntityID = ToSIC_EAV_Entities_4.EntityID WHERE (ToSIC_SexyContent_Templates.SysDeleted IS NULL) AND ((SELECT COUNT(*) FROM ToSIC_EAV_Entities WHERE EntityGUID = ToSIC_SexyContent_Templates.Temp_NewTemplateGuid) = 0)"; var adapter = new SqlDataAdapter(sqlCommand, sqlConnection); adapter.SelectCommand.CommandTimeout = 3600; adapter.Fill(templates); var existingTemplates = templates.AsEnumerable().Select(t => { var templateId = (int)t["TemplateID"]; var zoneId = (int)t["ZoneID"]; var appId = (int)t["AppID"]; var cache = ((BaseCache)DataSource.GetCache(zoneId, appId)).GetContentTypes(); #region Helper Functions Func<int?, string> getContentTypeStaticName = contentTypeId => { if (!contentTypeId.HasValue || contentTypeId == 0) return ""; if (cache.Any(c => c.Value.AttributeSetId == contentTypeId)) return cache[contentTypeId.Value].StaticName; return ""; }; #endregion // Create anonymous object to validate the types var tempTemplate = new { TemplateID = templateId, Name = (string)t["Name"], Path = (string)t["Path"], NewEntityGuid = Guid.Parse((string)t["Temp_NewTemplateGuid"]), //AlreadyImported = t["Temp_NewTemplateGuid"] != DBNull.Value, ContentTypeId = getContentTypeStaticName(t["AttributeSetID"] == DBNull.Value ? new int?() : (int)t["AttributeSetID"]), ContentDemoEntityGuids = t["ContentDemoEntityGuid"] == DBNull.Value ? new List<Guid>() : new List<Guid> { (Guid)t["ContentDemoEntityGuid"] }, PresentationTypeId = getContentTypeStaticName((int)t["Temp_PresentationTypeID"]), PresentationDemoEntityGuids = t["PresentationDemoEntityGuid"] == DBNull.Value ? new List<Guid>() : new List<Guid> { (Guid)t["PresentationDemoEntityGuid"] }, ListContentTypeId = getContentTypeStaticName((int)t["Temp_ListContentTypeID"]), ListContentDemoEntityGuids = t["ListContentDemoEntityGuid"] == DBNull.Value ? new List<Guid>() : new List<Guid> { (Guid)t["ListContentDemoEntityGuid"] }, ListPresentationTypeId = getContentTypeStaticName((int)t["Temp_ListPresentationTypeID"]), ListPresentationDemoEntityGuids = t["ListPresentationDemoEntityGuid"] == DBNull.Value ? new List<Guid>() : new List<Guid> { (Guid)t["ListPresentationDemoEntityGuid"] }, Type = (string)t["Type"], IsHidden = (bool)t["IsHidden"], Location = (string)t["Location"], UseForList = (bool)t["UseForList"], AppId = appId, PublishData = (bool)t["PublishData"], StreamsToPublish = (string)t["StreamsToPublish"], PipelineEntityGuids = t["PipelineEntityGuid"] == DBNull.Value ? new List<Guid>() : new List<Guid> { (Guid)t["PipelineEntityGuid"] }, ViewNameInUrl = t["ViewNameInUrl"].ToString(), ZoneId = zoneId }; return tempTemplate; }).ToList(); #endregion #region Prepare ContentGroups logger.LogStep("07.00.00", "2. Prepare Content Groups", false); var contentGroupItemsTable = new DataTable(); const string sqlCommandContentGroups = @"SELECT DISTINCT ToSIC_SexyContent_ContentGroupItems.ContentGroupItemID, ToSIC_SexyContent_ContentGroupItems.ContentGroupID, ToSIC_SexyContent_ContentGroupItems.TemplateID, ToSIC_SexyContent_ContentGroupItems.SortOrder, ToSIC_SexyContent_ContentGroupItems.Type, ToSIC_SexyContent_ContentGroupItems.SysCreated, ToSIC_SexyContent_ContentGroupItems.SysCreatedBy, ToSIC_SexyContent_ContentGroupItems.SysModified, ToSIC_SexyContent_ContentGroupItems.SysModifiedBy, ToSIC_SexyContent_ContentGroupItems.SysDeleted, ToSIC_SexyContent_ContentGroupItems.SysDeletedBy, ToSIC_SexyContent_Templates.AppID, ToSIC_EAV_Apps.ZoneID, ToSIC_EAV_Entities.EntityGUID, ToSIC_SexyContent_ContentGroupItems.EntityID, ToSIC_SexyContent_ContentGroupItems.Temp_NewContentGroupGuid, ToSIC_SexyContent_Templates.Temp_NewTemplateGuid FROM ToSIC_SexyContent_Templates INNER JOIN ModuleSettings INNER JOIN ToSIC_SexyContent_ContentGroupItems ON ModuleSettings.SettingValue = ToSIC_SexyContent_ContentGroupItems.ContentGroupID ON ToSIC_SexyContent_Templates.TemplateID = ToSIC_SexyContent_ContentGroupItems.TemplateID INNER JOIN ToSIC_EAV_Apps ON ToSIC_SexyContent_Templates.AppID = ToSIC_EAV_Apps.AppID LEFT OUTER JOIN ToSIC_EAV_Entities ON ToSIC_SexyContent_ContentGroupItems.EntityID = ToSIC_EAV_Entities.EntityID WHERE (ToSIC_SexyContent_ContentGroupItems.SysDeleted IS NULL) AND (ModuleSettings.SettingName = N'ContentGroupID') AND ((SELECT COUNT(*) FROM ToSIC_EAV_Entities WHERE EntityGUID = ToSIC_SexyContent_ContentGroupItems.Temp_NewContentGroupGuid) = 0) ORDER BY SortOrder"; var adapterContentGroups = new SqlDataAdapter(sqlCommandContentGroups, sqlConnection); adapterContentGroups.SelectCommand.CommandTimeout = 3600; adapterContentGroups.Fill(contentGroupItemsTable); var contentGroupItems = contentGroupItemsTable.AsEnumerable().Select(c => new { ContentGroupId = (int)c["ContentGroupID"], NewContentGroupGuid = Guid.Parse((string)c["Temp_NewContentGroupGuid"]), EntityId = c["EntityID"] == DBNull.Value ? new int?() : (int)c["EntityID"], EntityGuid = c["EntityGUID"] == DBNull.Value ? (Guid?)null : ((Guid)c["EntityGUID"]), TemplateId = c["TemplateID"] == DBNull.Value ? new int?() : (int)c["TemplateID"], SortOrder = (int)c["SortOrder"], Type = (string)c["Type"], AppId = (int)c["AppID"], ZoneId = (int)c["ZoneID"], TemplateEntityGuids = new List<Guid>() { Guid.Parse((string)c["Temp_NewTemplateGuid"]) } }); var existingContentGroups = contentGroupItems.GroupBy(c => c.ContentGroupId, c => c, (id, items) => { var itemsList = items.ToList(); var contentGroup = new { NewEntityGuid = itemsList.First().NewContentGroupGuid, itemsList.First().AppId, itemsList.First().ZoneId, ContentGroupId = id, TemplateGuids = itemsList.First().TemplateEntityGuids, ContentGuids = itemsList.Where(p => p.Type == Constants.ContentKey).Select(p => p.EntityGuid).ToList(), PresentationGuids = itemsList.Where(p => p.Type == Constants.PresentationKey).Select(p => p.EntityGuid).ToList(), ListContentGuids = itemsList.Where(p => p.Type == "ListContent").Select(p => p.EntityGuid).ToList(), ListPresentationGuids = itemsList.Where(p => p.Type == "ListPresentation").Select(p => p.EntityGuid).ToList() }; return contentGroup; }).ToList(); #endregion // Import all entities logger.LogStep("07.00.00", "2. Import all entities", false); var apps = existingTemplates.Select(p => p.AppId).ToList(); apps.AddRange(existingContentGroups.Select(p => p.AppId)); apps = apps.Distinct().ToList(); foreach (var app in apps) { logger.LogStep("07.00.00", "Starting to migrate data for app " + app + "..."); var currentApp = app; var entitiesToImport = new List<ImportEntity>(); foreach (var t in existingTemplates.Where(t => t.AppId == currentApp)) { var entity = new ImportEntity { AttributeSetStaticName = "2SexyContent-Template", EntityGuid = t.NewEntityGuid, IsPublished = true, AssignmentObjectTypeId = ContentTypeHelpers.AssignmentObjectTypeIDDefault }; entity.Values = new Dictionary<string, List<IValueImportModel>> { {"Name", new List<IValueImportModel> {new ValueImportModel<string>(entity) { Value = t.Name }}}, {"Path", new List<IValueImportModel> {new ValueImportModel<string>(entity) { Value = t.Path }}}, {"ContentTypeStaticName", new List<IValueImportModel> {new ValueImportModel<string>(entity) { Value = t.ContentTypeId }}}, {"ContentDemoEntity", new List<IValueImportModel> {new ValueImportModel<List<Guid>>(entity) { Value = t.ContentDemoEntityGuids }}}, {"PresentationTypeStaticName", new List<IValueImportModel> {new ValueImportModel<string>(entity) { Value = t.PresentationTypeId }}}, {"PresentationDemoEntity", new List<IValueImportModel> {new ValueImportModel<List<Guid>>(entity) { Value = t.PresentationDemoEntityGuids }}}, {"ListContentTypeStaticName", new List<IValueImportModel> {new ValueImportModel<string>(entity) { Value = t.ListContentTypeId }}}, {"ListContentDemoEntity", new List<IValueImportModel> {new ValueImportModel<List<Guid>>(entity) { Value = t.ListContentDemoEntityGuids }}}, {"ListPresentationTypeStaticName", new List<IValueImportModel> {new ValueImportModel<string>(entity) { Value = t.ListPresentationTypeId }}}, {"ListPresentationDemoEntity", new List<IValueImportModel> {new ValueImportModel<List<Guid>>(entity) { Value = t.ListPresentationDemoEntityGuids }}}, {"Type", new List<IValueImportModel> {new ValueImportModel<string>(entity) { Value = t.Type }}}, {"IsHidden", new List<IValueImportModel> {new ValueImportModel<bool?>(entity) { Value = t.IsHidden }}}, {"Location", new List<IValueImportModel> {new ValueImportModel<string>(entity) { Value = t.Location }}}, {"UseForList", new List<IValueImportModel> {new ValueImportModel<bool?>(entity) { Value = t.UseForList }}}, {"PublishData", new List<IValueImportModel> {new ValueImportModel<bool?>(entity) { Value = t.PublishData }}}, {"StreamsToPublish", new List<IValueImportModel> {new ValueImportModel<string>(entity) { Value = t.StreamsToPublish }}}, {"Pipeline", new List<IValueImportModel> {new ValueImportModel<List<Guid>>(entity) { Value = t.PipelineEntityGuids }}}, {"ViewNameInUrl", new List<IValueImportModel> {new ValueImportModel<string>(entity) { Value = t.ViewNameInUrl }}} }; entitiesToImport.Add(entity); } foreach (var t in existingContentGroups.Where(t => t.AppId == app)) { var entity = new ImportEntity { AttributeSetStaticName = "2SexyContent-ContentGroup", EntityGuid = t.NewEntityGuid, IsPublished = true, AssignmentObjectTypeId = ContentTypeHelpers.AssignmentObjectTypeIDDefault }; entity.Values = new Dictionary<string, List<IValueImportModel>> { {"Template", new List<IValueImportModel> {new ValueImportModel<List<Guid>>(entity) { Value = t.TemplateGuids }}}, {Constants.ContentKey, new List<IValueImportModel> {new ValueImportModel<List<Guid?>>(entity) { Value = t.ContentGuids }}}, {Constants.PresentationKey, new List<IValueImportModel> {new ValueImportModel<List<Guid?>>(entity) { Value = t.PresentationGuids }}}, {"ListContent", new List<IValueImportModel> {new ValueImportModel<List<Guid?>>(entity) { Value = t.ListContentGuids }}}, {"ListPresentation", new List<IValueImportModel> {new ValueImportModel<List<Guid?>>(entity) { Value = t.ListPresentationGuids }}} }; entitiesToImport.Add(entity); } var import = new Eav.Import.Import(null, app, userName); import.RunImport(null, entitiesToImport); logger.LogStep("07.00.00", "Migrated data for app " + app); } logger.LogStep("07.00.00", "Done", false); }
internal void Version070303() { logger.LogStep("07.03.03", "Start", false); var userName = "******"; // 1. Import new Attributes for @All content type var xmlToImport = File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/07.03.03-01.xml")); var xmlImport = new XmlImport("en-US", userName, true); var success = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport)); if (!success) { var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray()); throw new Exception("The 2sxc module upgrade to 07.03.03-01 failed: " + messages); } // 2. Import ContentType-InputType and entities for it xmlToImport = File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/07.03.03-02.xml")); xmlImport = new XmlImport("en-US", userName, true); success = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport)); if (!success) { var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray()); throw new Exception("The 2sxc module upgrade to 07.03.03-02 failed: " + messages); } // 3. Hide all unneeded fields - all fields for string, number: all but "Number of Decimals", Minimum and Maximum xmlToImport = File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/07.03.03-03.xml")); xmlImport = new XmlImport("en-US", userName, true); success = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport), false); // special note - change existing values if (!success) { var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray()); throw new Exception("The 2sxc module upgrade to 07.03.03-03 failed: " + messages); } logger.LogStep("07.03.03", "Done", false); }
internal void Version070200() { logger.LogStep("07.02.00", "Start", false); var userName = "******"; // Import new ContentType for permissions if (DataSource.GetCache(Constants.DefaultZoneId, Constants.MetaDataAppId).GetContentType("|Config ToSic.Eav.DataSources.Paging") == null) { var xmlToImport = File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/07.02.00.xml")); //var xmlToImport = File.ReadAllText("../../../../Upgrade/07.00.00.xml"); var xmlImport = new XmlImport("en-US", userName, true); var success = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport)); if (!success) { var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray()); throw new Exception("The 2sxc module upgrade to 07.02.00 failed: " + messages); } } logger.LogStep("07.02.00", "Done", false); }
internal void Version080100() { logger.LogStep("08.01.00", "Start", false); var userName = "******"; // Add new content types and entities var xmlToImport = File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/08.01.00.xml")); var xmlImport = new XmlImport("en-US", userName, true); var success = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport), false); // special note - change existing values if (!success) { var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray()); throw new Exception("The 2sxc module upgrade to 08.01.00 failed: " + messages); } // Remove unneeded control key for template file editing RemoveModuleControls(new[] { "edittemplatefile" }); }
internal void Version080303() { logger.LogStep("08.03.03", "Start", false); var userName = "******"; // Change "Author" to "Owner" (permissions content type) var xmlToImport = File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/08.03.03.xml")); var xmlImport = new XmlImport("en-US", userName, true); var success = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport), false); // Overwrite existing values if (!success) { var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray()); throw new Exception("The 2sxc module upgrade to 08.03.03 failed: " + messages); } }
internal void Version080302() { logger.LogStep("08.03.02", "Start", false); var userName = "******"; // Add new content types and entities var xmlToImport = File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/08.03.02.xml")); var xmlImport = new XmlImport("en-US", userName, true); var success = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport), true); if (!success) { var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray()); throw new Exception("The 2sxc module upgrade to 08.03.02 failed: " + messages); } // 2016-03-13 2dm: disabled this rename again, because I tested it without and it seems the manifest works, so this could only lead to trouble one day //var desktopModuleNames = new[] { "2sxc", "2sxc-app" }; //// Update BusinessController class name in desktop module info //foreach (var d in desktopModuleNames) //{ // var dmi = DesktopModuleController.GetDesktopModuleByModuleName(d, -1); // dmi.BusinessControllerClass = "ToSic.SexyContent.Environment.Dnn7.DnnBusinessController"; // DesktopModuleController.SaveDesktopModule(dmi, false, true); //} }
private static void Version070003() { var userName = "******"; // Import new ContentType for permissions if (DataSource.GetCache(Constants.DefaultZoneId, Constants.MetaDataAppId).GetContentType("PermissionConfiguration") == null) { var xmlToImport = File.ReadAllText(HttpContext.Current.Server.MapPath("~/DesktopModules/ToSIC_SexyContent/Upgrade/07.00.03.xml")); //var xmlToImport = File.ReadAllText("../../../../Upgrade/07.00.00.xml"); var xmlImport = new XmlImport("en-US", userName, true); var success = xmlImport.ImportXml(Constants.DefaultZoneId, Constants.MetaDataAppId, XDocument.Parse(xmlToImport)); if (!success) { var messages = String.Join("\r\n- ", xmlImport.ImportLog.Select(p => p.Message).ToArray()); throw new Exception("The 2sxc module upgrade to 07.00.03 failed: " + messages); } } }