#5375: Added current theme recipe step.

This enables exporting the current theme setting and restoring it during import.
This commit is contained in:
Sipke Schoorstra
2015-07-13 14:37:41 +01:00
parent 171f7ad227
commit cb00640ecc
6 changed files with 113 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Orchard.Environment.Extensions;
using Orchard.Events;
using Orchard.Themes.Services;
namespace Orchard.Themes.ImportExport {
public interface IExportEventHandler : IEventHandler {
void Exporting(dynamic context);
void Exported(dynamic context);
}
[OrchardFeature("Orchard.Themes.ImportExportCurrentTheme")]
public class CurrentThemeExportHandler : IExportEventHandler {
private readonly ISiteThemeService _siteThemeService;
public CurrentThemeExportHandler(ISiteThemeService siteThemeService) {
_siteThemeService = siteThemeService;
}
public void Exporting(dynamic context) { }
public void Exported(dynamic context) {
if (!((IEnumerable<string>)context.ExportOptions.CustomSteps).Contains("CurrentTheme")) {
return;
}
var currentThemeId = _siteThemeService.GetCurrentThemeName();
var root = new XElement("CurrentTheme", new XAttribute("id", currentThemeId));
context.Document.Element("Orchard").Add(root);
}
}
}

View File

@@ -0,0 +1,27 @@
using System;
using Orchard.Environment.Extensions;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
using Orchard.Themes.Services;
namespace Orchard.Themes.ImportExport {
[OrchardFeature("Orchard.Themes.ImportExportCurrentTheme")]
public class CurrentThemeRecipeHandler : IRecipeHandler {
private readonly ISiteThemeService _siteThemeService;
public CurrentThemeRecipeHandler(ISiteThemeService siteThemeService) {
_siteThemeService = siteThemeService;
}
public void ExecuteRecipeStep(RecipeContext context) {
if (!String.Equals(context.RecipeStep.Name, "CurrentTheme", StringComparison.OrdinalIgnoreCase)) {
return;
}
var themeId = context.RecipeStep.Step.Attribute("id").Value;
_siteThemeService.SetSiteTheme(themeId);
context.Executed = true;
}
}
}

View File

@@ -0,0 +1,18 @@
using System.Collections.Generic;
using Orchard.Environment.Extensions;
using Orchard.Events;
namespace Orchard.Themes.ImportExport {
public interface ICustomExportStep : IEventHandler {
void Register(IList<string> steps);
}
[OrchardFeature("Orchard.Themes.ImportExportCurrentTheme")]
public class CurrentThemeStep : ICustomExportStep {
void ICustomExportStep.Register(IList<string> steps) {
steps.Add("CurrentTheme");
}
}
}

View File

@@ -8,3 +8,12 @@ OrchardVersion: 1.9
Description: The themes module makes it possible for Orchard applications to customize the look and feel of an Orchard web site. Description: The themes module makes it possible for Orchard applications to customize the look and feel of an Orchard web site.
FeatureDescription: Basic theming capability. FeatureDescription: Basic theming capability.
Category: Core Category: Core
Features:
Orchard.Themes:
Description: Basic theming capability.
Category: Core
Orchard.Themes.ImportExportCurrentTheme:
Name: Import Export Current Theme
Description: Provides the capability to import and export the current theme.
Category: Deployment
Dependencies: Orchard.ImportExport

View File

@@ -25,6 +25,7 @@
<IISExpressAnonymousAuthentication /> <IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication /> <IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode /> <IISExpressUseClassicPipelineMode />
<UseGlobalApplicationHostFile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@@ -60,6 +61,7 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\aspnetmvc\System.Web.Mvc.dll</HintPath> <HintPath>..\..\..\..\lib\aspnetmvc\System.Web.Mvc.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.XML" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -67,6 +69,9 @@
<Compile Include="Commands\ThemeCommands.cs" /> <Compile Include="Commands\ThemeCommands.cs" />
<Compile Include="Drivers\DisableThemePartDriver.cs" /> <Compile Include="Drivers\DisableThemePartDriver.cs" />
<Compile Include="Events\IExtensionDisplayEventHandler.cs" /> <Compile Include="Events\IExtensionDisplayEventHandler.cs" />
<Compile Include="ImportExport\CurrentThemeRecipeHandler.cs" />
<Compile Include="ImportExport\CurrentThemeExportHandler.cs" />
<Compile Include="ImportExport\CurrentThemeStep.cs" />
<Compile Include="Migrations.cs" /> <Compile Include="Migrations.cs" />
<Compile Include="Models\ThemeEntry.cs" /> <Compile Include="Models\ThemeEntry.cs" />
<Compile Include="Models\DisableThemePart.cs" /> <Compile Include="Models\DisableThemePart.cs" />

View File

@@ -0,0 +1,20 @@
using System;
using System.Xml.Linq;
namespace Orchard.ContentManagement.Handlers {
public class IdentifyDependenciesContext {
public IdentifyDependenciesContext(XElement contentElement, ImportContentSession importContentSession) {
ContentElement = contentElement;
ImportContentSession = importContentSession;
}
public XElement ContentElement { get; set; }
private ImportContentSession ImportContentSession { get; }
public void RegisterDependency(string id) {
if(!String.IsNullOrWhiteSpace(id))
ImportContentSession.RegisterDependency(new ContentIdentity(id));
}
}
}