diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs index c19c83eaf..f6ccfe672 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Drivers/AutoroutePartDriver.cs @@ -75,13 +75,23 @@ namespace Orchard.Autoroute.Drivers { } } + //we update the settings assuming that when + //pattern culture = null it means culture = default website culture + //for patterns that we migrated + foreach (RoutePattern pattern in settings.Patterns.Where(x => String.IsNullOrEmpty(x.Culture))) { + pattern.Culture = _cultureManager.GetSiteCulture(); ; + } + + //we do the same for default patterns + foreach (DefaultPattern pattern in settings.DefaultPatterns.Where(x => String.IsNullOrEmpty(x.Culture))) { + pattern.Culture = _cultureManager.GetSiteCulture(); + } + // if the content type has no pattern for autoroute, then use a default one if (!settings.Patterns.Any(x => x.Culture == itemCulture)) { settings.AllowCustomPattern = true; settings.AutomaticAdjustmentOnEdit = false; settings.Patterns = new List { new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = itemCulture } }; - - _notifier.Warning(T("No route patterns are currently defined for this Content Type. If you don't set one in the settings, a default one will be used.")); } // if the content type has no defaultPattern for autoroute, then use a default one diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs index ada4364bd..09ff40d68 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Migrations.cs @@ -3,21 +3,14 @@ using Orchard.Autoroute.Services; using Orchard.Autoroute.Settings; using Orchard.ContentManagement; using Orchard.ContentManagement.MetaData; +using Orchard.ContentManagement.MetaData.Models; using Orchard.Core.Contents.Extensions; using Orchard.Data.Migration; using System.Collections.Generic; +using System.Linq; namespace Orchard.Autoroute { public class Migrations : DataMigrationImpl { - private readonly IAutorouteService _autorouteService; - private readonly IContentManager _contentManager; - - public Migrations( - IAutorouteService autorouteService, - IContentManager contentManager) { - _autorouteService = autorouteService; - _contentManager = contentManager; - } public int Create() { SchemaBuilder.CreateTable("AutoroutePartRecord", @@ -25,6 +18,7 @@ namespace Orchard.Autoroute { .ContentPartVersionRecord() .Column("CustomPattern", c => c.WithLength(2048)) .Column("UseCustomPattern", c => c.WithDefault(false)) + .Column("UseCulturePattern", c => c.WithDefault(false)) .Column("DisplayAlias", c => c.WithLength(2048))); ContentDefinitionManager.AlterPartDefinition("AutoroutePart", part => part @@ -35,7 +29,7 @@ namespace Orchard.Autoroute { .CreateIndex("IDX_AutoroutePartRecord_DisplayAlias", "DisplayAlias") ); - return 3; + return 4; } public int UpdateFrom1() { @@ -59,13 +53,14 @@ namespace Orchard.Autoroute { .AddColumn("UseCulturePattern", c => c.WithDefault(false)) ); - // populate the AutorouteSettings.DefaultPatternDefinitions AutoroutePart settings - foreach (var autoroutePart in _contentManager.Query().List()) { - var settings = autoroutePart.Settings.GetModel(); - string patternIndex = autoroutePart.Settings["AutorouteSettings.DefaultPatternIndex"]; - settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = patternIndex, Culture = "" } }; + foreach (ContentTypeDefinition contentTypeDefinition in ContentDefinitionManager.ListTypeDefinitions()) { + foreach (ContentTypePartDefinition contentTypePartDefinition in contentTypeDefinition.Parts.Where(x => x.PartDefinition.Name == "AutoroutePart")) { + var settings = contentTypePartDefinition.Settings.GetModel(); + string patternIndex = contentTypePartDefinition.Settings["AutorouteSettings.DefaultPatternIndex"]; + settings.DefaultPatterns = new List { new DefaultPattern { PatternIndex = patternIndex, Culture = "" } }; - ContentDefinitionManager.AlterTypeDefinition(autoroutePart.TypeDefinition.Name, builder => builder.WithPart("AutoroutePart", settings.Build)); + ContentDefinitionManager.AlterTypeDefinition(contentTypeDefinition.Name, builder => builder.WithPart("AutoroutePart", settings.Build)); + } } return 4; diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs index 15234b71c..97d61324f 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Providers/ContentDefinition/ContentDefinitionEventHandler.cs @@ -82,6 +82,8 @@ namespace Orchard.Autoroute.Providers.ContentDefinition { _contentDefinitionManager.AlterTypeDefinition(context.ContentTypeName, builder => builder.WithPart("AutoroutePart", settings.Build)); //TODO Generate URL's for existing content items + //We should provide a global setting to enable/disable this feature + } } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs index cd7993b81..51cc23ead 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettings.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Web.Script.Serialization; using Orchard.ContentManagement.MetaData.Builders; +using Orchard.Services; namespace Orchard.Autoroute.Settings { @@ -39,7 +39,7 @@ namespace Orchard.Autoroute.Settings { public List Patterns { get { if (_patterns == null) { - _patterns = new JavaScriptSerializer().Deserialize(PatternDefinitions).ToList(); + _patterns = new DefaultJsonConverter().Deserialize(PatternDefinitions).ToList(); } return _patterns; @@ -47,7 +47,7 @@ namespace Orchard.Autoroute.Settings { set { _patterns = value; - PatternDefinitions = new JavaScriptSerializer().Serialize(_patterns.ToArray()); + PatternDefinitions = new DefaultJsonConverter().Serialize(_patterns.ToArray()); } } @@ -59,7 +59,7 @@ namespace Orchard.Autoroute.Settings { public List DefaultPatterns { get { if (_defaultPatterns == null) { - _defaultPatterns = new JavaScriptSerializer().Deserialize(DefaultPatternDefinitions).ToList(); + _defaultPatterns = new DefaultJsonConverter().Deserialize(DefaultPatternDefinitions).ToList(); } //We split the values from the radio button returned values @@ -86,7 +86,7 @@ namespace Orchard.Autoroute.Settings { } i++; } - DefaultPatternDefinitions = new JavaScriptSerializer().Serialize(_defaultPatterns.ToArray()); + DefaultPatternDefinitions = new DefaultJsonConverter().Serialize(_defaultPatterns.ToArray()); } } diff --git a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs index f21cc0339..18a970916 100644 --- a/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs +++ b/src/Orchard.Web/Modules/Orchard.Autoroute/Settings/AutorouteSettingsEvents.cs @@ -62,9 +62,9 @@ namespace Orchard.Autoroute.Settings { //We add a pattern for each culture if there is none if (!settings.Patterns.Where(x => x.Culture == culture).Any()) { //We add the default pattern from migrations - if (settings.Patterns.Where(x => x.Culture == "").Any()) { + if (settings.Patterns.Where(x => String.IsNullOrEmpty(x.Culture)).Any()) { //we add the RoutePattern and we set the culture since there is none defined - RoutePattern migrationRoutePattern = settings.Patterns.Where(x => x.Culture == "").First(); + RoutePattern migrationRoutePattern = settings.Patterns.Where(x => String.IsNullOrEmpty(x.Culture)).First(); newPatterns.Add(new RoutePattern { Culture = culture, Name = migrationRoutePattern.Name, Description = migrationRoutePattern.Description, Pattern = migrationRoutePattern.Pattern }); } else { //we add the default pattern for custom content types or modules that don't define it in their migration @@ -107,7 +107,7 @@ namespace Orchard.Autoroute.Settings { List newPatterns = new List(); int current = 0; foreach (string culture in settings.SiteCultures) { - if (settings.Patterns.Any(x => x.Culture == culture)) { + if (settings.Patterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { foreach (RoutePattern routePattern in settings.Patterns.Where(x => x.Culture == culture)) { newPatterns.Add(settings.Patterns[current]); current++; diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs index 6672f4fea..7915220e0 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs @@ -39,8 +39,7 @@ namespace Orchard.Blogs { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-blog\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-blog\"}]")) .WithPart("MenuPart") .WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "2")) ); @@ -58,8 +57,7 @@ namespace Orchard.Blogs { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Blog and Title\",\"Pattern\":\"{Content.Container.Path}/{Content.Slug}\",\"Description\":\"my-blog/my-post\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Blog and Title\",\"Pattern\":\"{Content.Container.Path}/{Content.Slug}\",\"Description\":\"my-blog/my-post\"}]")) .WithPart("BodyPart") .Draftable() ); diff --git a/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs b/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs index 82d6c36f7..2dcb18a4c 100644 --- a/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.CustomForms/Migrations.cs @@ -12,8 +12,8 @@ namespace Orchard.CustomForms { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\"}]") + .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) .WithPart("MenuPart") .WithPart("CustomFormPart") .DisplayedAs("Custom Form") diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs index 2da3ad651..f55753b3c 100644 --- a/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/Migrations.cs @@ -21,8 +21,7 @@ namespace Orchard.DynamicForms { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\"}]") - .WithSetting("AutorouteSettings.DefaultPatternIndex", "0")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\"}]")) .WithPart("LayoutPart", p => p .WithSetting("LayoutTypePartSettings.DefaultLayoutData", "{" + @@ -66,15 +65,5 @@ namespace Orchard.DynamicForms { .DisplayedAs("Form Widget")); return 1; } - - public int UpdateFrom1() { - ContentDefinitionManager.AlterTypeDefinition("Form", type => type - .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-form\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) - ); - - return 2; - } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs index 767737719..07fca7109 100644 --- a/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Lists/Migrations.cs @@ -11,10 +11,9 @@ namespace Orchard.Lists { .WithPart("ContainerPart") .WithPart("MenuPart") .WithPart("AutoroutePart", builder => builder - .WithSetting("AutorouteSettings.AllowCustomPattern", "True") - .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-list\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]"))); + .WithSetting("AutorouteSettings.AllowCustomPattern", "True") + .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-list\"}]"))); return 4; } diff --git a/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs index 61e979a2a..202c08c3c 100644 --- a/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Pages/Migrations.cs @@ -5,7 +5,7 @@ using Orchard.Data.Migration; namespace Orchard.Pages { public class Migrations : DataMigrationImpl { public int Create() { - ContentDefinitionManager.AlterTypeDefinition("Page", + ContentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg .WithPart("CommonPart", p => p .WithSetting("DateEditorSettings.ShowDateEditor", "True")) @@ -14,8 +14,7 @@ namespace Orchard.Pages { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-page\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-page\"}]")) .WithPart("LayoutPart") .Creatable() .Listable() diff --git a/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs index 6b6888439..5c201cc9b 100644 --- a/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Projections/Migrations.cs @@ -126,7 +126,7 @@ namespace Orchard.Projections { .Column("CreateLabel") .Column("Label", c => c.WithLength(255)) .Column("LinkToContent") - + .Column("CustomizePropertyHtml") .Column("CustomPropertyTag", c => c.WithLength(64)) .Column("CustomPropertyCss", c => c.WithLength(64)) @@ -190,8 +190,7 @@ namespace Orchard.Projections { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-projections\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-projections\"}]")) .WithPart("MenuPart") .WithPart("ProjectionPart") .WithPart("AdminMenuPart", p => p.WithSetting("AdminMenuPartTypeSettings.DefaultPosition", "5")) diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs index 5b9cca080..24adc8610 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Migrations.cs @@ -36,8 +36,7 @@ namespace Orchard.Taxonomies { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "True") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "False") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-taxonomy\",\"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{\"Name\":\"Title\",\"Pattern\":\"{Content.Slug}\",\"Description\":\"my-taxonomy\"}]")) ); SchemaBuilder.CreateTable("TermsPartRecord", table => table diff --git a/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs b/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs index a71ded72c..a6d6b14d0 100644 --- a/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs +++ b/src/Orchard.Web/Modules/Orchard.Taxonomies/Services/TaxonomyService.cs @@ -105,8 +105,7 @@ namespace Orchard.Taxonomies.Services { .WithPart("AutoroutePart", builder => builder .WithSetting("AutorouteSettings.AllowCustomPattern", "true") .WithSetting("AutorouteSettings.AutomaticAdjustmentOnEdit", "false") - .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Taxonomy and Title', Pattern: '{Content.Container.Path}/{Content.Slug}', Description: 'my-taxonomy/my-term/sub-term', \"Culture\":\"\"}]") - .WithSetting("AutorouteSettings.DefaultPatternDefinitions", "[{\"PatternIndex\":\"0\",\"Culture\":\"\"}]")) + .WithSetting("AutorouteSettings.PatternDefinitions", "[{Name:'Taxonomy and Title', Pattern: '{Content.Container.Path}/{Content.Slug}', Description: 'my-taxonomy/my-term/sub-term'}]")) .WithPart("CommonPart") .DisplayedAs(taxonomy.Name + " Term") ); @@ -216,8 +215,7 @@ namespace Orchard.Taxonomies.Services { termPart.As().Container = GetTaxonomy(termPart.TaxonomyId).ContentItem; _contentManager.Create(termPart); - } - else { + } else { _notifier.Warning(T("The term {0} already exists in this taxonomy", termPart.Name)); } } @@ -282,8 +280,7 @@ namespace Orchard.Taxonomies.Services { tpr => tpr.Terms.Any(tr => tr.TermRecord.Id == term.Id || tr.TermRecord.Path.StartsWith(rootPath))); - } - else { + } else { query = query.Where( tpr => tpr.Terms.Any(tr => tr.Field == fieldName