Merge branch '6.0.7' into 6.1.2
This commit is contained in:
@@ -27,6 +27,8 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
_contentTypeRepository = contentTypeRepository;
|
||||
_templateRepository = templateRepository;
|
||||
|
||||
EnsureUniqueNaming = true;
|
||||
}
|
||||
|
||||
public ContentRepository(IDatabaseUnitOfWork work, IRepositoryCacheProvider cache, IContentTypeRepository contentTypeRepository, ITemplateRepository templateRepository)
|
||||
@@ -34,8 +36,12 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
_contentTypeRepository = contentTypeRepository;
|
||||
_templateRepository = templateRepository;
|
||||
|
||||
EnsureUniqueNaming = true;
|
||||
}
|
||||
|
||||
public bool EnsureUniqueNaming { get; set; }
|
||||
|
||||
#region Overrides of RepositoryBase<IContent>
|
||||
|
||||
protected override IContent PerformGet(int id)
|
||||
@@ -180,6 +186,9 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
((Content)entity).AddingEntity();
|
||||
|
||||
//Ensure unique name on the same level
|
||||
entity.Name = EnsureUniqueNodeName(entity.ParentId, entity.Name);
|
||||
|
||||
var factory = new ContentFactory(NodeObjectTypeId, entity.Id);
|
||||
var dto = factory.BuildDto(entity);
|
||||
|
||||
@@ -260,6 +269,9 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
entity.UpdateDate = DateTime.Now;
|
||||
}
|
||||
|
||||
//Ensure unique name on the same level
|
||||
entity.Name = EnsureUniqueNodeName(entity.ParentId, entity.Name, entity.Id);
|
||||
|
||||
//Look up parent to get and set the correct Path and update SortOrder if ParentId has changed
|
||||
if (((ICanBeDirty)entity).IsPropertyDirty("ParentId"))
|
||||
{
|
||||
@@ -489,5 +501,77 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
|
||||
return new PropertyCollection(properties);
|
||||
}
|
||||
|
||||
private string EnsureUniqueNodeName(int parentId, string nodeName, int id = 0)
|
||||
{
|
||||
if (EnsureUniqueNaming == false)
|
||||
return nodeName;
|
||||
|
||||
var sql = new Sql();
|
||||
sql.Select("*")
|
||||
.From<NodeDto>()
|
||||
.Where<NodeDto>(x => x.ParentId == parentId && x.Text.StartsWith(nodeName));
|
||||
|
||||
int uniqueNumber = 1;
|
||||
var currentName = nodeName;
|
||||
|
||||
var dtos = Database.Fetch<NodeDto>(sql);
|
||||
if (dtos.Any())
|
||||
{
|
||||
var results = dtos.OrderBy(x => x.Text, new SimilarNodeNameComparer());
|
||||
foreach (var dto in results)
|
||||
{
|
||||
if(id != 0 && id == dto.NodeId) continue;
|
||||
|
||||
if (dto.Text.ToLowerInvariant().Equals(currentName.ToLowerInvariant()))
|
||||
{
|
||||
currentName = nodeName + string.Format(" ({0})", uniqueNumber);
|
||||
uniqueNumber++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return currentName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Comparer that takes into account the duplicate index of a node name
|
||||
/// This is needed as a normal alphabetic sort would go Page (1), Page (10), Page (2) etc.
|
||||
/// </summary>
|
||||
private class SimilarNodeNameComparer : IComparer<string>
|
||||
{
|
||||
public int Compare(string x, string y)
|
||||
{
|
||||
if (x.LastIndexOf(')') == x.Length - 1 && y.LastIndexOf(')') == y.Length - 1)
|
||||
{
|
||||
if (x.ToLower().Substring(0, x.LastIndexOf('(')) == y.ToLower().Substring(0, y.LastIndexOf('(')))
|
||||
{
|
||||
int xDuplicateIndex = ExtractDuplicateIndex(x);
|
||||
int yDuplicateIndex = ExtractDuplicateIndex(y);
|
||||
|
||||
if (xDuplicateIndex != 0 && yDuplicateIndex != 0)
|
||||
{
|
||||
return xDuplicateIndex.CompareTo(yDuplicateIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return String.Compare(x.ToLower(), y.ToLower(), StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private int ExtractDuplicateIndex(string text)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
if (text.LastIndexOf('(') != -1 && text.LastIndexOf('(') < text.Length - 2)
|
||||
{
|
||||
int startPos = text.LastIndexOf('(') + 1;
|
||||
int length = text.Length - 1 - startPos;
|
||||
|
||||
int.TryParse(text.Substring(startPos, length), out index);
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ namespace Umbraco.Core.Persistence
|
||||
uow,
|
||||
RuntimeCacheProvider.Current,
|
||||
CreateContentTypeRepository(uow),
|
||||
CreateTemplateRepository(uow));
|
||||
CreateTemplateRepository(uow)) { EnsureUniqueNaming = Umbraco.Core.Configuration.UmbracoSettings.EnsureUniqueNaming };
|
||||
}
|
||||
|
||||
public virtual IContentTypeRepository CreateContentTypeRepository(IDatabaseUnitOfWork uow)
|
||||
|
||||
@@ -12,7 +12,8 @@ namespace umbraco.ActionHandlers
|
||||
/// It ensures that new content nodes gets a unique name, and thereby avoiding conflictiong URLs.
|
||||
/// It can be disabled in the umbracoSettings.config file.
|
||||
/// </summary>
|
||||
public class umbEnsureUniqueName : umbraco.BusinessLogic.Actions.IActionHandler
|
||||
[Obsolete("This handler is no longer used")]
|
||||
public class umbEnsureUniqueName : IActionHandler
|
||||
{
|
||||
public umbEnsureUniqueName()
|
||||
{
|
||||
@@ -82,7 +83,7 @@ namespace umbraco.ActionHandlers
|
||||
/// <returns></returns>
|
||||
public interfaces.IAction[] ReturnActions()
|
||||
{
|
||||
interfaces.IAction[] _retVal = { ActionNew.Instance };
|
||||
interfaces.IAction[] _retVal = { };
|
||||
return _retVal;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Reflection;
|
||||
using umbraco.BasePages;
|
||||
using umbraco.BusinessLogic.Utils;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.cms.businesslogic.workflow;
|
||||
using umbraco.interfaces;
|
||||
|
||||
namespace umbraco.BusinessLogic.Actions
|
||||
@@ -20,6 +13,7 @@ namespace umbraco.BusinessLogic.Actions
|
||||
/// <example>
|
||||
///
|
||||
/// </example>
|
||||
[Obsolete("Legacy! Use events instead")]
|
||||
public interface IActionHandler
|
||||
{
|
||||
bool Execute(Document documentObject, IAction action);
|
||||
|
||||
@@ -632,6 +632,7 @@ namespace umbraco.cms.businesslogic.member
|
||||
poco.Integer = property.Value != null && string.IsNullOrEmpty(property.Value.ToString())
|
||||
? 0
|
||||
: Convert.ToInt32(property.Value);
|
||||
: Convert.ToInt32(property.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user