Fixes the null PublishName problem, ensures the quey strings are not replaced when selecting a doc type

This commit is contained in:
Shannon
2018-05-02 15:35:26 +10:00
parent 9843f3a5fd
commit 6fe9c4d4df
4 changed files with 41 additions and 31 deletions

View File

@@ -207,20 +207,20 @@ namespace Umbraco.Core.Models
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullOrEmptyException(nameof(name));
//fixme - we always need to set the invariant values since these cannot be null! discuss http://issues.umbraco.org/issue/U4-11286
PublishName = name;
PublishDate = date;
if (culture == null)
{
PublishName = name;
PublishDate = date;
return;
if (culture != null)
{
// private method, assume that culture is valid
if (_publishInfos == null)
_publishInfos = new Dictionary<string, (string Name, DateTime Date)>(StringComparer.OrdinalIgnoreCase);
_publishInfos[culture] = (name, date);
}
// private method, assume that culture is valid
if (_publishInfos == null)
_publishInfos = new Dictionary<string, (string Name, DateTime Date)>(StringComparer.OrdinalIgnoreCase);
_publishInfos[culture] = (name, date);
}
/// <inheritdoc/>

View File

@@ -241,7 +241,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
if (entity.Template == null)
entity.Template = entity.ContentType.DefaultTemplate;
entity.Name = FormatInvariantNameValue(entity);
EnsureInvariantNameValues(entity, publishing);
// ensure unique name on the same level
entity.Name = EnsureUniqueNodeName(entity.ParentId, entity.Name);
@@ -309,7 +309,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
content.PublishedVersionId = content.VersionId;
contentVersionDto.Id = 0;
contentVersionDto.Current = true;
contentVersionDto.Text = content.Name;
contentVersionDto.Text = content.PublishName;
Database.Insert(contentVersionDto);
content.VersionId = contentVersionDto.Id;
@@ -420,7 +420,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
Database.Execute(Sql().Update<DocumentVersionDto>(u => u.Set(x => x.Published, false)).Where<DocumentVersionDto>(x => x.Id == content.PublishedVersionId));
}
entity.Name = FormatInvariantNameValue(entity);
EnsureInvariantNameValues(entity, publishing);
// ensure unique name on the same level
entity.Name = EnsureUniqueNodeName(entity.ParentId, entity.Name, entity.Id);
@@ -1080,33 +1080,38 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
#region Utilities
/// <summary>
/// This ensures that the Name property exists and validates if all names are null
/// This ensures that the Name/PublishName properties are filled in and validates if all names are null
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
private string FormatInvariantNameValue(IContent content)
private void EnsureInvariantNameValues(IContent content, bool publishing)
{
//fixme - if we are saving a variant, we current need to have the invariant name set too, discuss! http://issues.umbraco.org/issue/U4-11286
//NOTE - this doesn't deal with the PublishName since that is readonly, instead this scenario is dealt with in `Content.SetPublishInfos`
//validate
if (content.Name.IsNullOrWhiteSpace() && content.Names.Count == 0)
throw new InvalidOperationException("Cannot save content with empty name.");
throw new InvalidOperationException("Cannot save content with an empty name.");
if (publishing && content.PublishName.IsNullOrWhiteSpace() && content.PublishNames.Count == 0)
throw new InvalidOperationException("Cannot publish content with an empty name.");
//ensure the invariant Name
if (content.Name.IsNullOrWhiteSpace() && content.Names.Count > 0)
{
//if we are saving a variant, we current need to have the invariant name set too
//fixme - this needs to be discussed! http://issues.umbraco.org/issue/U4-11286
var defaultCulture = LanguageRepository.GetDefaultIsoCode();
if (!defaultCulture.IsNullOrWhiteSpace() && content.Names.TryGetValue(defaultCulture, out var cultureName))
{
return cultureName;
content.Name = cultureName;
}
else
{
//our only option is to take the first
return content.Names.First().Value;
content.Name = content.Names.First().Value;
}
}
return content.Name;
}
protected override string EnsureUniqueNodeName(int parentId, string nodeName, int id = 0)

View File

@@ -1147,7 +1147,8 @@ namespace Umbraco.Core
/// <param name="text">The text to filter.</param>
/// <returns>The safe url segment.</returns>
public static string ToUrlSegment(this string text)
{
{
if (string.IsNullOrWhiteSpace(text)) throw new ArgumentException("message", nameof(text));
return Current.ShortStringHelper.CleanStringForUrlSegment(text);
}
@@ -1158,7 +1159,10 @@ namespace Umbraco.Core
/// <param name="culture">The culture.</param>
/// <returns>The safe url segment.</returns>
public static string ToUrlSegment(this string text, CultureInfo culture)
{
{
if (string.IsNullOrWhiteSpace(text)) throw new ArgumentException("message", nameof(text));
if (culture == null) throw new ArgumentNullException(nameof(culture));
return Current.ShortStringHelper.CleanStringForUrlSegment(text, culture);
}

View File

@@ -29,9 +29,10 @@ function contentCreateController($scope,
}
function createBlank(docType) {
$location
.path("/content/content/edit/" + $scope.currentNode.id)
.search("doctype=" + docType.alias + "&create=true");
$location
.path("/content/content/edit/" + $scope.currentNode.id)
.search("doctype", docType.alias)
.search("create", true);
close();
}
@@ -69,4 +70,4 @@ angular.module("umbraco").controller("Umbraco.Editors.Content.CreateController",
angular.module("umbraco").value("blueprintConfig", {
skipSelect: false,
allowBlank: true
});
});