mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Added support for default configurations, enabling a full site export.
The command "export file" with no arguments will export everything.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
@@ -18,19 +19,22 @@ namespace Orchard.ImportExport.Commands {
|
|||||||
private readonly ISiteService _siteService;
|
private readonly ISiteService _siteService;
|
||||||
private readonly IMembershipService _membershipService;
|
private readonly IMembershipService _membershipService;
|
||||||
private readonly IAuthenticationService _authenticationService;
|
private readonly IAuthenticationService _authenticationService;
|
||||||
|
private readonly IEnumerable<IExportAction> _exportActions;
|
||||||
|
|
||||||
public ImportExportCommands(
|
public ImportExportCommands(
|
||||||
IImportExportService importExportService,
|
IImportExportService importExportService,
|
||||||
IContentDefinitionManager contentDefinitionManager,
|
IContentDefinitionManager contentDefinitionManager,
|
||||||
ISiteService siteService,
|
ISiteService siteService,
|
||||||
IMembershipService membershipService,
|
IMembershipService membershipService,
|
||||||
IAuthenticationService authenticationService) {
|
IAuthenticationService authenticationService,
|
||||||
|
IEnumerable<IExportAction> exportActions) {
|
||||||
|
|
||||||
_importExportService = importExportService;
|
_importExportService = importExportService;
|
||||||
_contentDefinitionManager = contentDefinitionManager;
|
_contentDefinitionManager = contentDefinitionManager;
|
||||||
_siteService = siteService;
|
_siteService = siteService;
|
||||||
_membershipService = membershipService;
|
_membershipService = membershipService;
|
||||||
_authenticationService = authenticationService;
|
_authenticationService = authenticationService;
|
||||||
|
_exportActions = exportActions;
|
||||||
}
|
}
|
||||||
|
|
||||||
[OrchardSwitch]
|
[OrchardSwitch]
|
||||||
@@ -86,11 +90,19 @@ namespace Orchard.ImportExport.Commands {
|
|||||||
// Impersonate the Site owner.
|
// Impersonate the Site owner.
|
||||||
ImpersonateSuperUser();
|
ImpersonateSuperUser();
|
||||||
|
|
||||||
// Read config file if specified.
|
IEnumerable<IExportAction> actions;
|
||||||
var configurationDocument = UpdateExportConfiguration(ReadExportConfigurationFile(ConfigFilename), Types, Metadata, Data, Version, SiteSettings, Steps);
|
|
||||||
|
|
||||||
// Get all the steps based on the configuration.
|
if (!IsAnySwitchDefined("ConfigFilename", "Types", "Metadata", "Version", "SiteSettings", "Steps")) {
|
||||||
var actions = _importExportService.ParseExportActions(configurationDocument);
|
// Get default configured actions.
|
||||||
|
actions = GetDefaultConfiguration();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Read config file if specified.
|
||||||
|
var configurationDocument = UpdateExportConfiguration(ReadExportConfigurationFile(ConfigFilename), Types, Metadata, Data, Version, SiteSettings, Steps);
|
||||||
|
|
||||||
|
// Get all the steps based on the configuration.
|
||||||
|
actions = _importExportService.ParseExportActions(configurationDocument);
|
||||||
|
}
|
||||||
|
|
||||||
Context.Output.WriteLine(T("Export starting..."));
|
Context.Output.WriteLine(T("Export starting..."));
|
||||||
var exportContext = new ExportActionContext();
|
var exportContext = new ExportActionContext();
|
||||||
@@ -108,6 +120,18 @@ namespace Orchard.ImportExport.Commands {
|
|||||||
Context.Output.WriteLine(T("Export completed at {0}", exportFilePath));
|
Context.Output.WriteLine(T("Export completed at {0}", exportFilePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsAnySwitchDefined(params string[] switches) {
|
||||||
|
return Context.Switches.Keys.Any(switches.Contains);
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<IExportAction> GetDefaultConfiguration() {
|
||||||
|
foreach (var action in _exportActions) {
|
||||||
|
action.ConfigureDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _exportActions;
|
||||||
|
}
|
||||||
|
|
||||||
private XDocument UpdateExportConfiguration(XDocument configurationDocument, string types, bool metadata, bool data, string version, bool siteSettings, string customSteps) {
|
private XDocument UpdateExportConfiguration(XDocument configurationDocument, string types, bool metadata, bool data, string version, bool siteSettings, string customSteps) {
|
||||||
var buildRecipeElement = GetOrCreateElement(configurationDocument.Root, "BuildRecipe");
|
var buildRecipeElement = GetOrCreateElement(configurationDocument.Root, "BuildRecipe");
|
||||||
var stepsElement = GetOrCreateElement(buildRecipeElement, "Steps");
|
var stepsElement = GetOrCreateElement(buildRecipeElement, "Steps");
|
||||||
|
|||||||
@@ -80,6 +80,14 @@ namespace Orchard.ImportExport.Providers.ExportActions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ConfigureDefault() {
|
||||||
|
RecipeBuilderSteps = _recipeBuilderSteps.ToList();
|
||||||
|
|
||||||
|
foreach (var step in RecipeBuilderSteps) {
|
||||||
|
step.ConfigureDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Execute(ExportActionContext context) {
|
public override void Execute(ExportActionContext context) {
|
||||||
context.RecipeDocument = _recipeBuilder.Build(RecipeBuilderSteps);
|
context.RecipeDocument = _recipeBuilder.Build(RecipeBuilderSteps);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,10 @@ namespace Orchard.ImportExport.Recipes.Builders {
|
|||||||
CustomSteps = steps.ToList();
|
CustomSteps = steps.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ConfigureDefault() {
|
||||||
|
_customExportStep.Register(CustomSteps);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Build(BuildContext context) {
|
public override void Build(BuildContext context) {
|
||||||
var exportContext = new ExportContext {
|
var exportContext = new ExportContext {
|
||||||
Document = context.RecipeDocument,
|
Document = context.RecipeDocument,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Xml.Linq;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement;
|
|
||||||
using Orchard.ImportExport.Models;
|
using Orchard.ImportExport.Models;
|
||||||
|
|
||||||
namespace Orchard.ImportExport.Services {
|
namespace Orchard.ImportExport.Services {
|
||||||
@@ -22,6 +21,9 @@ namespace Orchard.ImportExport.Services {
|
|||||||
public virtual void Configure(ExportActionConfigurationContext context) {
|
public virtual void Configure(ExportActionConfigurationContext context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void ConfigureDefault() {
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void Execute(ExportActionContext context);
|
public abstract void Execute(ExportActionContext context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Xml.Linq;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement;
|
|
||||||
using Orchard.ImportExport.Models;
|
using Orchard.ImportExport.Models;
|
||||||
|
|
||||||
namespace Orchard.ImportExport.Services {
|
namespace Orchard.ImportExport.Services {
|
||||||
@@ -10,6 +9,7 @@ namespace Orchard.ImportExport.Services {
|
|||||||
dynamic BuildEditor(dynamic shapeFactory);
|
dynamic BuildEditor(dynamic shapeFactory);
|
||||||
dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater);
|
dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater);
|
||||||
void Configure(ExportActionConfigurationContext context);
|
void Configure(ExportActionConfigurationContext context);
|
||||||
|
void ConfigureDefault();
|
||||||
void Execute(ExportActionContext context);
|
void Execute(ExportActionContext context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,6 +58,11 @@ namespace Orchard.Modules.Recipes.Builders {
|
|||||||
ExportDisabledFeatures = context.ConfigurationElement.Attr<bool>("ExportDisabledFeatures");
|
ExportDisabledFeatures = context.ConfigurationElement.Attr<bool>("ExportDisabledFeatures");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ConfigureDefault() {
|
||||||
|
ExportEnabledFeatures = true;
|
||||||
|
ExportDisabledFeatures = false;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Build(BuildContext context) {
|
public override void Build(BuildContext context) {
|
||||||
if (!ExportEnabledFeatures && !ExportDisabledFeatures)
|
if (!ExportEnabledFeatures && !ExportDisabledFeatures)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -83,6 +83,12 @@ namespace Orchard.Recipes.Providers.Builders {
|
|||||||
VersionHistoryOptions = versionHistoryOptions;
|
VersionHistoryOptions = versionHistoryOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void ConfigureDefault() {
|
||||||
|
var contentTypeDefinitions = _contentDefinitionManager.ListTypeDefinitions().OrderBy(x => x.Name).ToList();
|
||||||
|
SchemaContentTypes = DataContentTypes = contentTypeDefinitions.Select(x => x.Name).ToList();
|
||||||
|
VersionHistoryOptions = VersionHistoryOptions.Published;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Build(BuildContext context) {
|
public override void Build(BuildContext context) {
|
||||||
var dataContentTypes = DataContentTypes;
|
var dataContentTypes = DataContentTypes;
|
||||||
var schemaContentTypes = SchemaContentTypes;
|
var schemaContentTypes = SchemaContentTypes;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace Orchard.Recipes.Services {
|
|||||||
dynamic BuildEditor(dynamic shapeFactory);
|
dynamic BuildEditor(dynamic shapeFactory);
|
||||||
dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater);
|
dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater);
|
||||||
void Configure(RecipeBuilderStepConfigurationContext configurationElement);
|
void Configure(RecipeBuilderStepConfigurationContext configurationElement);
|
||||||
|
void ConfigureDefault();
|
||||||
void Build(BuildContext context);
|
void Build(BuildContext context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,9 @@ namespace Orchard.Recipes.Services {
|
|||||||
public virtual void Configure(RecipeBuilderStepConfigurationContext context) {
|
public virtual void Configure(RecipeBuilderStepConfigurationContext context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void ConfigureDefault() {
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Build(BuildContext context) {}
|
public virtual void Build(BuildContext context) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user