#5337: Fixed homepage becoming lost after publishing layout template being used by the homepage.

Work Item: 5337
This commit is contained in:
Sipke Schoorstra
2015-07-02 13:37:20 +03:00
parent eebe29fec3
commit 2873eb8991
2 changed files with 38 additions and 2 deletions

View File

@@ -1,9 +1,13 @@
using Orchard.ContentManagement; using System;
using Orchard.Alias;
using Orchard.Autoroute.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using Orchard.Data; using Orchard.Data;
using Orchard.DisplayManagement; using Orchard.DisplayManagement;
using Orchard.Layouts.Models; using Orchard.Layouts.Models;
using Orchard.Layouts.Services; using Orchard.Layouts.Services;
using Orchard.Utility.Extensions;
namespace Orchard.Layouts.Handlers { namespace Orchard.Layouts.Handlers {
public class LayoutPartHandler : ContentHandler { public class LayoutPartHandler : ContentHandler {
@@ -13,6 +17,7 @@ namespace Orchard.Layouts.Handlers {
private readonly IShapeDisplay _shapeDisplay; private readonly IShapeDisplay _shapeDisplay;
private readonly ILayoutSerializer _serializer; private readonly ILayoutSerializer _serializer;
private readonly IStaticHttpContextScopeFactory _staticHttpContextScopeFactory; private readonly IStaticHttpContextScopeFactory _staticHttpContextScopeFactory;
private readonly IAliasService _aliasService;
public LayoutPartHandler( public LayoutPartHandler(
IRepository<LayoutPartRecord> repository, IRepository<LayoutPartRecord> repository,
@@ -21,7 +26,8 @@ namespace Orchard.Layouts.Handlers {
IContentPartDisplay contentPartDisplay, IContentPartDisplay contentPartDisplay,
IShapeDisplay shapeDisplay, IShapeDisplay shapeDisplay,
ILayoutSerializer serializer, ILayoutSerializer serializer,
IStaticHttpContextScopeFactory staticHttpContextScopeFactory) { IStaticHttpContextScopeFactory staticHttpContextScopeFactory,
IAliasService aliasService) {
_layoutManager = layoutManager; _layoutManager = layoutManager;
_contentManager = contentManager; _contentManager = contentManager;
@@ -29,6 +35,7 @@ namespace Orchard.Layouts.Handlers {
_shapeDisplay = shapeDisplay; _shapeDisplay = shapeDisplay;
_serializer = serializer; _serializer = serializer;
_staticHttpContextScopeFactory = staticHttpContextScopeFactory; _staticHttpContextScopeFactory = staticHttpContextScopeFactory;
_aliasService = aliasService;
Filters.Add(StorageFilter.For(repository)); Filters.Add(StorageFilter.For(repository));
OnPublished<LayoutPart>(UpdateTemplateClients); OnPublished<LayoutPart>(UpdateTemplateClients);
@@ -77,6 +84,12 @@ namespace Orchard.Layouts.Handlers {
draft.LayoutData = _serializer.Serialize(updatedLayout); draft.LayoutData = _serializer.Serialize(updatedLayout);
if (isPublished) { if (isPublished) {
// If the content being published is currently the homepage, we need to change the DisplayAlias from "" to "/"
// so that the autoroute part handler will not regenerate the alias and causes the homepage to become "lost".
if (IsHomePage(layout)) {
PromoteToHomePage(draft);
}
// We don't have to recurse here, since invoking Publish on a Layout will cause this handler to execute again. // We don't have to recurse here, since invoking Publish on a Layout will cause this handler to execute again.
_contentManager.Publish(draft.ContentItem); _contentManager.Publish(draft.ContentItem);
} }
@@ -85,5 +98,20 @@ namespace Orchard.Layouts.Handlers {
} }
} }
} }
private bool IsHomePage(IContent content) {
var homepage = _aliasService.Get(String.Empty);
var displayRouteValues = _contentManager.GetItemMetadata(content).DisplayRouteValues;
return homepage.Match(displayRouteValues);
}
private void PromoteToHomePage(IContent content) {
var autoroutePart = content.As<AutoroutePart>();
if (autoroutePart == null)
return;
autoroutePart.DisplayAlias = "/";
}
} }
} }

View File

@@ -287,6 +287,14 @@
<Project>{3158c928-888c-4a84-8bc1-4a8257489538}</Project> <Project>{3158c928-888c-4a84-8bc1-4a8257489538}</Project>
<Name>Markdown</Name> <Name>Markdown</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Orchard.Alias\Orchard.Alias.csproj">
<Project>{475b6c45-b27c-438b-8966-908b9d6d1077}</Project>
<Name>Orchard.Alias</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Autoroute\Orchard.Autoroute.csproj">
<Project>{66fccd76-2761-47e3-8d11-b45d0001ddaa}</Project>
<Name>Orchard.Autoroute</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Forms\Orchard.Forms.csproj"> <ProjectReference Include="..\Orchard.Forms\Orchard.Forms.csproj">
<Project>{642a49d7-8752-4177-80d6-bfbbcfad3de0}</Project> <Project>{642a49d7-8752-4177-80d6-bfbbcfad3de0}</Project>
<Name>Orchard.Forms</Name> <Name>Orchard.Forms</Name>