Merge remote-tracking branch 'origin/temp8' into temp8-IAction-cleanup

# Conflicts:
#	src/Umbraco.Tests/Composing/ActionCollectionTests.cs
#	src/Umbraco.Web/Models/Trees/MenuItem.cs
#	src/Umbraco.Web/_Legacy/Actions/Action.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionAssignDomain.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionBrowse.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionChangeDocType.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionCopy.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionCreateBlueprintFromContent.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionDelete.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionEmptyTranscan.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionExport.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionImport.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionMove.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionNew.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionNotify.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionNull.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionPackage.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionPackageCreate.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionProtect.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionPublish.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionRePublish.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionRefresh.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionRestore.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionRights.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionRollback.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionSort.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionToPublish.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionTranslate.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionUnPublish.cs
#	src/Umbraco.Web/_Legacy/Actions/ActionUpdate.cs
#	src/Umbraco.Web/_Legacy/Actions/ContextMenuSeperator.cs
#	src/Umbraco.Web/_Legacy/Actions/IAction.cs
#	src/Umbraco.Web/umbraco.presentation/umbraco/developer/RelationTypes/TreeMenu/ActionDeleteRelationType.cs
#	src/Umbraco.Web/umbraco.presentation/umbraco/developer/RelationTypes/TreeMenu/ActionNewRelationType.cs
This commit is contained in:
Shannon
2018-10-29 23:35:24 +11:00
41 changed files with 552 additions and 85 deletions

View File

@@ -28,11 +28,11 @@ namespace Umbraco.Core.Models
/// Initializes a new instance of the <see cref="ContentCultureInfos"/> class.
/// </summary>
/// <remarks>Used for cloning, without change tracking.</remarks>
private ContentCultureInfos(string culture, string name, DateTime date)
: this(culture)
internal ContentCultureInfos(ContentCultureInfos other)
: this(other.Culture)
{
_name = name;
_date = date;
_name = other.Name;
_date = other.Date;
}
/// <summary>
@@ -61,7 +61,7 @@ namespace Umbraco.Core.Models
/// <inheritdoc />
public object DeepClone()
{
return new ContentCultureInfos(Culture, Name, Date);
return new ContentCultureInfos(this);
}
/// <inheritdoc />

View File

@@ -24,8 +24,12 @@ namespace Umbraco.Core.Models
public ContentCultureInfosCollection(IEnumerable<ContentCultureInfos> items)
: base(x => x.Culture, StringComparer.InvariantCultureIgnoreCase)
{
// make sure to add *copies* and not the original items,
// as items can be modified by AddOrUpdate, and therefore
// the new collection would be impacted by changes made
// to the old collection
foreach (var item in items)
Add(item);
Add(new ContentCultureInfos(item));
}
/// <summary>

View File

