Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2971ec77e5 | ||
|
|
6d788f105e | ||
|
|
cf3f1cfc65 |
@@ -163,7 +163,7 @@ internal sealed class DocumentPresentationFactory : IDocumentPresentationFactory
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ internal sealed class DocumentPresentationFactory : IDocumentPresentationFactory
|
||||
}
|
||||
|
||||
contentScheduleCollection.Add(new ContentSchedule(
|
||||
cultureAndScheduleRequestModel.Culture ?? Constants.System.InvariantCulture,
|
||||
cultureAndScheduleRequestModel.Culture ?? "*",
|
||||
cultureAndScheduleRequestModel.Schedule.PublishTime.Value.UtcDateTime,
|
||||
ContentScheduleAction.Release));
|
||||
}
|
||||
@@ -204,7 +204,7 @@ internal sealed class DocumentPresentationFactory : IDocumentPresentationFactory
|
||||
}
|
||||
|
||||
contentScheduleCollection.Add(new ContentSchedule(
|
||||
cultureAndScheduleRequestModel.Culture ?? Constants.System.InvariantCulture,
|
||||
cultureAndScheduleRequestModel.Culture ?? "*",
|
||||
cultureAndScheduleRequestModel.Schedule.UnpublishTime.Value.UtcDateTime,
|
||||
ContentScheduleAction.Expire));
|
||||
}
|
||||
@@ -226,8 +226,7 @@ internal sealed class DocumentPresentationFactory : IDocumentPresentationFactory
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,7 @@ public interface IDocumentPresentationFactory
|
||||
{
|
||||
model.Add(new CulturePublishScheduleModel
|
||||
{
|
||||
Culture = cultureAndScheduleRequestModel.Culture
|
||||
?? Constants.System.InvariantCulture
|
||||
Culture = cultureAndScheduleRequestModel.Culture ?? "*"
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -140,5 +140,5 @@ public class DocumentMapDefinition : ContentMapDefinition<IContent, DocumentValu
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsInvariant(string? culture) => culture.IsNullOrWhiteSpace() || culture == Core.Constants.System.InvariantCulture;
|
||||
private static bool IsInvariant(string? culture) => culture.IsNullOrWhiteSpace() || culture == string.Empty;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,5 @@ public static partial class Constants
|
||||
/// The DataDirectory placeholder.
|
||||
/// </summary>
|
||||
public const string DataDirectoryPlaceholder = "|DataDirectory|";
|
||||
|
||||
public const string InvariantCulture = "*";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ public static class ContentExtensions
|
||||
|
||||
if (!content.ContentType.VariesByCulture())
|
||||
{
|
||||
culture = Constants.System.InvariantCulture;
|
||||
culture = string.Empty;
|
||||
}
|
||||
else if (culture.IsNullOrWhiteSpace())
|
||||
{
|
||||
|
||||
@@ -64,7 +64,7 @@ public class ContentScheduleCollection : INotifyCollectionChanged, IDeepCloneabl
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class ContentScheduleCollection : INotifyCollectionChanged, IDeepCloneabl
|
||||
/// </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
|
||||
@@ -170,11 +170,10 @@ public class ContentScheduleCollection : INotifyCollectionChanged, IDeepCloneabl
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -184,9 +183,8 @@ public class ContentScheduleCollection : INotifyCollectionChanged, IDeepCloneabl
|
||||
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)
|
||||
{
|
||||
@@ -196,13 +194,29 @@ public class ContentScheduleCollection : INotifyCollectionChanged, IDeepCloneabl
|
||||
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
|
||||
@@ -252,7 +266,7 @@ public class ContentScheduleCollection : INotifyCollectionChanged, IDeepCloneabl
|
||||
/// </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
|
||||
|
||||
@@ -52,13 +52,13 @@ internal sealed class ContentPublishingService : IContentPublishingService
|
||||
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)
|
||||
{
|
||||
@@ -150,7 +150,7 @@ internal sealed class ContentPublishingService : IContentPublishingService
|
||||
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());
|
||||
@@ -165,7 +165,7 @@ internal sealed class ContentPublishingService : IContentPublishingService
|
||||
}
|
||||
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());
|
||||
|
||||
@@ -3332,8 +3332,8 @@ public class ContentService : RepositoryService, IContentService
|
||||
|
||||
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
|
||||
|
||||
@@ -117,7 +117,7 @@ public class DocumentRepository : ContentRepositoryBase<int, IContent, DocumentR
|
||||
{
|
||||
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
|
||||
|
||||
+14
-14
@@ -122,7 +122,7 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
|
||||
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);
|
||||
@@ -140,7 +140,7 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
|
||||
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);
|
||||
@@ -233,7 +233,7 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
new()
|
||||
{
|
||||
Culture = Constants.System.InvariantCulture,
|
||||
Culture = null,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
},
|
||||
@@ -250,7 +250,7 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
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);
|
||||
});
|
||||
}
|
||||
@@ -451,7 +451,7 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
new()
|
||||
{
|
||||
Culture = Constants.System.InvariantCulture,
|
||||
Culture = null,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
|
||||
},
|
||||
},
|
||||
@@ -468,7 +468,7 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
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);
|
||||
});
|
||||
}
|
||||
@@ -677,7 +677,7 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
new()
|
||||
{
|
||||
Culture = Constants.System.InvariantCulture,
|
||||
Culture = null,
|
||||
Schedule = new ContentScheduleModel { UnpublishDate = _scheduleUnPublishDate },
|
||||
},
|
||||
},
|
||||
@@ -692,8 +692,8 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
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);
|
||||
});
|
||||
}
|
||||
@@ -922,7 +922,7 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
new()
|
||||
{
|
||||
Culture = Constants.System.InvariantCulture,
|
||||
Culture = null,
|
||||
Schedule = new ContentScheduleModel { PublishDate = _schedulePublishDate },
|
||||
},
|
||||
},
|
||||
@@ -937,8 +937,8 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
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);
|
||||
});
|
||||
}
|
||||
@@ -1166,7 +1166,7 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
new()
|
||||
{
|
||||
Culture = Constants.System.InvariantCulture,
|
||||
Culture = null,
|
||||
Schedule = new ContentScheduleModel(),
|
||||
},
|
||||
},
|
||||
@@ -1544,7 +1544,7 @@ public class ContentPublishingServiceTests : UmbracoIntegrationTestWithContent
|
||||
{
|
||||
new()
|
||||
{
|
||||
Culture = Constants.System.InvariantCulture,
|
||||
Culture = null,
|
||||
Schedule =
|
||||
new ContentScheduleModel
|
||||
{
|
||||
|
||||
@@ -328,7 +328,7 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent
|
||||
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);
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ContentScheduleTests
|
||||
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());
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class ContentScheduleTests
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user