Fix Page commands and migration

--HG--
branch : autoroute
This commit is contained in:
randompete
2011-12-07 23:47:57 +00:00
parent 37640d1c08
commit 404180927a
2 changed files with 24 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ using Orchard.Core.Common.Models;
using Orchard.Core.Routable.Models;
using Orchard.Security;
using Orchard.Settings;
using Orchard.Core.Title.Models;
namespace Orchard.Pages.Commands {
public class PageCommands : DefaultOrchardCommandHandler {
@@ -44,7 +45,7 @@ namespace Orchard.Pages.Commands {
public bool UseWelcomeText { get; set; }
[CommandName("page create")]
[CommandHelp("page create /Slug:<slug> /Title:<title> /Path:<path> [/Text:<text>] [/Owner:<username>] [/Homepage:true|false] [/Publish:true|false] [/UseWelcomeText:true|false]\r\n\t" + "Creates a new page")]
[CommandHelp("page create [/Slug:<slug>] /Title:<title> /Path:<path> [/Text:<text>] [/Owner:<username>] [/Homepage:true|false] [/Publish:true|false] [/UseWelcomeText:true|false]\r\n\t" + "Creates a new page")]
[OrchardSwitches("Slug,Title,Path,Text,Owner,Homepage,Publish,UseWelcomeText")]
public void Create() {
if (String.IsNullOrEmpty(Owner)) {
@@ -52,11 +53,17 @@ namespace Orchard.Pages.Commands {
}
var owner = _membershipService.GetUser(Owner);
var page = _contentManager.Create("Page", VersionOptions.Draft);
page.As<RoutePart>().Title = Title;
page.As<RoutePart>().Path = Path;
page.As<RoutePart>().Slug = Slug;
page.As<RoutePart>().PromoteToHomePage = Homepage;
page.As<TitlePart>().Title = Title;
page.As<ICommonPart>().Owner = owner;
// (PH:Autoroute) Hackish way to leave Slug and Homepage switches intact without requiring a dependency on Autoroute. This may throw an Exception with
// no AutoroutePart. But it means that normal setup recipes will still be able to give you a homepage without issue.
dynamic dpage = page;
if (dpage.AutoroutePart != null && (Homepage || !String.IsNullOrWhiteSpace(Slug))) {
dpage.AutoroutePart.UseCustomPattern = true;
dpage.AutoroutePart.CustomPattern = Slug;
}
var text = String.Empty;
if (UseWelcomeText) {
text = T(

View File

@@ -10,16 +10,26 @@ namespace Orchard.Pages {
.WithPart("CommonPart", p => p
.WithSetting("DateEditorSettings.ShowDateEditor", "true"))
.WithPart("PublishLaterPart")
.WithPart("RoutePart")
.WithPart("TitlePart")
.WithPart("AutoroutePart")
.WithPart("BodyPart")
.Creatable());
return 2;
return 3;
}
public int UpdateFrom1() {
ContentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg.WithPart("CommonPart", p => p.WithSetting("DateEditorSettings.ShowDateEditor", "true")));
return 2;
}
public int UpdateFrom2() {
// TODO: (PH:Autoroute) Copy routes/titles
ContentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg
.RemovePart("RoutePart")
.WithPart("TitlePart")
.WithPart("AutoroutePart"));
return 3;
}
}
}