From fbc4820ab4a37a2164a25616bbb7988d6a414876 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 30 Jul 2018 23:23:01 +1000 Subject: [PATCH] Fixes migrations and updates the api usages for v8, more manual merging of files --- .../Migrations/Install/DatabaseDataCreator.cs | 3 +- .../AddRelationTypeForMediaFolderOnDelete.cs | 34 +++++--------- .../IncreaseLanguageIsoCodeColumnLength.cs | 23 ++++----- .../Upgrade/V_7_12_0/RenameTrueFalseField.cs | 16 ++----- .../V_7_12_0/SetDefaultTagsStorageType.cs | 47 ++++++++----------- .../Upgrade/V_7_12_0/UpdateUmbracoConsent.cs | 2 +- .../PropertyEditors/ValueListConfiguration.cs | 2 +- .../Services/Implement/FileService.cs | 31 ++++++------ src/Umbraco.Core/Umbraco.Core.csproj | 4 ++ 9 files changed, 72 insertions(+), 90 deletions(-) diff --git a/src/Umbraco.Core/Migrations/Install/DatabaseDataCreator.cs b/src/Umbraco.Core/Migrations/Install/DatabaseDataCreator.cs index 28e203c7b7..13352b0af0 100644 --- a/src/Umbraco.Core/Migrations/Install/DatabaseDataCreator.cs +++ b/src/Umbraco.Core/Migrations/Install/DatabaseDataCreator.cs @@ -288,7 +288,8 @@ namespace Umbraco.Core.Migrations.Install _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto { NodeId = -42, EditorAlias = Constants.PropertyEditors.Aliases.DropDownList, DbType = "Integer" }); _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto { NodeId = -43, EditorAlias = Constants.PropertyEditors.Aliases.CheckBoxList, DbType = "Nvarchar" }); _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto { NodeId = 1041, EditorAlias = Constants.PropertyEditors.Aliases.Tags, DbType = "Ntext", - Configuration = "{\"group\":\"default\"}" }); + Configuration = "{\"group\":\"default\", \"storageType\":\"Json\"}" + }); _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto { NodeId = 1043, EditorAlias = Constants.PropertyEditors.Aliases.ImageCropper, DbType = "Ntext" }); _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, new DataTypeDto { NodeId = Constants.DataTypes.DefaultContentListView, EditorAlias = Constants.PropertyEditors.Aliases.ListView, DbType = "Nvarchar", Configuration = "{\"pageSize\":100, \"orderBy\":\"updateDate\", \"orderDirection\":\"desc\", \"layouts\":" + layouts + ", \"includeProperties\":[{\"alias\":\"updateDate\",\"header\":\"Last edited\",\"isSystem\":1},{\"alias\":\"owner\",\"header\":\"Updated by\",\"isSystem\":1}]}" }); diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/AddRelationTypeForMediaFolderOnDelete.cs b/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/AddRelationTypeForMediaFolderOnDelete.cs index 9de051e725..baf4a9234e 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/AddRelationTypeForMediaFolderOnDelete.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/AddRelationTypeForMediaFolderOnDelete.cs @@ -1,38 +1,30 @@ using System; -using Umbraco.Core.Logging; -using Umbraco.Core.Models.Rdbms; -using Umbraco.Core.Persistence.DatabaseAnnotations; -using Umbraco.Core.Persistence.SqlSyntax; +using Umbraco.Core.Persistence.Dtos; -namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwelveZero +namespace Umbraco.Core.Migrations.Upgrade.V_7_12_0 { - [Migration("7.12.0", 0, Constants.System.UmbracoMigrationName)] public class AddRelationTypeForMediaFolderOnDelete : MigrationBase { - public AddRelationTypeForMediaFolderOnDelete(ISqlSyntaxProvider sqlSyntax, ILogger logger) - : base(sqlSyntax, logger) + + public AddRelationTypeForMediaFolderOnDelete(IMigrationContext context) : base(context) { } - public override void Up() + public override void Migrate() { var exists = Context.Database.FirstOrDefault("WHERE alias=@alias", new { alias = Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias }); if (exists == null) { - var relationTypeDto = new RelationTypeDto + Insert.IntoTable(Constants.DatabaseSchema.Tables.RelationType).Row(new { - Alias = Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias, - Name = Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteName, - ChildObjectType = Guid.Parse(Constants.ObjectTypes.MediaType), - ParentObjectType = Guid.Parse(Constants.ObjectTypes.MediaType), - Dual = false - }; - - Context.Database.Insert(relationTypeDto); + alias = Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias, + name = Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteName, + childObjectType = Constants.ObjectTypes.MediaType, + parentObjectType = Constants.ObjectTypes.MediaType, + dual = false + }).Do(); } } - public override void Down() - { } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/IncreaseLanguageIsoCodeColumnLength.cs b/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/IncreaseLanguageIsoCodeColumnLength.cs index 8a4a453cdf..302069855a 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/IncreaseLanguageIsoCodeColumnLength.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/IncreaseLanguageIsoCodeColumnLength.cs @@ -1,37 +1,32 @@ using Umbraco.Core.Logging; +using Umbraco.Core.Migrations; using Umbraco.Core.Persistence.SqlSyntax; namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwelveZero { - [Migration("7.12.0", 2, Constants.System.UmbracoMigrationName)] public class IncreaseLanguageIsoCodeColumnLength : MigrationBase { - public IncreaseLanguageIsoCodeColumnLength(ISqlSyntaxProvider sqlSyntax, ILogger logger) - : base(sqlSyntax, logger) + public IncreaseLanguageIsoCodeColumnLength(IMigrationContext context) : base(context) { } - public override void Up() + public override void Migrate() { - Execute.Code(database => - { - database.Execute("DROP INDEX [umbracoLanguage].[IX_umbracoLanguage_languageISOCode]"); - return null; - }); + Delete.Index("IX_umbracoLanguage_languageISOCode").OnTable("umbracoLanguage").Do(); Alter.Table("umbracoLanguage") .AlterColumn("languageISOCode") .AsString(14) - .Nullable(); + .Nullable() + .Do(); Create.Index("IX_umbracoLanguage_languageISOCode") .OnTable("umbracoLanguage") .OnColumn("languageISOCode") - .Unique(); + .Unique() + .Do(); } - public override void Down() - { - } + } } diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/RenameTrueFalseField.cs b/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/RenameTrueFalseField.cs index 4ff522bcf9..4022739ece 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/RenameTrueFalseField.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/RenameTrueFalseField.cs @@ -1,25 +1,19 @@ using Umbraco.Core.Logging; +using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Persistence.SqlSyntax; -namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwelveZero +namespace Umbraco.Core.Migrations.Upgrade.V_7_12_0 { - [Migration("7.12.0", 0, Constants.System.UmbracoMigrationName)] public class RenameTrueFalseField : MigrationBase { - public RenameTrueFalseField(ISqlSyntaxProvider sqlSyntax, ILogger logger) : base(sqlSyntax, logger) + public RenameTrueFalseField(IMigrationContext context) : base(context) { } - public override void Up() + public override void Migrate() { //rename the existing true/false field - Update.Table("umbracoNode").Set(new { text = "Checkbox" }).Where(new { id = -49 }); - } - - public override void Down() - { - //set the field back to true/false - Update.Table("umbracoNode").Set(new { text = "True/false" }).Where(new { id = -49 }); + Update.Table(NodeDto.TableName).Set(new { text = "Checkbox" }).Where(new { id = Constants.DataTypes.Boolean }).Do(); } } } diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/SetDefaultTagsStorageType.cs b/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/SetDefaultTagsStorageType.cs index 8e13fa1013..08598f1779 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/SetDefaultTagsStorageType.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/SetDefaultTagsStorageType.cs @@ -1,54 +1,47 @@ using System; using System.Linq; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Umbraco.Core.Logging; -using Umbraco.Core.Models.Rdbms; +using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.Persistence.SqlSyntax; -namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenTwelveZero +namespace Umbraco.Core.Migrations.Upgrade.V_7_12_0 { /// /// Set the default storageType for the tags datatype to "CSV" to ensure backwards compatibilty since the default is going to be JSON in new versions - /// - - [Migration("7.12.0", 1, Constants.System.UmbracoMigrationName)] - public class SetDefaultTagsStorageType: MigrationBase + /// + public class SetDefaultTagsStorageType : MigrationBase { - public SetDefaultTagsStorageType(ISqlSyntaxProvider sqlSyntax, ILogger logger) : base(sqlSyntax, logger) + public SetDefaultTagsStorageType(IMigrationContext context) : base(context) { } - public override void Up() + public override void Migrate() { if (Context?.Database == null) return; - + // We need to get all datatypes with an alias of "umbraco.tags" so we can loop over them and set the missing values if needed var datatypes = Context.Database.Fetch("SELECT * FROM cmsDataType"); - var tagsDataTypes = datatypes.Where(x => string.Equals(x.PropertyEditorAlias, Constants.PropertyEditors.TagsAlias, StringComparison.InvariantCultureIgnoreCase)); - var dataTypePreValues = Context.Database.Fetch("SELECT * FROM cmsDataTypePrevalues"); + var tagsDataTypes = datatypes.Where(x => string.Equals(x.EditorAlias, Constants.PropertyEditors.Aliases.Tags, StringComparison.InvariantCultureIgnoreCase)); foreach (var datatype in tagsDataTypes) { - // We need to check if the node has a "storageType" set - var result = dataTypePreValues.FirstOrDefault(x => - x.DataTypeNodeId == datatype.DataTypeId - && string.Equals(x.Alias, "storageType", StringComparison.InvariantCultureIgnoreCase)); + var dataTypePreValues = JsonConvert.DeserializeObject(datatype.Configuration); - // if the "storageType" has not been set we do so by adding a new row in the table for the nodid and set it - if (result == null) + // We need to check if the node has a "storageType" set + if (!dataTypePreValues.ContainsKey("storageType")) { - Insert.IntoTable("CmsDataTypePrevalues").Row(new - { - datatypeNodeId = datatype.DataTypeId, - value = "Csv", - sortOrder = 2, - alias = "storageType" - }); + dataTypePreValues["storageType"] = "Csv"; } + + Update.Table(Constants.DatabaseSchema.Tables.DataType) + .Set(new { config = JsonConvert.SerializeObject(dataTypePreValues) }) + .Where(new { nodeId = datatype.NodeId }) + .Do(); } } - public override void Down() - { - } + } } diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/UpdateUmbracoConsent.cs b/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/UpdateUmbracoConsent.cs index d8c6e145b1..942d32f83d 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/UpdateUmbracoConsent.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_7_12_0/UpdateUmbracoConsent.cs @@ -10,6 +10,6 @@ namespace Umbraco.Core.Migrations.Upgrade.V_7_12_0 : base(context) { } - public override void Migrate() { Alter.Table("umbracoConsent").AlterColumn("comment").AsString().Nullable(); } + public override void Migrate() { Alter.Table("umbracoConsent").AlterColumn("comment").AsString().Nullable().Do(); } } } diff --git a/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs b/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs index 23ea4547df..c5b8b723bd 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.PropertyEditors /// public class ValueListConfiguration { - [ConfigurationField("items", "Configure", "multivalues", Description = "Add and remove values for the list.")] + [ConfigurationField("items", "Configure", "multivalues", Description = "Add, remove or sort values for the list.")] public List Items { get; set; } = new List(); public class ValueListItem diff --git a/src/Umbraco.Core/Services/Implement/FileService.cs b/src/Umbraco.Core/Services/Implement/FileService.cs index 4b95a0c1c3..cf16e8be2b 100644 --- a/src/Umbraco.Core/Services/Implement/FileService.cs +++ b/src/Umbraco.Core/Services/Implement/FileService.cs @@ -344,7 +344,7 @@ namespace Umbraco.Core.Services.Implement // check that the template hasn't been created on disk before creating the content type // if it exists, set the new template content to the existing file content string content = GetViewContent(contentTypeAlias); - if (content.IsNullOrWhiteSpace() == false) + if (content != null) { template.Content = content; } @@ -369,26 +369,29 @@ namespace Umbraco.Core.Services.Implement return OperationResult.Attempt.Succeed(OperationResultType.Success, evtMsgs, template); } + /// + /// Create a new template, setting the content if a view exists in the filesystem + /// + /// + /// + /// + /// + /// public ITemplate CreateTemplateWithIdentity(string name, string content, ITemplate masterTemplate = null, int userId = 0) { + // file might already be on disk, if so grab the content to avoid overwriting var template = new Template(name, name) { - Content = content + Content = GetViewContent(name) ?? content }; - - // check that the template hasn't been created on disk before creating the content type - // if it exists, set the new template content to the existing file content - string existingContent = GetViewContent(template.Alias); - if (existingContent.IsNullOrWhiteSpace() == false) - { - template.Content = content; - } - + if (masterTemplate != null) { template.SetMasterTemplate(masterTemplate); } + SaveTemplate(template, userId); + return template; } @@ -681,11 +684,11 @@ namespace Umbraco.Core.Services.Implement if (fileName.IsNullOrWhiteSpace()) throw new ArgumentNullException(nameof(fileName)); - if (!fileName.EndsWith(".cshtml")) - fileName = string.Concat(fileName, ".cshtml"); + if (!fileName.EndsWith(".cshtml")) + fileName = $"{fileName}.cshtml"; var fs = _templateRepository.GetFileContentStream(fileName); - if (fs == null) return string.Empty; + if (fs == null) return null; using (var view = new StreamReader(fs)) { return view.ReadToEnd().Trim(); diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 3954267118..cc494fc471 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -313,6 +313,10 @@ + + + +