mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#5375: Added current theme recipe step.
This enables exporting the current theme setting and restoring it during import.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
FeatureDescription: Basic theming capability.
|
||||
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
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<IISExpressAnonymousAuthentication />
|
||||
<IISExpressWindowsAuthentication />
|
||||
<IISExpressUseClassicPipelineMode />
|
||||
<UseGlobalApplicationHostFile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -60,6 +61,7 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\lib\aspnetmvc\System.Web.Mvc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.XML" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -67,6 +69,9 @@
|
||||
<Compile Include="Commands\ThemeCommands.cs" />
|
||||
<Compile Include="Drivers\DisableThemePartDriver.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="Models\ThemeEntry.cs" />
|
||||
<Compile Include="Models\DisableThemePart.cs" />
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user