mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-23 21:32:14 +08:00
#18979: Fixing GetMany() and Query() in regards to DraftRequired option
Work Item: 18979 --HG-- branch : 1.x
This commit is contained in:
@@ -261,21 +261,25 @@ namespace Orchard.ContentManagement {
|
||||
else if (options.IsLatest) {
|
||||
contentItemVersionCriteria.Add(Restrictions.Eq("Latest", true));
|
||||
}
|
||||
else if (options.IsDraft) {
|
||||
else if (options.IsDraft && !options.IsDraftRequired) {
|
||||
contentItemVersionCriteria.Add(
|
||||
Restrictions.And(Restrictions.Eq("Published", false),
|
||||
Restrictions.Eq("Latest", true)));
|
||||
}
|
||||
else if (options.IsDraft || options.IsDraftRequired) {
|
||||
contentItemVersionCriteria.Add(Restrictions.Eq("Latest", true));
|
||||
}
|
||||
});
|
||||
|
||||
var itemsById = contentItemVersionRecords
|
||||
.Select(r => Get(r.ContentItemRecord.Id, VersionOptions.VersionRecord(r.Id)))
|
||||
.Select(r => Get(r.ContentItemRecord.Id, options == VersionOptions.DraftRequired ? options : VersionOptions.VersionRecord(r.Id)))
|
||||
.GroupBy(ci => ci.Id)
|
||||
.ToDictionary(g => g.Key);
|
||||
|
||||
return ids.SelectMany(id => {
|
||||
IGrouping<int, ContentItem> values;
|
||||
return itemsById.TryGetValue(id, out values) ? values : Enumerable.Empty<ContentItem>();
|
||||
}).AsPart<T>().ToArray();
|
||||
IGrouping<int, ContentItem> values;
|
||||
return itemsById.TryGetValue(id, out values) ? values : Enumerable.Empty<ContentItem>();
|
||||
}).AsPart<T>().ToArray();
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetManyByVersionId<T>(IEnumerable<int> versionRecordIds, QueryHints hints) where T : class, IContent {
|
||||
|
||||
@@ -10,7 +10,6 @@ using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data;
|
||||
using NHibernate.Transform;
|
||||
using NHibernate.SqlCommand;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.ContentManagement {
|
||||
@@ -146,7 +145,7 @@ namespace Orchard.ContentManagement {
|
||||
|
||||
return criteria
|
||||
.List<ContentItemVersionRecord>()
|
||||
.Select(x => ContentManager.Get(x.Id, VersionOptions.VersionRecord(x.Id)))
|
||||
.Select(x => ContentManager.Get(x.Id, _versionOptions == VersionOptions.DraftRequired ? _versionOptions : VersionOptions.VersionRecord(x.Id)))
|
||||
.ToReadOnlyCollection();
|
||||
}
|
||||
|
||||
@@ -316,11 +315,14 @@ namespace Orchard.ContentManagement {
|
||||
else if (versionOptions.IsLatest) {
|
||||
criteria.Add(Restrictions.Eq("Latest", true));
|
||||
}
|
||||
else if (versionOptions.IsDraft) {
|
||||
else if (versionOptions.IsDraft && !versionOptions.IsDraftRequired) {
|
||||
criteria.Add(Restrictions.And(
|
||||
Restrictions.Eq("Latest", true),
|
||||
Restrictions.Eq("Published", false)));
|
||||
}
|
||||
else if (versionOptions.IsDraft || versionOptions.IsDraftRequired) {
|
||||
criteria.Add(Restrictions.Eq("Latest", true));
|
||||
}
|
||||
else if (versionOptions.IsAllVersions) {
|
||||
// no-op... all versions will be returned by default
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user