mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 11:44:41 +08:00
#18957: Fixing blog creationg from command line
Work Item: 18957 --HG-- branch : 1.x
This commit is contained in:
@@ -68,7 +68,7 @@ namespace Orchard.Blogs.Commands {
|
|||||||
|
|
||||||
[CommandName("blog create")]
|
[CommandName("blog create")]
|
||||||
[CommandHelp("blog create [/Slug:<slug>] /Title:<title> [/Owner:<username>] [/Description:<description>] [/MenuName:<name>] [/MenuText:<menu text>] [/Homepage:true|false]\r\n\t" + "Creates a new Blog")]
|
[CommandHelp("blog create [/Slug:<slug>] /Title:<title> [/Owner:<username>] [/Description:<description>] [/MenuName:<name>] [/MenuText:<menu text>] [/Homepage:true|false]\r\n\t" + "Creates a new Blog")]
|
||||||
[OrchardSwitches("Title,Owner,Description,MenuText,Homepage,MenuName")]
|
[OrchardSwitches("Slug,Title,Owner,Description,MenuText,Homepage,MenuName")]
|
||||||
public void Create() {
|
public void Create() {
|
||||||
if (String.IsNullOrEmpty(Owner)) {
|
if (String.IsNullOrEmpty(Owner)) {
|
||||||
Owner = _siteService.GetSiteSettings().SuperUser;
|
Owner = _siteService.GetSiteSettings().SuperUser;
|
||||||
@@ -86,18 +86,6 @@ namespace Orchard.Blogs.Commands {
|
|||||||
if (!String.IsNullOrEmpty(Description)) {
|
if (!String.IsNullOrEmpty(Description)) {
|
||||||
blog.As<BlogPart>().Description = Description;
|
blog.As<BlogPart>().Description = Description;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !String.IsNullOrWhiteSpace(MenuText) ) {
|
|
||||||
var menu = _menuService.GetMenu(MenuName);
|
|
||||||
|
|
||||||
if (menu != null) {
|
|
||||||
var menuItem = _contentManager.Create<ContentMenuItemPart>("ContentMenuItem");
|
|
||||||
menuItem.Content = blog;
|
|
||||||
menuItem.As<MenuPart>().MenuPosition = Position.GetNext(_navigationManager.BuildMenu(menu));
|
|
||||||
menuItem.As<MenuPart>().MenuText = MenuText;
|
|
||||||
menuItem.As<MenuPart>().Menu = menu;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Homepage || !String.IsNullOrWhiteSpace(Slug)) {
|
if (Homepage || !String.IsNullOrWhiteSpace(Slug)) {
|
||||||
dynamic dblog = blog;
|
dynamic dblog = blog;
|
||||||
@@ -109,6 +97,18 @@ namespace Orchard.Blogs.Commands {
|
|||||||
|
|
||||||
_contentManager.Create(blog);
|
_contentManager.Create(blog);
|
||||||
|
|
||||||
|
if (!String.IsNullOrWhiteSpace(MenuText)) {
|
||||||
|
var menu = _menuService.GetMenu(MenuName);
|
||||||
|
|
||||||
|
if (menu != null) {
|
||||||
|
var menuItem = _contentManager.Create<ContentMenuItemPart>("ContentMenuItem");
|
||||||
|
menuItem.Content = blog;
|
||||||
|
menuItem.As<MenuPart>().MenuPosition = _navigationManager.GetNextPosition(menu);
|
||||||
|
menuItem.As<MenuPart>().MenuText = MenuText;
|
||||||
|
menuItem.As<MenuPart>().Menu = menu;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Context.Output.WriteLine(T("Blog created successfully"));
|
Context.Output.WriteLine(T("Blog created successfully"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ namespace Orchard.UI.Navigation {
|
|||||||
IEnumerable<MenuItem> BuildMenu(IContent menu);
|
IEnumerable<MenuItem> BuildMenu(IContent menu);
|
||||||
IEnumerable<string> BuildImageSets(string menuName);
|
IEnumerable<string> BuildImageSets(string menuName);
|
||||||
string GetUrl(string menuItemUrl, RouteValueDictionary routeValueDictionary);
|
string GetUrl(string menuItemUrl, RouteValueDictionary routeValueDictionary);
|
||||||
|
string GetNextPosition(IContent menu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ using Orchard.Logging;
|
|||||||
using Orchard.Security;
|
using Orchard.Security;
|
||||||
using Orchard.Security.Permissions;
|
using Orchard.Security.Permissions;
|
||||||
using Orchard.UI.Admin;
|
using Orchard.UI.Admin;
|
||||||
|
using Orchard.Utility;
|
||||||
|
|
||||||
namespace Orchard.UI.Navigation {
|
namespace Orchard.UI.Navigation {
|
||||||
public class NavigationManager : INavigationManager {
|
public class NavigationManager : INavigationManager {
|
||||||
@@ -38,12 +39,17 @@ namespace Orchard.UI.Navigation {
|
|||||||
|
|
||||||
public IEnumerable<MenuItem> BuildMenu(string menuName) {
|
public IEnumerable<MenuItem> BuildMenu(string menuName) {
|
||||||
var sources = GetSources(menuName);
|
var sources = GetSources(menuName);
|
||||||
return FinishMenu(Reduce(Merge(sources)).ToArray());
|
return FinishMenu(Reduce(Merge(sources), menuName == "admin").ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<MenuItem> BuildMenu(IContent menu) {
|
public IEnumerable<MenuItem> BuildMenu(IContent menu) {
|
||||||
var sources = GetSources(menu);
|
var sources = GetSources(menu);
|
||||||
return FinishMenu(Reduce(Arrange(Filter(Merge(sources)))).ToArray());
|
return FinishMenu(Reduce(Arrange(Filter(Merge(sources))), false).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetNextPosition(IContent menu) {
|
||||||
|
var sources = GetSources(menu);
|
||||||
|
return Position.GetNext(Reduce(Arrange(Filter(Merge(sources))), false).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> BuildImageSets(string menuName) {
|
public IEnumerable<string> BuildImageSets(string menuName) {
|
||||||
@@ -91,9 +97,8 @@ namespace Orchard.UI.Navigation {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the items by checking for permissions
|
/// Updates the items by checking for permissions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private IEnumerable<MenuItem> Reduce(IEnumerable<MenuItem> items) {
|
private IEnumerable<MenuItem> Reduce(IEnumerable<MenuItem> items, bool isAdminMenu) {
|
||||||
var hasDebugShowAllMenuItems = _authorizationService.TryCheckAccess(Permission.Named("DebugShowAllMenuItems"), _orchardServices.WorkContext.CurrentUser, null);
|
var hasDebugShowAllMenuItems = _authorizationService.TryCheckAccess(Permission.Named("DebugShowAllMenuItems"), _orchardServices.WorkContext.CurrentUser, null);
|
||||||
var isAdminMenu = AdminFilter.IsApplied(_urlHelper.RequestContext);
|
|
||||||
|
|
||||||
foreach (var item in items) {
|
foreach (var item in items) {
|
||||||
if (
|
if (
|
||||||
@@ -107,7 +112,7 @@ namespace Orchard.UI.Navigation {
|
|||||||
isAdminMenu && (!item.Permissions.Any() || item.Permissions.Any(x => _authorizationService.TryCheckAccess(x, _orchardServices.WorkContext.CurrentUser, null))) ) {
|
isAdminMenu && (!item.Permissions.Any() || item.Permissions.Any(x => _authorizationService.TryCheckAccess(x, _orchardServices.WorkContext.CurrentUser, null))) ) {
|
||||||
|
|
||||||
yield return new MenuItem {
|
yield return new MenuItem {
|
||||||
Items = Reduce(item.Items),
|
Items = Reduce(item.Items, isAdminMenu),
|
||||||
Permissions = item.Permissions,
|
Permissions = item.Permissions,
|
||||||
Position = item.Position,
|
Position = item.Position,
|
||||||
RouteValues = item.RouteValues,
|
RouteValues = item.RouteValues,
|
||||||
|
|||||||
Reference in New Issue
Block a user