diff --git a/.gitignore b/.gitignore index 51405dd753..b6839b4e04 100644 --- a/.gitignore +++ b/.gitignore @@ -84,3 +84,4 @@ src/*.psess NDependOut/* *.ndproj QueryResult.htm +*.ndproj diff --git a/src/Umbraco.Core/Models/PropertyExtensions.cs b/src/Umbraco.Core/Models/PropertyExtensions.cs index 2ef594c8c2..ae01532c87 100644 --- a/src/Umbraco.Core/Models/PropertyExtensions.cs +++ b/src/Umbraco.Core/Models/PropertyExtensions.cs @@ -43,7 +43,7 @@ namespace Umbraco.Core.Models //This seems to fail during testing //SD: With the new null checks below, this shouldn't fail anymore. var dt = property.PropertyType.DataType(property.Id, dataTypeService); - if (dt != null && dt.Data != null && dt.Data.Value != null) + if (dt != null && dt.Data != null) { //We've already got the value for the property so we're going to give it to the // data type's data property so it doesn't go re-look up the value from the db again. diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs index 156eeab919..4c93fa70b2 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ContentRepository.cs @@ -360,19 +360,18 @@ namespace Umbraco.Core.Persistence.Repositories } } + //Look up (newest) entries by id in cmsDocument table to set newest = false + var documentDtos = Database.Fetch("WHERE nodeId = @Id AND newest = @IsNewest", new { Id = entity.Id, IsNewest = true }); + foreach (var documentDto in documentDtos) + { + var docDto = documentDto; + docDto.Newest = false; + Database.Update(docDto); + } + var contentVersionDto = dto.ContentVersionDto; if (shouldCreateNewVersion) { - //Look up (newest) entries by id in cmsDocument table to set newest = false - //NOTE: This is only relevant when a new version is created, which is why its done inside this if-statement. - var documentDtos = Database.Fetch("WHERE nodeId = @Id AND newest = @IsNewest", new { Id = entity.Id, IsNewest = true }); - foreach (var documentDto in documentDtos) - { - var docDto = documentDto; - docDto.Newest = false; - Database.Update(docDto); - } - //Create a new version - cmsContentVersion //Assumes a new Version guid and Version date (modified date) has been set Database.Insert(contentVersionDto); diff --git a/src/Umbraco.Tests/Models/DataValueSetterTests.cs b/src/Umbraco.Tests/Models/DataValueSetterTests.cs index db59217166..891c53dd0d 100644 --- a/src/Umbraco.Tests/Models/DataValueSetterTests.cs +++ b/src/Umbraco.Tests/Models/DataValueSetterTests.cs @@ -66,6 +66,7 @@ namespace Umbraco.Tests.Models var dataTypeId = Guid.NewGuid(); var dataTypeData = MockRepository.GenerateMock(); + dataTypeData .Stub(data => data.ToXMl(Arg.Is.Anything)) .Return(null) // you have to call Return() even though we're about to override it @@ -98,5 +99,18 @@ namespace Umbraco.Tests.Models ((IDataValueSetter)dataTypeData).AssertWasCalled(setter => setter.SetValue("Hello world", DataTypeDatabaseType.Nvarchar.ToString())); } + [TestCase(DataTypeDatabaseType.Nvarchar)] + [TestCase(DataTypeDatabaseType.Date)] + [TestCase(DataTypeDatabaseType.Integer)] + [TestCase(DataTypeDatabaseType.Ntext)] + public void DefaultData_SetValue_Ensures_Empty_String_When_Null_Value_Any_Data_Type(DataTypeDatabaseType type) + { + var defaultData = new DefaultData(MockRepository.GenerateMock()); + + ((IDataValueSetter)defaultData).SetValue(null, type.ToString()); + + Assert.AreEqual(string.Empty, defaultData.Value); + } + } } \ No newline at end of file diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasks.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasks.cs index c1c9f27a8a..9d9e65f151 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasks.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasks.cs @@ -101,8 +101,7 @@ namespace umbraco { //write out the template header sw.Write("@inherits "); - sw.Write(typeof(UmbracoViewPage<>).FullName.TrimEnd("`1")); - sw.Write(""); + sw.Write(typeof(UmbracoTemplatePage).FullName.TrimEnd("`1")); } public bool Delete() diff --git a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs index a974fda7c2..471fcc9479 100644 --- a/src/umbraco.cms/businesslogic/datatype/DefaultData.cs +++ b/src/umbraco.cms/businesslogic/datatype/DefaultData.cs @@ -65,6 +65,17 @@ namespace umbraco.cms.businesslogic.datatype /// void IDataValueSetter.SetValue(object val, string strDbType) { + //We need to ensure that val is not a null value, if it is then we'll convert this to an empty string. + //The reason for this is because by default the DefaultData.Value property returns an empty string when + // there is no value, this is based on the PropertyDataDto.GetValue return value which defaults to an + // empty string (which is called from this class's method LoadValueFromDatabase). + //Some legacy implementations of DefaultData are expecting an empty string when there is + // no value so we need to keep this consistent. + if (val == null) + { + val = string.Empty; + } + _value = val; //now that we've set our value, we can update our BaseDataType object with the correct values from the db //instead of making it query for itself. This is a peformance optimization enhancement.