mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Fix Page commands and migration
--HG-- branch : autoroute
This commit is contained in:
@@ -6,6 +6,7 @@ using Orchard.Core.Common.Models;
|
|||||||
using Orchard.Core.Routable.Models;
|
using Orchard.Core.Routable.Models;
|
||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
using Orchard.Settings;
|
using Orchard.Settings;
|
||||||
|
using Orchard.Core.Title.Models;
|
||||||
|
|
||||||
namespace Orchard.Pages.Commands {
|
namespace Orchard.Pages.Commands {
|
||||||
public class PageCommands : DefaultOrchardCommandHandler {
|
public class PageCommands : DefaultOrchardCommandHandler {
|
||||||
@@ -44,7 +45,7 @@ namespace Orchard.Pages.Commands {
|
|||||||
public bool UseWelcomeText { get; set; }
|
public bool UseWelcomeText { get; set; }
|
||||||
|
|
||||||
[CommandName("page create")]
|
[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")]
|
[OrchardSwitches("Slug,Title,Path,Text,Owner,Homepage,Publish,UseWelcomeText")]
|
||||||
public void Create() {
|
public void Create() {
|
||||||
if (String.IsNullOrEmpty(Owner)) {
|
if (String.IsNullOrEmpty(Owner)) {
|
||||||
@@ -52,11 +53,17 @@ namespace Orchard.Pages.Commands {
|
|||||||
}
|
}
|
||||||
var owner = _membershipService.GetUser(Owner);
|
var owner = _membershipService.GetUser(Owner);
|
||||||
var page = _contentManager.Create("Page", VersionOptions.Draft);
|
var page = _contentManager.Create("Page", VersionOptions.Draft);
|
||||||
page.As<RoutePart>().Title = Title;
|
page.As<TitlePart>().Title = Title;
|
||||||
page.As<RoutePart>().Path = Path;
|
|
||||||
page.As<RoutePart>().Slug = Slug;
|
|
||||||
page.As<RoutePart>().PromoteToHomePage = Homepage;
|
|
||||||
page.As<ICommonPart>().Owner = owner;
|
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;
|
var text = String.Empty;
|
||||||
if (UseWelcomeText) {
|
if (UseWelcomeText) {
|
||||||
text = T(
|
text = T(
|
||||||
|
|||||||
@@ -10,16 +10,26 @@ namespace Orchard.Pages {
|
|||||||
.WithPart("CommonPart", p => p
|
.WithPart("CommonPart", p => p
|
||||||
.WithSetting("DateEditorSettings.ShowDateEditor", "true"))
|
.WithSetting("DateEditorSettings.ShowDateEditor", "true"))
|
||||||
.WithPart("PublishLaterPart")
|
.WithPart("PublishLaterPart")
|
||||||
.WithPart("RoutePart")
|
.WithPart("TitlePart")
|
||||||
|
.WithPart("AutoroutePart")
|
||||||
.WithPart("BodyPart")
|
.WithPart("BodyPart")
|
||||||
.Creatable());
|
.Creatable());
|
||||||
|
|
||||||
return 2;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int UpdateFrom1() {
|
public int UpdateFrom1() {
|
||||||
ContentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg.WithPart("CommonPart", p => p.WithSetting("DateEditorSettings.ShowDateEditor", "true")));
|
ContentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg.WithPart("CommonPart", p => p.WithSetting("DateEditorSettings.ShowDateEditor", "true")));
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int UpdateFrom2() {
|
||||||
|
// TODO: (PH:Autoroute) Copy routes/titles
|
||||||
|
ContentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg
|
||||||
|
.RemovePart("RoutePart")
|
||||||
|
.WithPart("TitlePart")
|
||||||
|
.WithPart("AutoroutePart"));
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user