Skip to content

V15/fix/schedule variant notation #18669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: v15/dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public Attempt<CultureAndScheduleModel, ContentPublishingOperationStatus> Create
{
if (cultureAndScheduleRequestModel.Schedule is null || (cultureAndScheduleRequestModel.Schedule.PublishTime is null && cultureAndScheduleRequestModel.Schedule.UnpublishTime is null))
{
culturesToPublishImmediately.Add(cultureAndScheduleRequestModel.Culture ?? Constants.System.InvariantCulture); // API have `null` for invariant, but service layer has "*".
culturesToPublishImmediately.Add(cultureAndScheduleRequestModel.Culture ?? "*"); // API have `null` for invariant, but service layer has "*".
continue;
}

Expand All @@ -179,7 +179,7 @@ public Attempt<CultureAndScheduleModel, ContentPublishingOperationStatus> Create
}

contentScheduleCollection.Add(new ContentSchedule(
cultureAndScheduleRequestModel.Culture ?? Constants.System.InvariantCulture,
cultureAndScheduleRequestModel.Culture ?? "*",
cultureAndScheduleRequestModel.Schedule.PublishTime.Value.UtcDateTime,
ContentScheduleAction.Release));
}
Expand All @@ -204,7 +204,7 @@ public Attempt<CultureAndScheduleModel, ContentPublishingOperationStatus> Create
}

contentScheduleCollection.Add(new ContentSchedule(
cultureAndScheduleRequestModel.Culture ?? Constants.System.InvariantCulture,
cultureAndScheduleRequestModel.Culture ?? "*",
cultureAndScheduleRequestModel.Schedule.UnpublishTime.Value.UtcDateTime,
ContentScheduleAction.Expire));
}
Expand All @@ -226,8 +226,7 @@ public Attempt<List<CulturePublishScheduleModel>, ContentPublishingOperationStat
{
model.Add(new CulturePublishScheduleModel
{
Culture = cultureAndScheduleRequestModel.Culture
?? Constants.System.InvariantCulture // API have `null` for invariant, but service layer has "*".
Culture = cultureAndScheduleRequestModel.Culture ?? "*" // API have `null` for invariant, but service layer has "*".
});
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ Attempt<List<CulturePublishScheduleModel>, ContentPublishingOperationStatus> Cre
{
model.Add(new CulturePublishScheduleModel
{
Culture = cultureAndScheduleRequestModel.Culture
?? Constants.System.InvariantCulture
Culture = cultureAndScheduleRequestModel.Culture ?? "*"
});
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,5 @@ private void Map(ContentScheduleCollection source, DocumentResponseModel target,
}
}

private static bool IsInvariant(string? culture) => culture.IsNullOrWhiteSpace() || culture == Core.Constants.System.InvariantCulture;
private static bool IsInvariant(string? culture) => culture.IsNullOrWhiteSpace() || culture == string.Empty;
}
2 changes: 0 additions & 2 deletions src/Umbraco.Core/Constants-System.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,5 @@ public static class System
/// The DataDirectory placeholder.
/// </summary>
public const string DataDirectoryPlaceholder = "|DataDirectory|";

public const string InvariantCulture = "*";
}
}
2 changes: 1 addition & 1 deletion src/Umbraco.Core/Extensions/ContentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public static ContentStatus GetStatus(this IContent content, ContentScheduleColl

if (!content.ContentType.VariesByCulture())
{
culture = Constants.System.InvariantCulture;
culture = string.Empty;
}
else if (culture.IsNullOrWhiteSpace())
{
Expand Down
36 changes: 25 additions & 11 deletions src/Umbraco.Core/Models/ContentScheduleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public bool Equals(ContentScheduleCollection? other)
public static ContentScheduleCollection CreateWithEntry(DateTime? release, DateTime? expire)
{
var schedule = new ContentScheduleCollection();
schedule.Add(Constants.System.InvariantCulture, release, expire);
schedule.Add(string.Empty, release, expire);
return schedule;
}

Expand Down Expand Up @@ -98,7 +98,7 @@ public void Add(ContentSchedule schedule)
/// </summary>
/// <param name="releaseDate"></param>
/// <param name="expireDate"></param>
public bool Add(DateTime? releaseDate, DateTime? expireDate) => Add(Constants.System.InvariantCulture, releaseDate, expireDate);
public bool Add(DateTime? releaseDate, DateTime? expireDate) => Add(string.Empty, releaseDate, expireDate);

/// <summary>
/// Adds a new schedule for a culture
Expand Down Expand Up @@ -170,11 +170,10 @@ public void Remove(ContentSchedule change)
}
}

