Skip to content

Commit 2a1c898

Browse files
#8878: Fixing that Projection Manager should apply the Version Scope even if there are multiple filter groups (#8880)
1 parent bbde34d commit 2a1c898

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/Orchard.Web/Modules/Orchard.Projections/Services/IProjectionManager.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Orchard.Projections.Descriptors.Layout;
66
using Orchard.Projections.Descriptors.Property;
77
using Orchard.Projections.Descriptors.SortCriterion;
8+
using Orchard.Projections.Models;
89

910
namespace Orchard.Projections.Services
1011
{
@@ -23,7 +24,12 @@ public interface IProjectionManager : IDependency
2324
IEnumerable<ContentItem> GetContentItems(int queryId, int skip = 0, int count = 0);
2425
IEnumerable<ContentItem> GetContentItems(int queryId, ContentPart part, int skip = 0, int count = 0);
2526

27+
IEnumerable<IHqlQuery> GetContentQueries(
28+
QueryPartRecord queryRecord,
29+
IEnumerable<SortCriterionRecord> sortCriteria,
30+
Dictionary<string, object> tokens);
31+
2632
int GetCount(int queryId);
2733
int GetCount(int queryId, ContentPart part);
2834
}
29-
}
35+
}

src/Orchard.Web/Modules/Orchard.Projections/Services/ProjectionManager.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public int GetCount(int queryId, ContentPart part)
128128
var queryRecord = _queryRepository.Get(queryId) ?? throw new ArgumentException("queryId");
129129

130130
// Prepare tokens.
131-
Dictionary<string, object> tokens = new Dictionary<string, object>();
131+
var tokens = new Dictionary<string, object>();
132132
if (part != null)
133133
{
134134
tokens.Add("Content", part.ContentItem);
@@ -151,17 +151,11 @@ public IEnumerable<ContentItem> GetContentItems(int queryId, ContentPart part, i
151151
{
152152
var availableSortCriteria = DescribeSortCriteria().ToList();
153153

154-
var queryRecord = _queryRepository.Get(queryId);
155-
156-
if (queryRecord == null)
157-
{
158-
throw new ArgumentException("queryId");
159-
}
160-
154+
var queryRecord = _queryRepository.Get(queryId) ?? throw new ArgumentException("queryId");
161155
var contentItems = new List<ContentItem>();
162156

163157
// Prepare tokens.
164-
Dictionary<string, object> tokens = new Dictionary<string, object>();
158+
var tokens = new Dictionary<string, object>();
165159
if (part != null)
166160
{
167161
tokens.Add("Content", part.ContentItem);
@@ -186,7 +180,8 @@ public IEnumerable<ContentItem> GetContentItems(int queryId, ContentPart part, i
186180
return Enumerable.Empty<ContentItem>();
187181
}
188182

189-
var groupQuery = _contentManager.HqlQuery().Where(alias => alias.Named("ci"), x => x.InG("Id", ids));
183+
var version = queryRecord.VersionScope.ToVersionOptions();
184+
var groupQuery = _contentManager.HqlQuery().ForVersion(version).Where(alias => alias.Named("ci"), x => x.InG("Id", ids));
190185

191186
// Iterate over each sort criteria to apply the alterations to the query object.
192187
foreach (var sortCriterion in queryRecord.SortCriteria.OrderBy(s => s.Position))
@@ -200,8 +195,8 @@ public IEnumerable<ContentItem> GetContentItems(int queryId, ContentPart part, i
200195
Tokens = tokens
201196
};
202197

203-
string category = sortCriterion.Category;
204-
string type = sortCriterion.Type;
198+
var category = sortCriterion.Category;
199+
var type = sortCriterion.Type;
205200

206201
// Find specific sort criterion.
207202
var descriptor = availableSortCriteria
@@ -255,8 +250,8 @@ public IEnumerable<IHqlQuery> GetContentQueries(
255250
Tokens = tokens
256251
};
257252

258-
string category = filter.Category;
259-
string type = filter.Type;
253+
var category = filter.Category;
254+
var type = filter.Type;
260255

261256
// Find specific filter.
262257
var descriptor = availableFilters
@@ -287,8 +282,8 @@ public IEnumerable<IHqlQuery> GetContentQueries(
287282
Tokens = tokens
288283
};
289284

290-
string category = sortCriterion.Category;
291-
string type = sortCriterion.Type;
285+
var category = sortCriterion.Category;
286+
var type = sortCriterion.Type;
292287

293288
// Find specific sort criterion.
294289
var descriptor = availableSortCriteria

0 commit comments

Comments
 (0)