From 600a8c00fe9d60cc46cc76edb82a62b3b186d089 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Thu, 16 Aug 2012 15:18:10 -0700 Subject: [PATCH 1/8] Fixing distinct root transformation The [Aggregate] attribute might be used and the QueryHints might not reflect it. --HG-- branch : 1.x --- src/Orchard/ContentManagement/DefaultContentQuery.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Orchard/ContentManagement/DefaultContentQuery.cs b/src/Orchard/ContentManagement/DefaultContentQuery.cs index 17c54c6f7..d23694502 100644 --- a/src/Orchard/ContentManagement/DefaultContentQuery.cs +++ b/src/Orchard/ContentManagement/DefaultContentQuery.cs @@ -303,7 +303,7 @@ namespace Orchard.ContentManagement { hit.Segments.Take(hit.Segments.Count() - 1).Aggregate(contentItemCriteria.UnderlyingCriteria, ExtendCriteria); } - if (hintDictionary.SelectMany(x => x.Value).Any(x => x.Segments.Count() > 1)) + // if (hintDictionary.SelectMany(x => x.Value).Any(x => x.Segments.Count() > 1)) contentItemVersionCriteria.TransformUsing(new DistinctRootEntityResultTransformer()); return this; From 40a11218c6553bdb442ea767dd8935995c683744 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Thu, 16 Aug 2012 15:20:00 -0700 Subject: [PATCH 2/8] Fixing tags queries QueryOver doesn't support the Any() operator on a relationship. The current Linq implementation supports it but is using Hql, so it can't be reused. The QueryOver uses Criteria. The old NHibernate.Linq implementation is not compatible with NH3. Though it was using the Criteria API. --HG-- branch : 1.x --- .../Modules/Orchard.Tags/Services/TagService.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs b/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs index b5045086a..bd8a7e05b 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs +++ b/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs @@ -131,9 +131,9 @@ namespace Orchard.Tags.Services { public IEnumerable GetTaggedContentItems(int tagId, int skip, int take, VersionOptions options) { return _orchardServices.ContentManager - .Query() - .Where(tpr => tpr.Tags.Any(tr => tr.TagRecord.Id == tagId)) - .Join().OrderByDescending(x => x.CreatedUtc) + .HqlQuery() + .Where(tpr => tpr.ContentPartRecord().Property("Tags", "tags"), x => x.Eq("TagRecord.Id", tagId)) + .OrderBy(alias => alias.ContentPartRecord(), x => x.Desc("CreatedUtc")) .Slice(skip, take); } @@ -143,8 +143,8 @@ namespace Orchard.Tags.Services { public int GetTaggedContentItemCount(int tagId, VersionOptions options) { return _orchardServices.ContentManager - .Query() - .Where(tpr => tpr.Tags.Any(tr => tr.TagRecord.Id == tagId)) + .HqlQuery() + .Where(tpr => tpr.ContentPartRecord().Property("Tags", "tags"), x => x.Eq("TagRecord.Id", tagId)) .Count(); } From 1ee76aa7fdaa70a1b216c1811df8ca6f4e5c8339 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 17 Aug 2012 08:53:50 -0700 Subject: [PATCH 3/8] Fixing [Aggregate] usage --HG-- branch : 1.x --- .hgsubstate | 2 +- .../ContentManagement/DefaultContentQuery.cs | 18 +++++++++++------- .../Data/Conventions/AggregateAttribute.cs | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.hgsubstate b/.hgsubstate index bdd6f35af..392ce4ccb 100644 --- a/.hgsubstate +++ b/.hgsubstate @@ -8,5 +8,5 @@ e57f4a5dffac99ac64e195ae6ee5f2d720876b52 src/Orchard.Web/Modules/Orchard.Rules c85cd1e9651e3e0bb1ca97442ce390bf34cf3c76 src/Orchard.Web/Modules/Orchard.TaskLease 6ce83f60624b333aa6e23e756c07181d9df40094 src/Orchard.Web/Modules/Orchard.Tokens 1b4c795960358a84c743eeb6bd778fabbdf8455e src/orchard.web/Modules/Orchard.Alias -a5b0e6345d1a316e7184d1e77905e1300390756e src/orchard.web/Modules/Orchard.Projections +8ca57ca0486ad535c6c5d6940ad6c4ddd71130d2 src/orchard.web/Modules/Orchard.Projections 2f1aeab07e777f9ba2cf2ed6db7dcd2da831fd97 src/orchard.web/modules/Orchard.Fields diff --git a/src/Orchard/ContentManagement/DefaultContentQuery.cs b/src/Orchard/ContentManagement/DefaultContentQuery.cs index d23694502..fd0def33b 100644 --- a/src/Orchard/ContentManagement/DefaultContentQuery.cs +++ b/src/Orchard/ContentManagement/DefaultContentQuery.cs @@ -36,7 +36,7 @@ namespace Orchard.ContentManagement { return _session; } - IQueryOver BindQueryOverByPath(IQueryOver queryOver, string name) { + IQueryOver BindQueryOverByPath(IQueryOver queryOver, string name, JoinType joinType = JoinType.InnerJoin) { if (_joins.ContainsKey(typeof(TRecord).Name)) { return (IQueryOver)_joins[typeof(TRecord).Name]; } @@ -53,7 +53,7 @@ namespace Orchard.ContentManagement { Expression.Property(parameter, syntheticProperty), parameter); - var join = queryOver.JoinQueryOver(syntheticExpression); + var join = queryOver.JoinQueryOver(syntheticExpression, joinType); _joins[typeof(TRecord).Name] = join; return join; @@ -62,13 +62,13 @@ namespace Orchard.ContentManagement { IQueryOver BindTypeQueryOver() { // ([ContentItemVersionRecord] >join> [ContentItemRecord]) >join> [ContentType] - return BindQueryOverByPath(BindItemQueryOver(), "ContentType"); + return BindQueryOverByPath(BindItemQueryOver(), "ContentType", JoinType.LeftOuterJoin); } IQueryOver BindItemQueryOver() { // [ContentItemVersionRecord] >join> [ContentItemRecord] - return BindQueryOverByPath(BindItemVersionQueryOver(), "ContentItemRecord"); + return BindQueryOverByPath(BindItemVersionQueryOver(), "ContentItemRecord", JoinType.LeftOuterJoin); } IQueryOver BindItemVersionQueryOver() { @@ -146,10 +146,12 @@ namespace Orchard.ContentManagement { queryOver.Take(count); } - return new ReadOnlyCollection(queryOver + var result = queryOver .List() .Select(x => ContentManager.Get(x.Id, VersionOptions.VersionRecord(x.Id))) - .ToList()); + .ToList(); + + return new ReadOnlyCollection(result); } int Count() { @@ -291,6 +293,8 @@ namespace Orchard.ContentManagement { .GroupBy(item => item.Segments.FirstOrDefault()) .ToDictionary(grouping => grouping.Key, StringComparer.InvariantCultureIgnoreCase); + var aggregatedProperty = false; + // locate hints that match properties in the ContentItemVersionRecord foreach (var hit in contentItemVersionMetadata.PropertyNames.Where(hintDictionary.ContainsKey).SelectMany(key => hintDictionary[key])) { contentItemVersionCriteria.UnderlyingCriteria.SetFetchMode(hit.Hint, FetchMode.Eager); @@ -303,7 +307,7 @@ namespace Orchard.ContentManagement { hit.Segments.Take(hit.Segments.Count() - 1).Aggregate(contentItemCriteria.UnderlyingCriteria, ExtendCriteria); } - // if (hintDictionary.SelectMany(x => x.Value).Any(x => x.Segments.Count() > 1)) + if (hintDictionary.SelectMany(x => x.Value).Any(x => x.Segments.Count() > 1)) contentItemVersionCriteria.TransformUsing(new DistinctRootEntityResultTransformer()); return this; diff --git a/src/Orchard/Data/Conventions/AggregateAttribute.cs b/src/Orchard/Data/Conventions/AggregateAttribute.cs index d15354a11..b83d5fe70 100644 --- a/src/Orchard/Data/Conventions/AggregateAttribute.cs +++ b/src/Orchard/Data/Conventions/AggregateAttribute.cs @@ -23,7 +23,7 @@ namespace Orchard.Data.Conventions { } public void Apply(IOneToManyCollectionInstance instance) { - instance.Fetch.Join(); + instance.Fetch.Select(); instance.Cache.ReadWrite(); } From 2fee00e1c5678fcef2ef857df45045fda448c0f2 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 17 Aug 2012 16:28:51 -0700 Subject: [PATCH 4/8] Polishing markdown editor style --HG-- branch : 1.x --- .../Modules/Markdown/Styles/admin-markdown.css | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Orchard.Web/Modules/Markdown/Styles/admin-markdown.css b/src/Orchard.Web/Modules/Markdown/Styles/admin-markdown.css index 5cc806cca..73a77fc1c 100644 --- a/src/Orchard.Web/Modules/Markdown/Styles/admin-markdown.css +++ b/src/Orchard.Web/Modules/Markdown/Styles/admin-markdown.css @@ -55,19 +55,32 @@ .wmd-preview blockquote { margin: 1em 3em; - color: #999; + color: #333; border-left: 2px solid #999; padding-left: 1em; } .wmd-preview pre, .wmd-preview code { margin: 1em 3em; - color: #999; + color: #333; border-left: 2px solid #999; padding-left: 1em; font-family: Courier New; } +.wmd-preview pre code { + border: none; + margin-left: 0px; + padding-left: 0px; +} + + +.wmd-preview p code { + border: none; + margin: 0px; + padding: 0px; +} + /* Grippie */ div.grippie { From 3fdfead729636a773c51f49f02847af54f0687fc Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 17 Aug 2012 16:31:42 -0700 Subject: [PATCH 5/8] Improving Content Query Custom extensions IStartingWith, IsEndingWith, IsContaining New IContentQuery.WhereAny to prevent the limitation from QueryOver to handle IEnumerable.Any() in expression queries --HG-- branch : 1.x --- .hgsubstate | 2 +- .../ContentManagement/ContentQueryTests.cs | 54 +++++++++++++ .../Orchard.Tags/Services/TagService.cs | 4 +- .../DefaultContentManager.cs | 3 + .../ContentManagement/DefaultContentQuery.cs | 16 +++- src/Orchard/ContentManagement/Diagram.cd | 77 ------------------- .../ContentManagement/IContentQuery.cs | 1 + .../RestrictionExtensions.cs | 53 +++++++++++++ src/Orchard/Orchard.Framework.csproj | 2 +- 9 files changed, 128 insertions(+), 84 deletions(-) delete mode 100644 src/Orchard/ContentManagement/Diagram.cd create mode 100644 src/Orchard/ContentManagement/RestrictionExtensions.cs diff --git a/.hgsubstate b/.hgsubstate index 392ce4ccb..fac0bee43 100644 --- a/.hgsubstate +++ b/.hgsubstate @@ -1,5 +1,5 @@ 1f8f582859916d411b5333dd0f32f57da0e72ee8 src/Orchard.Web/Modules/Orchard.AntiSpam -bb8c612e72535cbb28b03efb5f7c52e79ced61cd src/Orchard.Web/Modules/Orchard.Autoroute +5257b79de7ea0cdcd1bebc04f922fe9bbb127944 src/Orchard.Web/Modules/Orchard.Autoroute 2ca2dbbf97b7219f9150d46d52f62bc405c17673 src/Orchard.Web/Modules/Orchard.ContentPermissions e6e70d69f37e48ea6c8784e83a9af4103f5d0dde src/Orchard.Web/Modules/Orchard.ContentPicker b5ccdaed10ff8bcd5bc94d46541209873ae0f722 src/Orchard.Web/Modules/Orchard.CustomForms diff --git a/src/Orchard.Tests/ContentManagement/ContentQueryTests.cs b/src/Orchard.Tests/ContentManagement/ContentQueryTests.cs index ef6141fb2..e2dfcbac3 100644 --- a/src/Orchard.Tests/ContentManagement/ContentQueryTests.cs +++ b/src/Orchard.Tests/ContentManagement/ContentQueryTests.cs @@ -16,6 +16,7 @@ using Orchard.Tests.ContentManagement.Records; using Orchard.Tests.ContentManagement.Models; using Orchard.DisplayManagement.Implementation; using Orchard.Tests.Stubs; +using NHibernate.Impl; namespace Orchard.Tests.ContentManagement { [TestFixture] @@ -451,6 +452,59 @@ namespace Orchard.Tests.ContentManagement { Assert.That(listTwo.Count(), Is.EqualTo(2)); Assert.That(listThree.Count(), Is.EqualTo(1)); } + + [Test] + public void IsStartingExtensionShouldBeUsed() { + _manager.Create("gamma", init => { init.Record.Frap = "one"; }); + _manager.Create("gamma", init => { init.Record.Frap = "two"; }); + _manager.Create("gamma", init => { init.Record.Frap = "three"; }); + _manager.Create("gamma", init => { init.Record.Frap = "four"; }); + _session.Flush(); + + var result = _manager.Query() + .Where(x => x.Frap.IsStartingWith("t")) + .List(); + + Assert.That(result.Count(), Is.EqualTo(2)); + Assert.That(result.Count(x => x.Get().Record.Frap == "two"), Is.EqualTo(1)); + Assert.That(result.Count(x => x.Get().Record.Frap == "three"), Is.EqualTo(1)); + } + + [Test] + public void IsEndingExtensionShouldBeUsed() { + _manager.Create("gamma", init => { init.Record.Frap = "one"; }); + _manager.Create("gamma", init => { init.Record.Frap = "two"; }); + _manager.Create("gamma", init => { init.Record.Frap = "three"; }); + _manager.Create("gamma", init => { init.Record.Frap = "four"; }); + _session.Flush(); + + var result = _manager.Query() + .Where(x => x.Frap.IsEndingWith("e")) + .List(); + + Assert.That(result.Count(), Is.EqualTo(2)); + Assert.That(result.Count(x => x.Get().Record.Frap == "one"), Is.EqualTo(1)); + Assert.That(result.Count(x => x.Get().Record.Frap == "three"), Is.EqualTo(1)); + } + + [Test] + public void IsContainingExtensionShouldBeUsed() { + _manager.Create("gamma", init => { init.Record.Frap = "one"; }); + _manager.Create("gamma", init => { init.Record.Frap = "two"; }); + _manager.Create("gamma", init => { init.Record.Frap = "three"; }); + _manager.Create("gamma", init => { init.Record.Frap = "four"; }); + _session.Flush(); + + var result = _manager.Query() + .Where(x => x.Frap.IsContaining("o")) + .List(); + + Assert.That(result.Count(), Is.EqualTo(3)); + Assert.That(result.Count(x => x.Get().Record.Frap == "one"), Is.EqualTo(1)); + Assert.That(result.Count(x => x.Get().Record.Frap == "two"), Is.EqualTo(1)); + Assert.That(result.Count(x => x.Get().Record.Frap == "four"), Is.EqualTo(1)); + } + } } diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs b/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs index bd8a7e05b..4a93f6199 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs +++ b/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs @@ -143,8 +143,8 @@ namespace Orchard.Tags.Services { public int GetTaggedContentItemCount(int tagId, VersionOptions options) { return _orchardServices.ContentManager - .HqlQuery() - .Where(tpr => tpr.ContentPartRecord().Property("Tags", "tags"), x => x.Eq("TagRecord.Id", tagId)) + .Query() + .WhereAny(part => part.Tags, tag => tag.Id == tagId) .Count(); } diff --git a/src/Orchard/ContentManagement/DefaultContentManager.cs b/src/Orchard/ContentManagement/DefaultContentManager.cs index cfd91b0b3..419dadcb2 100644 --- a/src/Orchard/ContentManagement/DefaultContentManager.cs +++ b/src/Orchard/ContentManagement/DefaultContentManager.cs @@ -34,6 +34,9 @@ namespace Orchard.ContentManagement { private const string Published = "Published"; private const string Draft = "Draft"; + static DefaultContentManager() { + RestrictionExtensions.RegisterExtensions(); + } public DefaultContentManager( IComponentContext context, IRepository contentTypeRepository, diff --git a/src/Orchard/ContentManagement/DefaultContentQuery.cs b/src/Orchard/ContentManagement/DefaultContentQuery.cs index fd0def33b..069e3cc9a 100644 --- a/src/Orchard/ContentManagement/DefaultContentQuery.cs +++ b/src/Orchard/ContentManagement/DefaultContentQuery.cs @@ -103,7 +103,14 @@ namespace Orchard.ContentManagement { } private void Where(Expression> predicate) where TRecord : ContentPartRecord { - BindPartQueryOver().Where(predicate); + var processedCriteria = NHibernate.Impl.ExpressionProcessor.ProcessExpression(predicate); + BindPartQueryOver().Where(processedCriteria); + //BindPartQueryOver().WithSubquery.WhereSome(.Where(predicate); + } + + private void WhereAny(Expression>> selector, Expression> predicate) where TRecord : ContentPartRecord { + //var address = BindPartQueryOver() QueryOver.Of().Where(selector); + BindPartQueryOver().JoinQueryOver(selector).Where(predicate); } private void OrderBy(Expression> keySelector) where TRecord : ContentPartRecord { @@ -256,6 +263,11 @@ namespace Orchard.ContentManagement { return this; } + IContentQuery IContentQuery.WhereAny(Expression>> selector, Expression> predicate) { + _query.WhereAny(selector, predicate); + return this; + } + IContentQuery IContentQuery.OrderBy(Expression> keySelector) { _query.OrderBy(keySelector); return this; @@ -293,8 +305,6 @@ namespace Orchard.ContentManagement { .GroupBy(item => item.Segments.FirstOrDefault()) .ToDictionary(grouping => grouping.Key, StringComparer.InvariantCultureIgnoreCase); - var aggregatedProperty = false; - // locate hints that match properties in the ContentItemVersionRecord foreach (var hit in contentItemVersionMetadata.PropertyNames.Where(hintDictionary.ContainsKey).SelectMany(key => hintDictionary[key])) { contentItemVersionCriteria.UnderlyingCriteria.SetFetchMode(hit.Hint, FetchMode.Eager); diff --git a/src/Orchard/ContentManagement/Diagram.cd b/src/Orchard/ContentManagement/Diagram.cd deleted file mode 100644 index 6fc3fb202..000000000 --- a/src/Orchard/ContentManagement/Diagram.cd +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - AAACAAAAAAACAAhAABAAAAAAAAAAQABAAAAQAAAEBAA= - Models\ContentItem.cs - - - - - - - - - - - - - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAA= - Models\ContentPart.cs - - - - - - - - - - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAA= - Models\ContentPart.cs - - - - - - AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAA= - Models\Records\ContentItemRecord.cs - - - - - - - - - AAACAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA= - Models\Records\ContentTypeRecord.cs - - - - - - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAA= - Models\IContent.cs - - - - - - AAAAEAAAAAAAACBBAIAAAAAAAAEAAEgAAACAAAAAAAA= - Models\IContentManager.cs - - - - - - AAAAEAAAAAEAAABBAIAAAIAAACEAAAQAAACAAAAAAAg= - Models\Driver\IContentHandler.cs - - - - \ No newline at end of file diff --git a/src/Orchard/ContentManagement/IContentQuery.cs b/src/Orchard/ContentManagement/IContentQuery.cs index 946f47de7..6421f3c24 100644 --- a/src/Orchard/ContentManagement/IContentQuery.cs +++ b/src/Orchard/ContentManagement/IContentQuery.cs @@ -32,6 +32,7 @@ namespace Orchard.ContentManagement { new IContentQuery ForVersion(VersionOptions options); IContentQuery Where(Expression> predicate); + IContentQuery WhereAny(Expression>> selector, Expression> predicate); IContentQuery OrderBy(Expression> keySelector); IContentQuery OrderByDescending(Expression> keySelector); diff --git a/src/Orchard/ContentManagement/RestrictionExtensions.cs b/src/Orchard/ContentManagement/RestrictionExtensions.cs new file mode 100644 index 000000000..15324392f --- /dev/null +++ b/src/Orchard/ContentManagement/RestrictionExtensions.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using NHibernate.Criterion; +using NHibernate.Impl; +using Orchard.ContentManagement.Records; + +namespace Orchard.ContentManagement { + public static class RestrictionExtensions { + public static void RegisterExtensions() { + ExpressionProcessor.RegisterCustomMethodCall(() => RestrictionExtensions.IsStartingWith("", ""), RestrictionExtensions.ProcessIsStartingWith); + ExpressionProcessor.RegisterCustomMethodCall(() => RestrictionExtensions.IsEndingWith("", ""), RestrictionExtensions.ProcessIsEndingWith); + ExpressionProcessor.RegisterCustomMethodCall(() => RestrictionExtensions.IsContaining("", ""), RestrictionExtensions.ProcessIsContaining); + } + + public static bool IsStartingWith(this string item, string value) { + throw new NotImplementedException("Do not use this method directly"); + } + + public static bool IsEndingWith(this string item, string value) { + throw new NotImplementedException("Do not use this method directly"); + } + + public static bool IsContaining(this string item, string value) { + throw new NotImplementedException("Do not use this method directly"); + } + + public static ICriterion ProcessIsStartingWith(MethodCallExpression methodCallExpression) { + ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + MatchMode matchMode = MatchMode.Start; + return projection.Create(s => Restrictions.InsensitiveLike(s, value, matchMode), p => Restrictions.InsensitiveLike(p, value, matchMode)); + } + + + public static ICriterion ProcessIsEndingWith(MethodCallExpression methodCallExpression) { + ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + MatchMode matchMode = MatchMode.End; + return projection.Create(s => Restrictions.InsensitiveLike(s, value, matchMode), p => Restrictions.InsensitiveLike(p, value, matchMode)); + } + + + public static ICriterion ProcessIsContaining(MethodCallExpression methodCallExpression) { + ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); + string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + MatchMode matchMode = MatchMode.Anywhere; + return projection.Create(s => Restrictions.InsensitiveLike(s, value, matchMode), p => Restrictions.InsensitiveLike(p, value, matchMode)); + } + } +} diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 7b76f8631..963bb3b27 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -171,6 +171,7 @@ + @@ -906,7 +907,6 @@ - From 8427029ed75829f816eae316c321a77e93bdbefa Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 17 Aug 2012 16:33:25 -0700 Subject: [PATCH 6/8] Updating .hgignore to remove Visual Studio's test results --HG-- branch : 1.x --- .hgignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgignore b/.hgignore index 1c1635c97..4e3fd9c8b 100644 --- a/.hgignore +++ b/.hgignore @@ -26,3 +26,4 @@ glob:src/Orchard.Azure/Orchard.Azure.Web/Modules glob:src/Orchard.Azure/Orchard.Azure.Web/Themes syntax: glob src/Orchard.Web/Orchard.Web.Publish.xml +glob:src/TestResults/* From ac256e9c06154edbf5107f29e19e7966c6bdd435 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 20 Aug 2012 11:08:44 -0700 Subject: [PATCH 7/8] Implementing StartsWith, EndsWith and Contains query extensions for NH QueryOver. --HG-- branch : 1.x --- .hgsubstate | 2 +- .../ContentManagement/ContentQueryTests.cs | 13 ++++--- .../RestrictionExtensions.cs | 36 +++++++------------ 3 files changed, 19 insertions(+), 32 deletions(-) diff --git a/.hgsubstate b/.hgsubstate index fac0bee43..5a60f5eb9 100644 --- a/.hgsubstate +++ b/.hgsubstate @@ -1,5 +1,5 @@ 1f8f582859916d411b5333dd0f32f57da0e72ee8 src/Orchard.Web/Modules/Orchard.AntiSpam -5257b79de7ea0cdcd1bebc04f922fe9bbb127944 src/Orchard.Web/Modules/Orchard.Autoroute +e270989b0b0bcee22c03021af5a028215bcdefe9 src/Orchard.Web/Modules/Orchard.Autoroute 2ca2dbbf97b7219f9150d46d52f62bc405c17673 src/Orchard.Web/Modules/Orchard.ContentPermissions e6e70d69f37e48ea6c8784e83a9af4103f5d0dde src/Orchard.Web/Modules/Orchard.ContentPicker b5ccdaed10ff8bcd5bc94d46541209873ae0f722 src/Orchard.Web/Modules/Orchard.CustomForms diff --git a/src/Orchard.Tests/ContentManagement/ContentQueryTests.cs b/src/Orchard.Tests/ContentManagement/ContentQueryTests.cs index e2dfcbac3..0e23583bd 100644 --- a/src/Orchard.Tests/ContentManagement/ContentQueryTests.cs +++ b/src/Orchard.Tests/ContentManagement/ContentQueryTests.cs @@ -454,7 +454,7 @@ namespace Orchard.Tests.ContentManagement { } [Test] - public void IsStartingExtensionShouldBeUsed() { + public void StartsWithExtensionShouldBeUsed() { _manager.Create("gamma", init => { init.Record.Frap = "one"; }); _manager.Create("gamma", init => { init.Record.Frap = "two"; }); _manager.Create("gamma", init => { init.Record.Frap = "three"; }); @@ -462,7 +462,7 @@ namespace Orchard.Tests.ContentManagement { _session.Flush(); var result = _manager.Query() - .Where(x => x.Frap.IsStartingWith("t")) + .Where(x => x.Frap.StartsWith("t")) .List(); Assert.That(result.Count(), Is.EqualTo(2)); @@ -471,7 +471,7 @@ namespace Orchard.Tests.ContentManagement { } [Test] - public void IsEndingExtensionShouldBeUsed() { + public void EndsWithExtensionShouldBeUsed() { _manager.Create("gamma", init => { init.Record.Frap = "one"; }); _manager.Create("gamma", init => { init.Record.Frap = "two"; }); _manager.Create("gamma", init => { init.Record.Frap = "three"; }); @@ -479,7 +479,7 @@ namespace Orchard.Tests.ContentManagement { _session.Flush(); var result = _manager.Query() - .Where(x => x.Frap.IsEndingWith("e")) + .Where(x => x.Frap.EndsWith("e")) .List(); Assert.That(result.Count(), Is.EqualTo(2)); @@ -488,7 +488,7 @@ namespace Orchard.Tests.ContentManagement { } [Test] - public void IsContainingExtensionShouldBeUsed() { + public void ContainsExtensionShouldBeUsed() { _manager.Create("gamma", init => { init.Record.Frap = "one"; }); _manager.Create("gamma", init => { init.Record.Frap = "two"; }); _manager.Create("gamma", init => { init.Record.Frap = "three"; }); @@ -496,7 +496,7 @@ namespace Orchard.Tests.ContentManagement { _session.Flush(); var result = _manager.Query() - .Where(x => x.Frap.IsContaining("o")) + .Where(x => x.Frap.Contains("o")) .List(); Assert.That(result.Count(), Is.EqualTo(3)); @@ -504,7 +504,6 @@ namespace Orchard.Tests.ContentManagement { Assert.That(result.Count(x => x.Get().Record.Frap == "two"), Is.EqualTo(1)); Assert.That(result.Count(x => x.Get().Record.Frap == "four"), Is.EqualTo(1)); } - } } diff --git a/src/Orchard/ContentManagement/RestrictionExtensions.cs b/src/Orchard/ContentManagement/RestrictionExtensions.cs index 15324392f..b47d2ef38 100644 --- a/src/Orchard/ContentManagement/RestrictionExtensions.cs +++ b/src/Orchard/ContentManagement/RestrictionExtensions.cs @@ -10,42 +10,30 @@ using Orchard.ContentManagement.Records; namespace Orchard.ContentManagement { public static class RestrictionExtensions { public static void RegisterExtensions() { - ExpressionProcessor.RegisterCustomMethodCall(() => RestrictionExtensions.IsStartingWith("", ""), RestrictionExtensions.ProcessIsStartingWith); - ExpressionProcessor.RegisterCustomMethodCall(() => RestrictionExtensions.IsEndingWith("", ""), RestrictionExtensions.ProcessIsEndingWith); - ExpressionProcessor.RegisterCustomMethodCall(() => RestrictionExtensions.IsContaining("", ""), RestrictionExtensions.ProcessIsContaining); + ExpressionProcessor.RegisterCustomMethodCall(() => "".StartsWith(""), RestrictionExtensions.ProcessStartsWith); + ExpressionProcessor.RegisterCustomMethodCall(() => "".EndsWith(""), RestrictionExtensions.ProcessEndsWith); + ExpressionProcessor.RegisterCustomMethodCall(() => "".Contains(""), RestrictionExtensions.ProcessContains); } - public static bool IsStartingWith(this string item, string value) { - throw new NotImplementedException("Do not use this method directly"); - } - - public static bool IsEndingWith(this string item, string value) { - throw new NotImplementedException("Do not use this method directly"); - } - - public static bool IsContaining(this string item, string value) { - throw new NotImplementedException("Do not use this method directly"); - } - - public static ICriterion ProcessIsStartingWith(MethodCallExpression methodCallExpression) { - ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + public static ICriterion ProcessStartsWith(MethodCallExpression methodCallExpression) { + ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Object); + string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[0]); MatchMode matchMode = MatchMode.Start; return projection.Create(s => Restrictions.InsensitiveLike(s, value, matchMode), p => Restrictions.InsensitiveLike(p, value, matchMode)); } - public static ICriterion ProcessIsEndingWith(MethodCallExpression methodCallExpression) { - ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + public static ICriterion ProcessEndsWith(MethodCallExpression methodCallExpression) { + ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Object); + string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[0]); MatchMode matchMode = MatchMode.End; return projection.Create(s => Restrictions.InsensitiveLike(s, value, matchMode), p => Restrictions.InsensitiveLike(p, value, matchMode)); } - public static ICriterion ProcessIsContaining(MethodCallExpression methodCallExpression) { - ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Arguments[0]); - string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[1]); + public static ICriterion ProcessContains(MethodCallExpression methodCallExpression) { + ExpressionProcessor.ProjectionInfo projection = ExpressionProcessor.FindMemberProjection(methodCallExpression.Object); + string value = (string)ExpressionProcessor.FindValue(methodCallExpression.Arguments[0]); MatchMode matchMode = MatchMode.Anywhere; return projection.Create(s => Restrictions.InsensitiveLike(s, value, matchMode), p => Restrictions.InsensitiveLike(p, value, matchMode)); } From 5c7dadfa920404fe3590f76372793b36bacfe10d Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 20 Aug 2012 15:10:40 -0700 Subject: [PATCH 8/8] Updating TagsService to use WhereAny() --HG-- branch : 1.x --- .../Modules/Orchard.Tags/Services/TagService.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs b/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs index 4a93f6199..bc090f338 100644 --- a/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs +++ b/src/Orchard.Web/Modules/Orchard.Tags/Services/TagService.cs @@ -131,9 +131,9 @@ namespace Orchard.Tags.Services { public IEnumerable GetTaggedContentItems(int tagId, int skip, int take, VersionOptions options) { return _orchardServices.ContentManager - .HqlQuery() - .Where(tpr => tpr.ContentPartRecord().Property("Tags", "tags"), x => x.Eq("TagRecord.Id", tagId)) - .OrderBy(alias => alias.ContentPartRecord(), x => x.Desc("CreatedUtc")) + .Query() + .WhereAny(part => part.Tags, tag => tag.TagRecord.Id == tagId) + .Join().OrderByDescending(x => x.CreatedUtc) .Slice(skip, take); } @@ -144,7 +144,7 @@ namespace Orchard.Tags.Services { public int GetTaggedContentItemCount(int tagId, VersionOptions options) { return _orchardServices.ContentManager .Query() - .WhereAny(part => part.Tags, tag => tag.Id == tagId) + .WhereAny(part => part.Tags, tag => tag.TagRecord.Id == tagId) .Count(); }