public void RemoveIfExists(string culture, ContentScheduleAction action)
internal void RemoveIfExists(string culture, ContentScheduleAction action)
{
ContentSchedule? changeToRemove = FullSchedule.FirstOrDefault(change =>
change.Culture == culture
&& change.Action == action);
ContentSchedule? changeToRemove = FullSchedule.FirstOrDefault(schedule =>
MatchingScheduleTakingIntoAccountDifferentInvariantNotations(schedule, culture, action));
if (changeToRemove is not null)
{
Remove(changeToRemove);
Expand All @@ -184,9 +183,8 @@ public void RemoveIfExists(string culture, ContentScheduleAction action)
public void AddOrUpdate(string culture, DateTime dateTime, ContentScheduleAction action)
{
// we need to remove the old one as ContentSchedule.Date is immutable
ContentSchedule? changeToRemove = FullSchedule.FirstOrDefault(change =>
change.Culture == culture
&& change.Action == action);
ContentSchedule? changeToRemove = FullSchedule.FirstOrDefault(schedule =>
MatchingScheduleTakingIntoAccountDifferentInvariantNotations(schedule, culture, action));

if (changeToRemove is not null)
{
Expand All @@ -196,13 +194,29 @@ public void AddOrUpdate(string culture, DateTime dateTime, ContentScheduleAction
Add(new ContentSchedule(culture, dateTime, action));
}

private bool MatchingScheduleTakingIntoAccountDifferentInvariantNotations(ContentSchedule change, string culture,
ContentScheduleAction action)
{
if (change.Action != action)
{
return false;
}

if (culture is "" or "*")
{
return change.Culture is "" or "*";
}

return change.Culture == culture;
}

/// <summary>
/// Clear all of the scheduled change type for invariant content
/// </summary>
/// <param name="action"></param>
/// <param name="changeDate">If specified, will clear all entries with dates less than or equal to the value</param>
public void Clear(ContentScheduleAction action, DateTime? changeDate = null) =>
Clear(Constants.System.InvariantCulture, action, changeDate);
Clear(string.Empty, action, changeDate);

/// <summary>
/// Clear all of the scheduled change type for the culture
Expand Down Expand Up @@ -252,7 +266,7 @@ public IReadOnlyList<ContentSchedule> GetPending(ContentScheduleAction action, D
/// </summary>
/// <returns></returns>
public IEnumerable<ContentSchedule> GetSchedule(ContentScheduleAction? action = null) =>
GetSchedule(Constants.System.InvariantCulture, action);
GetSchedule(string.Empty, action);

/// <summary>
/// Gets the schedule for a culture
Expand Down
8 changes: 4 additions & 4 deletions src/Umbraco.Core/Services/ContentPublishingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public async Task<Attempt<ContentPublishingResult, ContentPublishingOperationSta
Guid userKey)
{
var culturesToPublishImmediately =
culturesToPublishOrSchedule.Where(culture => culture.Schedule is null).Select(c => c.Culture ?? Constants.System.InvariantCulture).ToHashSet();
culturesToPublishOrSchedule.Where(culture => culture.Schedule is null).Select(c => c.Culture ?? "*").ToHashSet();

ContentScheduleCollection schedules = _contentService.GetContentScheduleByContentId(key);

foreach (CulturePublishScheduleModel cultureToSchedule in culturesToPublishOrSchedule.Where(c => c.Schedule is not null))
{
var culture = cultureToSchedule.Culture ?? Constants.System.InvariantCulture;
var culture = cultureToSchedule.Culture ?? "*";

if (cultureToSchedule.Schedule!.PublishDate is null)
{
Expand Down Expand Up @@ -150,7 +150,7 @@ public async Task<Attempt<ContentPublishingResult, ContentPublishingOperationSta
return Attempt.FailWithStatus(ContentPublishingOperationStatus.CultureMissing, new ContentPublishingResult());
}

if (cultures.Any(x => x == Constants.System.InvariantCulture))
if (cultures.Any(x => x == "*"))
{
scope.Complete();
return Attempt.FailWithStatus(ContentPublishingOperationStatus.CannotPublishInvariantWhenVariant, new ContentPublishingResult());
Expand All @@ -165,7 +165,7 @@ public async Task<Attempt<ContentPublishingResult, ContentPublishingOperationSta
}
else
{
if (cultures.Length != 1 || cultures.Any(x => x != Constants.System.InvariantCulture))
if (cultures.Length != 1 || cultures.Any(x => x != "*"))
{
scope.Complete();
return Attempt.FailWithStatus(ContentPublishingOperationStatus.InvalidCulture, new ContentPublishingResult());
Expand Down
4 changes: 2 additions & 2 deletions src/Umbraco.Core/Services/ContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3332,8 +3332,8 @@ private PublishResult StrategyCanPublish(

ContentScheduleCollection contentSchedule = _documentRepository.GetContentSchedule(content.Id);

// loop over each culture publishing - or InvariantCulture for invariant
foreach (var culture in culturesPublishing ?? new[] { Constants.System.InvariantCulture })
// loop over each culture publishing - or string.empty for invariant
foreach (var culture in culturesPublishing ?? new[] { string.Empty })
{
// ensure that the document status is correct
// note: culture will be string.Empty for invariant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public ContentScheduleCollection GetContentSchedule(int contentId)
{
result.Add(new ContentSchedule(
scheduleDto.Id,
LanguageRepository.GetIsoCodeById(scheduleDto.LanguageId) ?? Constants.System.InvariantCulture,
LanguageRepository.GetIsoCodeById(scheduleDto.LanguageId) ?? string.Empty,
scheduleDto.Date,
scheduleDto.Action == ContentScheduleAction.Release.ToString()
? ContentScheduleAction.Release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public async Task Can_NOT_Publish_Invariant_In_Variant_Setup()

var publishAttempt = await ContentPublishingService.PublishAsync(
setupData.Key,
new List<CulturePublishScheduleModel> { new() { Culture = Constants.System.InvariantCulture } },
new List<CulturePublishScheduleModel> { new() { Culture = null } },
Constants.Security.SuperUserKey);

Assert.IsFalse(publishAttempt.Success);
Expand All @@ -140,7 +140,7 @@ public async Task Can_Publish_Invariant_In_Invariant_Setup()

var publishAttempt = await ContentPublishingService.PublishAsync(
setupData.Key,
new List<CulturePublishScheduleModel> { new() { Culture = Constants.System.InvariantCulture } },
new List<CulturePublishScheduleModel> { new() { Culture = null} },
Constants.Security.SuperUserKey);

Assert.IsTrue(publishAttempt.Success);
Expand Down Expand Up @@ -233,7 +233,7 @@ public async Task Can_Schedule_Publish_Invariant()
{
new()
{
Culture = Constants.System.InvariantCulture,
Culture = null,
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
},
},
Expand All @@ -250,7 +250,7 @@ public async Task Can_Schedule_Publish_Invariant()
Assert.IsNull(content!.PublishDate);
Assert.AreEqual(
_schedulePublishDate,
schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Release).Single().Date);
schedules.GetSchedule(string.Empty, ContentScheduleAction.Release).Single().Date);
Assert.AreEqual(1, schedules.FullSchedule.Count);
});
}
Expand Down Expand Up @@ -451,7 +451,7 @@ public async Task Can_Schedule_Unpublish_Invariant()
{
new()
{
Culture = Constants.System.InvariantCulture,
Culture = null,
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
},
},
Expand All @@ -468,7 +468,7 @@ public async Task Can_Schedule_Unpublish_Invariant()
Assert.IsNull(content!.PublishDate);
Assert.AreEqual(
_scheduleUnPublishDate,
schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Expire).Single().Date);
schedules.GetSchedule(string.Empty, ContentScheduleAction.Expire).Single().Date);
Assert.AreEqual(1, schedules.FullSchedule.Count);
});
}
Expand Down Expand Up @@ -677,7 +677,7 @@ public async Task Can_UnSchedule_Publish_Invariant()
{
new()
{
Culture = Constants.System.InvariantCulture,
Culture = null,
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
},
},
Expand All @@ -692,8 +692,8 @@ public async Task Can_UnSchedule_Publish_Invariant()
{
Assert.AreEqual(0, content!.PublishedCultures.Count());
Assert.IsNull(content!.PublishDate);
Assert.IsFalse(schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Release).Any());
Assert.IsTrue(schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Expire).Any());
Assert.IsFalse(schedules.GetSchedule(string.Empty, ContentScheduleAction.Release).Any());
Assert.IsTrue(schedules.GetSchedule(string.Empty, ContentScheduleAction.Expire).Any());
Assert.AreEqual(1, schedules.FullSchedule.Count);
});
}
Expand Down Expand Up @@ -922,7 +922,7 @@ public async Task Can_UnSchedule_Unpublish_Invariant()
{
new()
{
Culture = Constants.System.InvariantCulture,
Culture = null,
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
},
},
Expand All @@ -937,8 +937,8 @@ public async Task Can_UnSchedule_Unpublish_Invariant()
{
Assert.AreEqual(0, content!.PublishedCultures.Count());
Assert.IsNull(content!.PublishDate);
Assert.IsFalse(schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Expire).Any());
Assert.IsTrue(schedules.GetSchedule(Constants.System.InvariantCulture, ContentScheduleAction.Release).Any());
Assert.IsFalse(schedules.GetSchedule(string.Empty, ContentScheduleAction.Expire).Any());
Assert.IsTrue(schedules.GetSchedule(string.Empty, ContentScheduleAction.Release).Any());
Assert.AreEqual(1, schedules.FullSchedule.Count);
});
}
Expand Down Expand Up @@ -1166,7 +1166,7 @@ public async Task Can_Clear_Schedule_Invariant()
{
new()
{
Culture = Constants.System.InvariantCulture,
Culture = null,
Schedule = new ContentScheduleModel(),
},
},
Expand Down Expand Up @@ -1544,7 +1544,7 @@ private async Task<Attempt<ContentPublishingResult, ContentPublishingOperationSt
{
new()
{
Culture = Constants.System.InvariantCulture,
Culture = null,
Schedule =
new ContentScheduleModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public void Remove_Scheduled_Publishing_Date()
contentSchedule = ContentService.GetContentScheduleByContentId(content.Id);
var sched = contentSchedule.FullSchedule;
Assert.AreEqual(1, sched.Count);
Assert.AreEqual(1, sched.Count(x => x.Culture == Constants.System.InvariantCulture));
Assert.AreEqual(1, sched.Count(x => x.Culture == string.Empty));
contentSchedule.Clear(ContentScheduleAction.Expire);
ContentService.Save(content, Constants.Security.SuperUserId, contentSchedule);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Can_Remove_Invariant()
var now = DateTime.Now;
var schedule = new ContentScheduleCollection();
schedule.Add(now, null);
var invariantSched = schedule.GetSchedule(Constants.System.InvariantCulture);
var invariantSched = schedule.GetSchedule(string.Empty);
schedule.Remove(invariantSched.First());
Assert.AreEqual(0, schedule.FullSchedule.Count());
}
Expand All @@ -57,7 +57,7 @@ public void Can_Remove_Variant()
var schedule = new ContentScheduleCollection();
schedule.Add(now, null);
schedule.Add("en-US", now, null);
var invariantSched = schedule.GetSchedule(Constants.System.InvariantCulture);
var invariantSched = schedule.GetSchedule(string.Empty);
schedule.Remove(invariantSched.First());
Assert.AreEqual(0, schedule.GetSchedule(string.Empty).Count());
Assert.AreEqual(1, schedule.FullSchedule.Count());
Expand Down