Skip to content

Commit

Permalink
Merge pull request #11328 from umbraco/v9/feature/add-notifcation-for…
Browse files Browse the repository at this point in the history
…-url-collision

Add notifcation when publishing varying culture without domains configured
  • Loading branch information
Zeegaan authored Oct 15, 2021
2 parents 5fe30c7 + 48003e0 commit ee6abde
Show file tree
Hide file tree
Showing 16 changed files with 827 additions and 20 deletions.
14 changes: 11 additions & 3 deletions src/Umbraco.Core/Extensions/ContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;

Expand Down Expand Up @@ -165,7 +165,15 @@ public static ContentStatus GetStatus(this IContent content, string culture = nu
return ContentStatus.Unpublished;
}


/// <summary>
/// Gets a collection containing the ids of all ancestors.
/// </summary>
/// <param name="content"><see cref="IContent"/> to retrieve ancestors for</param>
/// <returns>An Enumerable list of integer ids</returns>
public static IEnumerable<int> GetAncestorIds(this IContent content) =>
content.Path.Split(Constants.CharArrays.Comma)
.Where(x => x != Constants.System.RootString && x != content.Id.ToString(CultureInfo.InvariantCulture)).Select(s =>
int.Parse(s, CultureInfo.InvariantCulture));

#endregion

