Skip to content

Commit ee6abde

Browse files
authored
Merge pull request #11328 from umbraco/v9/feature/add-notifcation-for-url-collision
Add notifcation when publishing varying culture without domains configured
2 parents 5fe30c7 + 48003e0 commit ee6abde

File tree

16 files changed

+827
-20
lines changed

16 files changed

+827
-20
lines changed

src/Umbraco.Core/Extensions/ContentExtensions.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Globalization;
67
using System.IO;
78
using System.Linq;
89
using System.Xml.Linq;
10+
using Umbraco.Cms.Core;
911
using Umbraco.Cms.Core.IO;
1012
using Umbraco.Cms.Core.Models;
1113
using Umbraco.Cms.Core.Models.Membership;
12-
using Umbraco.Cms.Core.Models.PublishedContent;
1314
using Umbraco.Cms.Core.PropertyEditors;
14-
using Umbraco.Cms.Core.Serialization;
1515
using Umbraco.Cms.Core.Services;
1616
using Umbraco.Cms.Core.Strings;
1717

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

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

170178
#endregion
171179

src/Umbraco.Infrastructure/Services/Implement/ContentService.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -531,18 +531,20 @@ public IEnumerable<IContent> GetAncestors(int id)
531531
public IEnumerable<IContent> GetAncestors(IContent content)
532532
{
533533
//null check otherwise we get exceptions
534-
if (content.Path.IsNullOrWhiteSpace()) return Enumerable.Empty<IContent>();
534+
if (content.Path.IsNullOrWhiteSpace())
535+
{
536+
return Enumerable.Empty<IContent>();
537+
}
535538

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

543-
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
545+
using (IScope scope = ScopeProvider.CreateScope(autoComplete: true))
544546
{
545-
scope.ReadLock(Cms.Core.Constants.Locks.ContentTree);
547+
scope.ReadLock(Constants.Locks.ContentTree);
546548
return _documentRepository.GetMany(ids);
547549
}
548550
}

src/Umbraco.Tests.Common/Builders/ContentBuilder.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Umbraco.Cms.Tests.Common.Builders
1616
public class ContentBuilder
1717
: BuilderBase<Content>,
1818
IBuildContentTypes,
19+
IBuildContentCultureInfosCollection,
1920
IWithIdBuilder,
2021
IWithKeyBuilder,
2122
IWithParentIdBuilder,
@@ -31,6 +32,7 @@ public class ContentBuilder
3132
IWithPropertyValues
3233
{
3334
private ContentTypeBuilder _contentTypeBuilder;
35+
private ContentCultureInfosCollectionBuilder _contentCultureInfosCollectionBuilder;
3436
private GenericDictionaryBuilder<ContentBuilder, string, object> _propertyDataBuilder;
3537

3638
private int? _id;
@@ -48,6 +50,7 @@ public class ContentBuilder
4850
private bool? _trashed;
4951
private CultureInfo _cultureInfo;
5052
private IContentType _contentType;
53+
private ContentCultureInfosCollection _contentCultureInfosCollection;
5154
private readonly IDictionary<string, string> _cultureNames = new Dictionary<string, string>();
5255
private object _propertyValues;
5356
private string _propertyValuesCulture;
@@ -73,6 +76,14 @@ public ContentBuilder WithContentType(IContentType contentType)
7376
return this;
7477
}
7578

