mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Reverting changes in Migration.
Adding String.IsNullOrEmpty instead of == "" Fixed migration code to use ContentDefinitionManager only Fixed return numbers on migration using DefaultJsonConverter service in AutorouteSettings.cs
This commit is contained in:
@@ -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<RoutePattern> { 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
|
||||
|
||||
@@ -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<string>("CustomPattern", c => c.WithLength(2048))
|
||||
.Column<bool>("UseCustomPattern", c => c.WithDefault(false))
|
||||
.Column<bool>("UseCulturePattern", c => c.WithDefault(false))
|
||||
.Column<string>("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<bool>("UseCulturePattern", c => c.WithDefault(false))
|
||||
);
|
||||
|
||||
// populate the AutorouteSettings.DefaultPatternDefinitions AutoroutePart settings
|
||||
foreach (var autoroutePart in _contentManager.Query<AutoroutePart, AutoroutePartRecord>().List()) {
|
||||
var settings = autoroutePart.Settings.GetModel<AutorouteSettings>();
|
||||
string patternIndex = autoroutePart.Settings["AutorouteSettings.DefaultPatternIndex"];
|
||||
settings.DefaultPatterns = new List<DefaultPattern> { 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<AutorouteSettings>();
|
||||
string patternIndex = contentTypePartDefinition.Settings["AutorouteSettings.DefaultPatternIndex"];
|
||||
settings.DefaultPatterns = new List<DefaultPattern> { 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;
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<RoutePattern> Patterns {
|
||||
get {
|
||||
if (_patterns == null) {
|
||||
_patterns = new JavaScriptSerializer().Deserialize<RoutePattern[]>(PatternDefinitions).ToList();
|
||||
_patterns = new DefaultJsonConverter().Deserialize<RoutePattern[]>(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<DefaultPattern> DefaultPatterns {
|
||||
get {
|
||||
if (_defaultPatterns == null) {
|
||||
_defaultPatterns = new JavaScriptSerializer().Deserialize<DefaultPattern[]>(DefaultPatternDefinitions).ToList();
|
||||
_defaultPatterns = new DefaultJsonConverter().Deserialize<DefaultPattern[]>(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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<RoutePattern> newPatterns = new List<RoutePattern>();
|
||||
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++;
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace Orchard.Projections {
|
||||
.Column<bool>("CreateLabel")
|
||||
.Column<string>("Label", c => c.WithLength(255))
|
||||
.Column<bool>("LinkToContent")
|
||||
|
||||
|
||||
.Column<bool>("CustomizePropertyHtml")
|
||||
.Column<string>("CustomPropertyTag", c => c.WithLength(64))
|
||||
.Column<string>("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"))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<ICommonPart>().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
|
||||
|
||||
Reference in New Issue
Block a user