Merge branch 'temp8-226-sched-pub-angular' into temp8-3096-angular-bulk-publish

This commit is contained in:
Shannon
2018-11-15 10:04:18 +11:00
5 changed files with 58 additions and 41 deletions

View File

@@ -13,7 +13,18 @@ namespace Umbraco.Core.Models
/// <summary>
/// Initializes a new instance of the <see cref="ContentSchedule"/> class.
/// </summary>
public ContentSchedule(int id, string culture, DateTime date, ContentScheduleAction action)
public ContentSchedule(string culture, DateTime date, ContentScheduleAction action)
{
Id = Guid.Empty; // will be assigned by document repository
Culture = culture;
Date = date;
Action = action;
}
/// <summary>
/// Initializes a new instance of the <see cref="ContentSchedule"/> class.
/// </summary>
public ContentSchedule(Guid id, string culture, DateTime date, ContentScheduleAction action)
{
Id = id;
Culture = culture;
@@ -25,7 +36,7 @@ namespace Umbraco.Core.Models
/// Gets the unique identifier of the document targeted by the scheduled action.
/// </summary>
[DataMember]
public int Id { get; }
public Guid Id { get; internal set; }
/// <summary>
/// Gets the culture of the scheduled action.

View File

@@ -75,14 +75,14 @@ namespace Umbraco.Core.Models
if (releaseDate.HasValue)
{
var entry = new ContentSchedule(0, culture, releaseDate.Value, ContentScheduleAction.Release);
var entry = new ContentSchedule(culture, releaseDate.Value, ContentScheduleAction.Release);
changes.Add(releaseDate.Value, entry);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, entry));
}
if (expireDate.HasValue)
{
var entry = new ContentSchedule(0, culture, expireDate.Value, ContentScheduleAction.Expire);
var entry = new ContentSchedule(culture, expireDate.Value, ContentScheduleAction.Expire);
changes.Add(expireDate.Value, entry);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, entry));
}

View File

@@ -5,15 +5,15 @@ using Umbraco.Core.Persistence.DatabaseAnnotations;
namespace Umbraco.Core.Persistence.Dtos
{
[TableName(TableName)]
[PrimaryKey("id", AutoIncrement = true)]
[PrimaryKey("id", AutoIncrement = false)]
[ExplicitColumns]
internal class ContentScheduleDto
{
public const string TableName = Constants.DatabaseSchema.Tables.ContentSchedule;
[Column("id")]
[PrimaryKeyColumn(AutoIncrement = true)]
public int Id { get; set; }
[PrimaryKeyColumn(AutoIncrement = false)]
public Guid Id { get; set; }
[Column("nodeId")]
[ForeignKey(typeof(ContentDto))]

View File

@@ -173,17 +173,17 @@ namespace Umbraco.Core.Persistence.Factories
return dto;
}
public static IEnumerable<ContentScheduleDto> BuildScheduleDto(IContent entity, ILanguageRepository languageRepository)
public static IEnumerable<(ContentSchedule Model, ContentScheduleDto Dto)> BuildScheduleDto(IContent entity, ILanguageRepository languageRepository)
{
return entity.ContentSchedule.FullSchedule.Select(x =>
new ContentScheduleDto
(x, new ContentScheduleDto
{
Action = x.Action.ToString(),
Date = x.Date,
NodeId = entity.Id,
LanguageId = languageRepository.GetIdByIsoCode(x.Culture, false),
Id = x.Id
});
}));
}
/// <summary>

View File

@@ -363,7 +363,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
// persist the document dto
// at that point, when publishing, the entity still has its old Published value
// so we need to explicitely update the dto to persist the correct value
// so we need to explicitly update the dto to persist the correct value
if (content.PublishedState == PublishedState.Publishing)
dto.Published = true;
dto.NodeId = nodeDto.NodeId;
@@ -371,12 +371,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
Database.Insert(dto);
//insert the schedule
var scheduleDtos = ContentBaseFactory.BuildScheduleDto(content, LanguageRepository);
foreach (var scheduleDto in scheduleDtos)
{
scheduleDto.NodeId = nodeDto.NodeId;
Database.Insert(scheduleDto);
}
PersistContentSchedule(content, false);
// persist the variations
if (content.ContentType.VariesByCulture())
@@ -588,7 +583,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
// update the document dto
// at that point, when un/publishing, the entity still has its old Published value
// so we need to explicitely update the dto to persist the correct value
// so we need to explicitly update the dto to persist the correct value
if (content.PublishedState == PublishedState.Publishing)
dto.Published = true;
else if (content.PublishedState == PublishedState.Unpublishing)
@@ -596,30 +591,12 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
content.Edited = dto.Edited = !dto.Published || edited; // if not published, always edited
Database.Update(dto);
//update the schedule
if (content.IsPropertyDirty("ContentSchedule"))
{
//update the schedule, get the existing one so we know what to update
var scheduleDtos = ContentBaseFactory.BuildScheduleDto(content, LanguageRepository).ToList();
//remove any that no longer exist
var ids = scheduleDtos.Where(x => x.Id > 0).Select(x => x.Id).Distinct();
Database.Execute(Sql()
.Delete<ContentScheduleDto>()
.Where<ContentScheduleDto>(x => x.NodeId == content.Id)
.WhereNotIn<ContentScheduleDto>(x => x.Id, ids));
//add/update the rest
foreach (var scheduleDto in scheduleDtos)
{
if (scheduleDto.Id == 0)
Database.Insert(scheduleDto);
else
Database.Update(scheduleDto);
}
}
PersistContentSchedule(content, true);
// if entity is publishing, update tags, else leave tags there
// means that implicitely unpublished, or trashed, entities *still* have tags in db
// means that implicitly unpublished, or trashed, entities *still* have tags in db
if (content.PublishedState == PublishedState.Publishing)
SetEntityTags(entity, _tagRepository);
@@ -649,8 +626,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
ClearEntityTags(entity, _tagRepository);
}
// note re. tags: explicitely unpublished entities have cleared tags,
// but masked or trashed entitites *still* have tags in the db fixme so what?
// note re. tags: explicitly unpublished entities have cleared tags,
// but masked or trashed entities *still* have tags in the db fixme so what?
entity.ResetDirtyProperties();
@@ -667,6 +644,35 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
//}
}
private void PersistContentSchedule(IContent content, bool update)
{
var schedules = ContentBaseFactory.BuildScheduleDto(content, LanguageRepository).ToList();
//remove any that no longer exist
if (update)
{
var ids = schedules.Where(x => x.Model.Id != Guid.Empty).Select(x => x.Model.Id).Distinct();
Database.Execute(Sql()
.Delete<ContentScheduleDto>()
.Where<ContentScheduleDto>(x => x.NodeId == content.Id)
.WhereNotIn<ContentScheduleDto>(x => x.Id, ids));
}
//add/update the rest
foreach (var schedule in schedules)
{
if (schedule.Model.Id == Guid.Empty)
{
schedule.Model.Id = schedule.Dto.Id = Guid.NewGuid();
Database.Insert(schedule.Dto);
}
else
{
Database.Update(schedule.Dto);
}
}
}
protected override void PersistDeletedItem(IContent entity)
{
// raise event first else potential FK issues