79+
public ContentBuilder WithContentCultureInfosCollection(
80+
ContentCultureInfosCollection contentCultureInfosCollection)
81+
{
82+
_contentCultureInfosCollectionBuilder = null;
83+
_contentCultureInfosCollection = contentCultureInfosCollection;
84+
return this;
85+
}
86+
7687
public ContentBuilder WithCultureName(string culture, string name = "")
7788
{
7889
if (string.IsNullOrWhiteSpace(name))
@@ -105,6 +116,14 @@ public GenericDictionaryBuilder<ContentBuilder, string, object> AddPropertyData(
105116
return builder;
106117
}
107118

119+
public ContentCultureInfosCollectionBuilder AddContentCultureInfosCollection()
120+
{
121+
_contentCultureInfosCollection = null;
122+
var builder = new ContentCultureInfosCollectionBuilder(this);
123+
_contentCultureInfosCollectionBuilder = builder;
124+
return builder;
125+
}
126+
108127
public override Content Build()
109128
{
110129
var id = _id ?? 0;
@@ -176,6 +195,13 @@ public override Content Build()
176195
content.ResetDirtyProperties(false);
177196
}
178197

198+
if (_contentCultureInfosCollection is not null || _contentCultureInfosCollectionBuilder is not null)
199+
{
200+
ContentCultureInfosCollection contentCultureInfos =
201+
_contentCultureInfosCollection ?? _contentCultureInfosCollectionBuilder.Build();
202+
content.PublishCultureInfos = contentCultureInfos;
203+
}
204+
179205
return content;
180206
}
181207

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using Umbraco.Cms.Core.Models;
3+
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
4+
5+
namespace Umbraco.Cms.Tests.Common.Builders
6+
{
7+
public class ContentCultureInfosBuilder : ChildBuilderBase<ContentCultureInfosCollectionBuilder, ContentCultureInfos>,
8+
IWithNameBuilder,
9+
IWithDateBuilder
10+
{
11+
private string _name;
12+
private string _cultureIso;
13+
private DateTime? _date;
14+
public ContentCultureInfosBuilder(ContentCultureInfosCollectionBuilder parentBuilder) : base(parentBuilder)
15+
{
16+
}
17+
18+
public ContentCultureInfosBuilder WithCultureIso(string cultureIso)
19+
{
20+
_cultureIso = cultureIso;
21+
return this;
22+
}
23+
24+
public override ContentCultureInfos Build()
25+
{
26+
var name = _name ?? Guid.NewGuid().ToString();
27+
var cultureIso = _cultureIso ?? "en-us";
28+
DateTime date = _date ?? DateTime.Now;
29+
30+
return new ContentCultureInfos(cultureIso) { Name = name, Date = date };
31+
}
32+
33+
public string Name
34+
{
35+
get => _name;
36+
set => _name = value;
37+
}
38+
39+
public DateTime? Date
40+
{
41+
get => _date;
42+
set => _date = value;
43+
}
44+
}
45+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Umbraco.Cms.Core.Models;
4+
using Umbraco.Cms.Tests.Common.Builders.Interfaces;
5+
6+
namespace Umbraco.Cms.Tests.Common.Builders
7+
{
8+
public class ContentCultureInfosCollectionBuilder : ChildBuilderBase<ContentBuilder, ContentCultureInfosCollection>, IBuildContentCultureInfosCollection
9+
{
10+
private readonly List<ContentCultureInfosBuilder> _cultureInfosBuilders;
11+
public ContentCultureInfosCollectionBuilder(ContentBuilder parentBuilder) : base(parentBuilder) => _cultureInfosBuilders = new List<ContentCultureInfosBuilder>();
12+
13+
public ContentCultureInfosBuilder AddCultureInfos()
14+
{
15+
var builder = new ContentCultureInfosBuilder(this);
16+
_cultureInfosBuilders.Add(builder);
17+
return builder;
18+
}
19+
20+
public override ContentCultureInfosCollection Build()
21+
{
22+
if (_cultureInfosBuilders.Count < 1)
23+
{
24+
throw new InvalidOperationException("You must add at least one culture infos to the collection builder");
25+
}
26+
var cultureInfosCollection = new ContentCultureInfosCollection();
27+
28+
foreach (ContentCultureInfosBuilder cultureInfosBuilder in _cultureInfosBuilders)
29+
{
30+
cultureInfosCollection.Add(cultureInfosBuilder.Build());
31+
}
32+
33+
return cultureInfosCollection;
34+
}
35+
}
36+
}

src/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,5 +234,11 @@ public static T WithPropertyValues<T>(this T builder, object propertyValues, str
234234
builder.PropertyValuesSegment = segment;
235235
return builder;
236236
}
237+
238+
public static T WithDate<T>(this T builder, DateTime date) where T : IWithDateBuilder
239+
{
240+
builder.Date = date;
241+
return builder;
242+
}
237243
}
238244
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces
2+
{
3+
public interface IBuildContentCultureInfosCollection
4+
{
5+
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Umbraco.Cms.Tests.Common.Builders.Interfaces
4+
{
5+
public interface IWithDateBuilder
6+
{
7+
DateTime? Date { get; set; }
8+
}
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
using NUnit.Framework;
2+
3+
[assembly: SetCulture("en-US")]
4+
[assembly: SetUICulture("en-US")]

0 commit comments

Comments
 (0)