Merge remote-tracking branch 'origin/dev-v7' into 7.3.0
This commit is contained in:
@@ -618,6 +618,17 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
repo.ReplaceEntityPermissions(permissionSet);
|
||||
}
|
||||
|
||||
public void ClearPublished(IContent content)
|
||||
{
|
||||
// race cond!
|
||||
var documentDtos = Database.Fetch<DocumentDto>("WHERE nodeId=@id AND published=@published", new { id = content.Id, published = true });
|
||||
foreach (var documentDto in documentDtos)
|
||||
{
|
||||
documentDto.Published = false;
|
||||
Database.Update(documentDto);
|
||||
}
|
||||
}
|
||||
|
||||
public IContent GetByLanguage(int id, string language)
|
||||
{
|
||||
var sql = GetBaseQuery(false);
|
||||
|
||||
@@ -27,6 +27,12 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// <param name="permissionSet"></param>
|
||||
void ReplaceContentPermissions(EntityPermissionSet permissionSet);
|
||||
|
||||
/// <summary>
|
||||
/// Clears the published flag for a content.
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
void ClearPublished(IContent content);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a specific language version of an <see cref="IContent"/>
|
||||
/// </summary>
|
||||
|
||||
@@ -303,32 +303,7 @@ namespace Umbraco.Core.Publishing
|
||||
/// <returns>True if the unpublish operation was successfull and not cancelled, otherwise false</returns>
|
||||
public override bool UnPublish(IContent content, int userId)
|
||||
{
|
||||
if (UnPublishing.IsRaisedEventCancelled(new PublishEventArgs<IContent>(content), this))
|
||||
{
|
||||
LogHelper.Info<PublishingStrategy>(
|
||||
string.Format("Content '{0}' with Id '{1}' will not be un-published, the event was cancelled.", content.Name, content.Id));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//If Content has a release date set to before now, it should be removed so it doesn't interrupt an unpublish
|
||||
//Otherwise it would remain released == published
|
||||
if (content.ReleaseDate.HasValue && content.ReleaseDate.Value <= DateTime.Now)
|
||||
{
|
||||
content.ReleaseDate = null;
|
||||
|
||||
LogHelper.Info<PublishingStrategy>(
|
||||
string.Format(
|
||||
"Content '{0}' with Id '{1}' had its release date removed, because it was unpublished.",
|
||||
content.Name, content.Id));
|
||||
}
|
||||
|
||||
content.ChangePublishedState(PublishedState.Unpublished);
|
||||
|
||||
LogHelper.Info<PublishingStrategy>(
|
||||
string.Format("Content '{0}' with Id '{1}' has been unpublished.",
|
||||
content.Name, content.Id));
|
||||
return true;
|
||||
return UnPublishInternal(content, userId).Success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -337,43 +312,47 @@ namespace Umbraco.Core.Publishing
|
||||
/// <param name="content">An enumerable list of <see cref="IContent"/></param>
|
||||
/// <param name="userId">Id of the User issueing the unpublish operation</param>
|
||||
/// <returns>A list of publish statuses</returns>
|
||||
internal IEnumerable<Attempt<PublishStatus>> UnPublishInternal(IEnumerable<IContent> content, int userId)
|
||||
private IEnumerable<Attempt<PublishStatus>> UnPublishInternal(IEnumerable<IContent> content, int userId)
|
||||
{
|
||||
var result = new List<Attempt<PublishStatus>>();
|
||||
return content.Select(x => UnPublishInternal(x, userId));
|
||||
}
|
||||
|
||||
//Only update content thats already been published
|
||||
foreach (var item in content.Where(x => x.Published == true))
|
||||
private Attempt<PublishStatus> UnPublishInternal(IContent content, int userId)
|
||||
{
|
||||
// content should (is assumed to ) be the newest version, which may not be published
|
||||
// don't know how to test this, so it's not verified
|
||||
// NOTE
|
||||
// if published != newest, then the published flags need to be reseted by whoever is calling that method
|
||||
// at the moment it's done by the content service
|
||||
|
||||
//Fire UnPublishing event
|
||||
if (UnPublishing.IsRaisedEventCancelled(new PublishEventArgs<IContent>(content), this))
|
||||
{
|
||||
//Fire UnPublishing event
|
||||
if (UnPublishing.IsRaisedEventCancelled(new PublishEventArgs<IContent>(item), this))
|
||||
{
|
||||
LogHelper.Info<PublishingStrategy>(
|
||||
string.Format("Content '{0}' with Id '{1}' will not be published, the event was cancelled.", item.Name, item.Id));
|
||||
result.Add(Attempt.Fail(new PublishStatus(item, PublishStatusType.FailedCancelledByEvent)));
|
||||
continue;
|
||||
}
|
||||
|
||||
//If Content has a release date set to before now, it should be removed so it doesn't interrupt an unpublish
|
||||
//Otherwise it would remain released == published
|
||||
if (item.ReleaseDate.HasValue && item.ReleaseDate.Value <= DateTime.Now)
|
||||
{
|
||||
item.ReleaseDate = null;
|
||||
|
||||
LogHelper.Info<PublishingStrategy>(
|
||||
string.Format("Content '{0}' with Id '{1}' had its release date removed, because it was unpublished.",
|
||||
item.Name, item.Id));
|
||||
}
|
||||
|
||||
item.ChangePublishedState(PublishedState.Unpublished);
|
||||
|
||||
LogHelper.Info<PublishingStrategy>(
|
||||
string.Format("Content '{0}' with Id '{1}' has been unpublished.",
|
||||
item.Name, item.Id));
|
||||
|
||||
result.Add(Attempt.Succeed(new PublishStatus(item)));
|
||||
string.Format("Content '{0}' with Id '{1}' will not be unpublished, the event was cancelled.", content.Name, content.Id));
|
||||
return Attempt.Fail(new PublishStatus(content, PublishStatusType.FailedCancelledByEvent));
|
||||
}
|
||||
|
||||
return result;
|
||||
//If Content has a release date set to before now, it should be removed so it doesn't interrupt an unpublish
|
||||
//Otherwise it would remain released == published
|
||||
if (content.ReleaseDate.HasValue && content.ReleaseDate.Value <= DateTime.Now)
|
||||
{
|
||||
content.ReleaseDate = null;
|
||||
|
||||
LogHelper.Info<PublishingStrategy>(
|
||||
string.Format("Content '{0}' with Id '{1}' had its release date removed, because it was unpublished.",
|
||||
content.Name, content.Id));
|
||||
}
|
||||
|
||||
// if newest is published, unpublish
|
||||
if (content.Published)
|
||||
content.ChangePublishedState(PublishedState.Unpublished);
|
||||
|
||||
LogHelper.Info<PublishingStrategy>(
|
||||
string.Format("Content '{0}' with Id '{1}' has been unpublished.",
|
||||
content.Name, content.Id));
|
||||
|
||||
return Attempt.Succeed(new PublishStatus(content));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1698,6 +1698,13 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>True if unpublishing succeeded, otherwise False</returns>
|
||||
private bool UnPublishDo(IContent content, bool omitCacheRefresh = false, int userId = 0)
|
||||
{
|
||||
var newest = GetById(content.Id); // ensure we have the newest version
|
||||
if (content.Version != newest.Version) // but use the original object if it's already the newest version
|
||||
content = newest;
|
||||
var published = content.Published ? content : GetPublishedVersion(content.Id); // get the published version
|
||||
if (published == null)
|
||||
return false; // already unpublished
|
||||
|
||||
var unpublished = _publishingStrategy.UnPublish(content, userId);
|
||||
if (unpublished)
|
||||
{
|
||||
@@ -1706,6 +1713,9 @@ namespace Umbraco.Core.Services
|
||||
{
|
||||
content.WriterId = userId;
|
||||
repository.AddOrUpdate(content);
|
||||
// is published is not newest, reset the published flag on published version
|
||||
if (published.Version != content.Version)
|
||||
repository.ClearPublished(published);
|
||||
repository.DeleteContentXml(content);
|
||||
|
||||
uow.Commit();
|
||||
|
||||
Reference in New Issue
Block a user