Message: [TreePathUtils.GetUniqueNodeName]: The maximum number of tries to get a unique node name was reached. Please validate URL settings to make sure the restrictions aren't too strict. Exception type: System.Exception Stack trace: at CMS.DocumentEngine.TreePathUtils.GetUniqueNodeName(String nodeName, Int32 parentNodeId, Int32 currentNodeId, String className) at CMS.DocumentEngine.TreeNode.InsertNode(TreeNode parent) at CMS.DocumentEngine.TreeNode.Insert(TreeNode parent, Boolean useDocumentHelper) at CMS.DocumentEngine.DocumentHelper.InsertDocument(TreeNode node, TreeNode parentNode, TreeProvider tree, Boolean allowCheckOut)
SELECT NodeClassID,* FROM dbo.CMS_Tree
WHERE NodeName LIKE '%am%'
ORDER BY NodeID DESC
SELECT ClassNodeNameSource,* FROM dbo.CMS_Class
WHERE ClassDisplayName LIKE '%%' --class id is 2968
SELECT NodeClassID,* FROM dbo.CMS_Tree
WHERE NodeName LIKE '%am%'
ORDER BY NodeID DESC
public static string GetUniqueNodeName(string nodeName, int parentNodeId, int currentNodeId, string className)
{
// If name not specified, do not process
if (string.IsNullOrEmpty(nodeName))
{
return string.Empty;
}
// Ensure maximal length
nodeName = nodeName.Trim();
nodeName = EnsureMaxNodeNameLength(nodeName, className);
// There is only one root node, no need to check uniqueness
if (parentNodeId <= 0)
{
return nodeName;
}
// Prepare base name
var baseName = nodeName;
if (baseName.EndsWith(")", StringComparison.Ordinal))
{
baseName = Regex.Replace(baseName, "[ ](\\(\\d+\\))$", string.Empty);
if (baseName == string.Empty)
{
baseName = nodeName;
}
}
// Get candidates
var maxNameLength = GetMaxNameLength(className);
var searchName = TextHelper.LimitLength(baseName, maxNameLength - UNIQUE_SUFFIX_MAX_LENGTH, string.Empty);
var data = DocumentNodeDataInfoProvider.GetDocumentNodes()
.Distinct()
.Columns("NodeName")
.WhereEquals("NodeParentID", parentNodeId)
.WhereStartsWith("NodeName", searchName)
.WhereNotEquals("NodeID", currentNodeId)
// Linked documents have same node name as their originals
.WhereNull("NodeLinkedNodeID")
.Result;
// No candidates available, the node name is unique
if (DataHelper.DataSourceIsEmpty(data))
{
return nodeName;
}
var candidates = data.Tables[0];
var uniqueIndex = 1;
do
{
// Get matching duplicate
var match = candidates.Select($"NodeName = '{SqlHelper.EscapeQuotes(nodeName)}'");
if (match.Length == 0)
{
// If not match, consider as unique
return nodeName;
}
// Prepare next candidate
var uniqueString = $" ({uniqueIndex})";
// Get the available length for the name without the unique suffix
int availableLength = maxNameLength - uniqueString.Length;
// Trim the name if necessary
nodeName = (baseName.Length > availableLength) ? baseName.Substring(0, availableLength) : baseName;
// Ensure unique suffix
nodeName += uniqueString;
// Maximal number of attemps reached
if (uniqueIndex >= MAX_UNIQUE_INDEX)
{
throw new Exception("[TreePathUtils.GetUniqueNodeName]: The maximum number of tries to get a unique node name was reached. Please validate URL settings to make sure the restrictions aren't too strict.");
}
uniqueIndex++;
}
while (true);
}