@@ -368,6 +368,11 @@ namespace Umbraco.Core.Services
/// <para>A publishing document is a document with values that are being published, i.e.
/// that have been published or cleared via <see cref="IContent.PublishCulture"/> and
/// <see cref="IContent.UnpublishCulture"/>.</para>
/// <para>When one needs to publish or unpublish a single culture, or all cultures, using <see cref="SaveAndPublish"/>
/// and <see cref="Unpublish"/> is the way to go. But if one needs to, say, publish two cultures and unpublish a third
/// one, in one go, then one needs to invoke <see cref="IContent.PublishCulture"/> and <see cref="IContent.UnpublishCulture"/>
/// on the content itself - this prepares the content, but does not commit anything - and then, invoke
/// <see cref="SavePublishing"/> to actually commit the changes to the database.</para>
/// <para>The document is *always* saved, even when publishing fails.</para>
/// </remarks>
PublishResult SavePublishing(IContent content, int userId = 0, bool raiseEvents = true);
@@ -375,11 +380,30 @@ namespace Umbraco.Core.Services
/// <summary>
/// Saves and publishes a document branch.
/// </summary>
/// <remarks>
/// <para>Unless specified, all cultures are re-published. Otherwise, one culture can be specified. To act on more
/// that one culture, see the other overload of this method.</para>
/// <para>The <paramref name="force"/> parameter determines which documents are published. When <c>false</c>,
/// only those documents that are already published, are republished. When <c>true</c>, all documents are
/// published.</para>
/// </remarks>
IEnumerable<PublishResult> SaveAndPublishBranch(IContent content, bool force, string culture = "*", int userId = 0);
/// <summary>
/// Saves and publishes a document branch.
/// </summary>
/// <remarks>
/// <para>The <paramref name="force"/> parameter determines which documents are published. When <c>false</c>,
/// only those documents that are already published, are republished. When <c>true</c>, all documents are
/// published.</para>
/// <para>The <paramref name="editing"/> parameter is a function which determines whether a document has
/// values to publish (else there is no need to publish it). If one wants to publish only a selection of
/// cultures, one may want to check that only properties for these cultures have changed. Otherwise, other
/// cultures may trigger an unwanted republish.</para>
/// <para>The <paramref name="publishCultures"/> parameter is a function to execute to publish cultures, on
/// each document. It can publish all, one, or a selection of cultures. It returns a boolean indicating
/// whether the cultures could be published.</para>
/// </remarks>
IEnumerable<PublishResult> SaveAndPublishBranch(IContent content, bool force, Func<IContent, bool> editing, Func<IContent, bool> publishCultures, int userId = 0);
/// <summary>

View File

@@ -1272,12 +1272,49 @@ namespace Umbraco.Core.Services.Implement
bool IsEditing(IContent c, string l)
=> c.PublishName != c.Name ||
c.PublishedCultures.Any(x => c.GetCultureName(x) != c.GetPublishName(x)) ||
c.Properties.Any(x => x.Values.Where(y => culture == "*" || y.Culture == l).Any(y => !y.EditedValue.Equals(y.PublishedValue)));
c.PublishedCultures.Where(x => x.InvariantEquals(l)).Any(x => c.GetCultureName(x) != c.GetPublishName(x)) ||
c.Properties.Any(x => x.Values.Where(y => culture == "*" || y.Culture.InvariantEquals(l)).Any(y => !y.EditedValue.Equals(y.PublishedValue)));
return SaveAndPublishBranch(content, force, document => IsEditing(document, culture), document => document.PublishCulture(culture), userId);
}
// fixme - make this public once we know it works + document
private IEnumerable<PublishResult> SaveAndPublishBranch(IContent content, bool force, string[] cultures, int userId = 0)
{
// note: EditedValue and PublishedValue are objects here, so it is important to .Equals()
// and not to == them, else we would be comparing references, and that is a bad thing
cultures = cultures ?? Array.Empty<string>();
// determines whether the document is edited, and thus needs to be published,
// for the specified cultures (it may be edited for other cultures and that
// should not trigger a publish).
bool IsEdited(IContent c)
{
if (cultures.Length == 0)
{
// nothing = everything
return c.PublishName != c.Name ||
c.PublishedCultures.Any(x => c.GetCultureName(x) != c.GetPublishName(x)) ||
c.Properties.Any(x => x.Values.Any(y => !y.EditedValue.Equals(y.PublishedValue)));
}
return c.PublishName != c.Name ||
c.PublishedCultures.Where(x => cultures.Contains(x, StringComparer.InvariantCultureIgnoreCase)).Any(x => c.GetCultureName(x) != c.GetPublishName(x)) ||
c.Properties.Any(x => x.Values.Where(y => cultures.Contains(y.Culture, StringComparer.InvariantCultureIgnoreCase)).Any(y => !y.EditedValue.Equals(y.PublishedValue)));
}
// publish the specified cultures
bool PublishCultures(IContent c)
{
return cultures.Length == 0
? c.PublishCulture() // nothing = everything
: cultures.All(c.PublishCulture);
}
return SaveAndPublishBranch(content, force, IsEdited, PublishCultures, userId);
}
/// <inheritdoc />
public IEnumerable<PublishResult> SaveAndPublishBranch(IContent document, bool force,
Func<IContent, bool> editing, Func<IContent, bool> publishCultures, int userId = 0)