Expand Down
16 changes: 9 additions & 7 deletions src/Umbraco.Infrastructure/Services/Implement/ContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,18 +531,20 @@ public IEnumerable<IContent> GetAncestors(int id)
public IEnumerable<IContent> GetAncestors(IContent content)
{
//null check otherwise we get exceptions
if (content.Path.IsNullOrWhiteSpace()) return Enumerable.Empty<IContent>();
if (content.Path.IsNullOrWhiteSpace())
{
return Enumerable.Empty<IContent>();
}

var rootId = Cms.Core.Constants.System.RootString;
var ids = content.Path.Split(Constants.CharArrays.Comma)
.Where(x => x != rootId && x != content.Id.ToString(CultureInfo.InvariantCulture)).Select(s =>
int.Parse(s, CultureInfo.InvariantCulture)).ToArray();
var ids = content.GetAncestorIds().ToArray();
if (ids.Any() == false)
{
return new List<IContent>();
}

using (var scope = ScopeProvider.CreateScope(autoComplete: true))
using (IScope scope = ScopeProvider.CreateScope(autoComplete: true))
{
scope.ReadLock(Cms.Core.Constants.Locks.ContentTree);
scope.ReadLock(Constants.Locks.ContentTree);
return _documentRepository.GetMany(ids);
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/Umbraco.Tests.Common/Builders/ContentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Umbraco.Cms.Tests.Common.Builders
public class ContentBuilder
: BuilderBase<Content>,
IBuildContentTypes,
IBuildContentCultureInfosCollection,
IWithIdBuilder,
IWithKeyBuilder,
IWithParentIdBuilder,
Expand All @@ -31,6 +32,7 @@ public class ContentBuilder
IWithPropertyValues
{
private ContentTypeBuilder _contentTypeBuilder;
private ContentCultureInfosCollectionBuilder _contentCultureInfosCollectionBuilder;
private GenericDictionaryBuilder<ContentBuilder, string, object> _propertyDataBuilder;

private int? _id;
Expand All @@ -48,6 +50,7 @@ public class ContentBuilder
private bool? _trashed;
private CultureInfo _cultureInfo;
private IContentType _contentType;
private ContentCultureInfosCollection _contentCultureInfosCollection;
private readonly IDictionary<string, string> _cultureNames = new Dictionary<string, string>();
private object _propertyValues;
private string _propertyValuesCulture;
Expand All @@ -73,6 +76,14 @@ public ContentBuilder WithContentType(IContentType contentType)
return this;
}

public ContentBuilder WithContentCultureInfosCollection(
ContentCultureInfosCollection contentCultureInfosCollection)
{
_contentCultureInfosCollectionBuilder = null;
_contentCultureInfosCollection = contentCultureInfosCollection;
return this;
}

public ContentBuilder WithCultureName(string culture, string name = "")
{
if (string.IsNullOrWhiteSpace(name))
Expand Down Expand Up @@ -105,6 +116,14 @@ public GenericDictionaryBuilder<ContentBuilder, string, object> AddPropertyData(
return builder;
}

public ContentCultureInfosCollectionBuilder AddContentCultureInfosCollection()
{
_contentCultureInfosCollection = null;
var builder = new ContentCultureInfosCollectionBuilder(this);
_contentCultureInfosCollectionBuilder = builder;
return builder;
}

public override Content Build()
{
var id = _id ?? 0;
Expand Down Expand Up @@ -176,6 +195,13 @@ public override Content Build()
content.ResetDirtyProperties(false);
}

if (_contentCultureInfosCollection is not null || _contentCultureInfosCollectionBuilder is not null)
{
ContentCultureInfosCollection contentCultureInfos =
_contentCultureInfosCollection ?? _contentCultureInfosCollectionBuilder.Build();
content.PublishCultureInfos = contentCultureInfos;
}

return content;
}

Expand Down
45 changes: 45 additions & 0 deletions src/Umbraco.Tests.Common/Builders/ContentCultureInfosBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Tests.Common.Builders.Interfaces;

namespace Umbraco.Cms.Tests.Common.Builders
{
public class ContentCultureInfosBuilder : ChildBuilderBase<ContentCultureInfosCollectionBuilder, ContentCultureInfos>,
IWithNameBuilder,
IWithDateBuilder
{
private string _name;
private string _cultureIso;
private DateTime? _date;
public ContentCultureInfosBuilder(ContentCultureInfosCollectionBuilder parentBuilder) : base(parentBuilder)
{
}

public ContentCultureInfosBuilder WithCultureIso(string cultureIso)
{
_cultureIso = cultureIso;
return this;
}

public override ContentCultureInfos Build()
{
var name = _name ?? Guid.NewGuid().ToString();
var cultureIso = _cultureIso ?? "en-us";
DateTime date = _date ?? DateTime.Now;

return new ContentCultureInfos(cultureIso) { Name = name, Date = date };
}

public string Name
{
get => _name;
set => _name = value;
}

public DateTime? Date
{
get => _date;
set => _date = value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Tests.Common.Builders.Interfaces;

namespace Umbraco.Cms.Tests.Common.Builders
{
public class ContentCultureInfosCollectionBuilder : ChildBuilderBase<ContentBuilder, ContentCultureInfosCollection>, IBuildContentCultureInfosCollection
{
private readonly List<ContentCultureInfosBuilder> _cultureInfosBuilders;
public ContentCultureInfosCollectionBuilder(ContentBuilder parentBuilder) : base(parentBuilder) => _cultureInfosBuilders = new List<ContentCultureInfosBuilder>();

public ContentCultureInfosBuilder AddCultureInfos()
{
var builder = new ContentCultureInfosBuilder(this);
_cultureInfosBuilders.Add(builder);
return builder;
}

public override ContentCultureInfosCollection Build()
{
if (_cultureInfosBuilders.Count < 1)
{
throw new InvalidOperationException("You must add at least one culture infos to the collection builder");
}
var cultureInfosCollection = new ContentCultureInfosCollection();

foreach (ContentCultureInfosBuilder cultureInfosBuilder in _cultureInfosBuilders)
{
cultureInfosCollection.Add(cultureInfosBuilder.Build());
}

return cultureInfosCollection;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,5 +234,11 @@ public static T WithPropertyValues<T>(this T builder, object propertyValues, str
builder.PropertyValuesSegment = segment;
return builder;
}

public static T WithDate<T>(this T builder, DateTime date) where T : IWithDateBuilder
{
builder.Date = date;
return builder;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces
{
public interface IBuildContentCultureInfosCollection
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Umbraco.Cms.Tests.Common.Builders.Interfaces
{
public interface IWithDateBuilder
{
DateTime? Date { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Umbraco.Tests.Integration/AssemblyAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using NUnit.Framework;

[assembly: SetCulture("en-US")]
[assembly: SetUICulture("en-US")]
Loading

0 comments on commit ee6abde

Please sign in to comment.