Merge remote-tracking branch 'origin/temp8' into temp8-231-send-to-publish-with-variants
# Conflicts: # src/Umbraco.Core/Services/Implement/ContentService.cs
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -344,37 +344,18 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<TItem> GetComposedOf(int id, IEnumerable<TItem> all)
|
||||
{
|
||||
return all.Where(x => x.ContentTypeComposition.Any(y => y.Id == id));
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<TItem> GetComposedOf(int id)
|
||||
{
|
||||
//fixme: this is essentially the same as ContentTypeServiceExtensions.GetWhereCompositionIsUsedInContentTypes which loads
|
||||
// all content types to figure this out, this instead makes quite a few queries so should be replaced
|
||||
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(ReadLockIds);
|
||||
|
||||
// hash set handles duplicates
|
||||
var composed = new HashSet<TItem>(new DelegateEqualityComparer<TItem>(
|
||||
(x, y) => x.Id == y.Id,
|
||||
x => x.Id.GetHashCode()));
|
||||
|
||||
var ids = new Stack<int>();
|
||||
ids.Push(id);
|
||||
|
||||
while (ids.Count > 0)
|
||||
{
|
||||
var i = ids.Pop();
|
||||
var result = Repository.GetTypesDirectlyComposedOf(i).ToArray();
|
||||
|
||||
foreach (var c in result)
|
||||
{
|
||||
composed.Add(c);
|
||||
ids.Push(c.Id);
|
||||
}
|
||||
}
|
||||
|
||||
return composed.ToArray();
|
||||
}
|
||||
// GetAll is cheap, repository has a full dataset cache policy
|
||||
// fixme - still, because it uses the cache, race conditions!
|
||||
var allContentTypes = GetAll(Array.Empty<int>());
|
||||
return GetComposedOf(id, allContentTypes);
|
||||
}
|
||||
|
||||
public int Count()
|
||||
|
||||
Reference in New Issue
Block a user