mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Added the ability to generate a Setup recipe using the export feature.
This commit is contained in:
@@ -74,6 +74,7 @@ namespace Orchard.ImportExport.Controllers {
|
||||
_customExportStep.Register(customSteps);
|
||||
|
||||
var viewModel = new ExportViewModel {
|
||||
RecipeVersion = "1.0",
|
||||
ContentTypes = new List<ContentTypeEntry>(),
|
||||
CustomSteps = customSteps.Select(x => new CustomStepEntry { CustomStep = x }).ToList()
|
||||
};
|
||||
@@ -102,6 +103,11 @@ namespace Orchard.ImportExport.Controllers {
|
||||
var exportOptions = new ExportOptions {
|
||||
ExportMetadata = viewModel.Metadata,
|
||||
ExportSiteSettings = viewModel.SiteSettings,
|
||||
SetupRecipe = viewModel.SetupRecipe,
|
||||
RecipeDescription = viewModel.RecipeDescription,
|
||||
RecipeWebsite = viewModel.RecipeWebsite,
|
||||
RecipeTags = viewModel.RecipeTags,
|
||||
RecipeVersion = viewModel.RecipeVersion,
|
||||
CustomSteps = customSteps
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,11 @@ namespace Orchard.ImportExport.Models {
|
||||
public VersionHistoryOptions VersionHistoryOptions { get; set; }
|
||||
public bool ExportSiteSettings { get; set; }
|
||||
public IEnumerable<string> CustomSteps { get; set; }
|
||||
public bool SetupRecipe { get; set; }
|
||||
public string RecipeDescription { get; set; }
|
||||
public string RecipeWebsite { get; set; }
|
||||
public string RecipeTags { get; set; }
|
||||
public string RecipeVersion { get; set; }
|
||||
}
|
||||
|
||||
public enum VersionHistoryOptions {
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Orchard.ImportExport.Services {
|
||||
}
|
||||
|
||||
public string Export(IEnumerable<string> contentTypes, IEnumerable<ContentItem> contentItems, ExportOptions exportOptions) {
|
||||
var exportDocument = CreateExportRoot();
|
||||
var exportDocument = CreateExportRoot(exportOptions);
|
||||
|
||||
var context = new ExportContext {
|
||||
Document = exportDocument,
|
||||
@@ -99,14 +99,19 @@ namespace Orchard.ImportExport.Services {
|
||||
return WriteExportFile(exportDocument.ToString());
|
||||
}
|
||||
|
||||
private XDocument CreateExportRoot() {
|
||||
private XDocument CreateExportRoot(ExportOptions exportOptions) {
|
||||
var exportRoot = new XDocument(
|
||||
new XDeclaration("1.0", "", "yes"),
|
||||
new XComment("Exported from Orchard"),
|
||||
new XElement("Orchard",
|
||||
new XElement("Recipe",
|
||||
new XElement("Name", "Generated by Orchard.ImportExport"),
|
||||
new XElement("Description", exportOptions.RecipeDescription),
|
||||
new XElement("Author", _orchardServices.WorkContext.CurrentUser.UserName),
|
||||
new XElement("WebSite", exportOptions.RecipeWebsite),
|
||||
new XElement("Tags", exportOptions.RecipeTags),
|
||||
new XElement("Version", exportOptions.RecipeVersion),
|
||||
new XElement("IsSetupRecipe", exportOptions.SetupRecipe),
|
||||
new XElement("ExportUtc", XmlConvert.ToString(_clock.UtcNow, XmlDateTimeSerializationMode.Utc))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -9,6 +9,11 @@ namespace Orchard.ImportExport.ViewModels {
|
||||
public int? ImportBatchSize { get; set; }
|
||||
public string DataImportChoice { get; set; }
|
||||
public bool SiteSettings { get; set; }
|
||||
public bool SetupRecipe { get; set; }
|
||||
public string RecipeDescription { get; set; }
|
||||
public string RecipeWebsite { get; set; }
|
||||
public string RecipeTags { get; set; }
|
||||
public string RecipeVersion { get; set; }
|
||||
}
|
||||
|
||||
public class ContentTypeEntry {
|
||||
|
||||
@@ -21,46 +21,74 @@
|
||||
<legend>@T("Choose what to save for these types:")</legend>
|
||||
<div>
|
||||
@Html.EditorFor(m => m.Metadata)
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.Metadata)">@T("Metadata")</label>
|
||||
@Html.LabelFor(m => m.Metadata, T("Batch Size").ToString(), new { @class = "forcheckbox" })
|
||||
@Html.Hint(T("Metadata is the definition of your content types: what parts and fields they have, with what settings."))
|
||||
</div>
|
||||
<div>
|
||||
@Html.EditorFor(m => m.Data)
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.Data)">@T("Data")</label>
|
||||
@Html.LabelFor(m => m.Data, T("Data").ToString(), new { @class = "forcheckbox" })
|
||||
@Html.Hint(T("Data is the actual content of your site."))
|
||||
</div>
|
||||
<div>
|
||||
@Html.LabelFor(m => m.ImportBatchSize, T("Batch Size"))
|
||||
@Html.TextBoxFor(m => m.ImportBatchSize, new { @class = "text small" })
|
||||
@Html.TextBoxFor(m => m.ImportBatchSize, new {@class = "text small"})
|
||||
@Html.Hint(T("The batch size to use when importing the data. Leave empty to disable batched imports."))
|
||||
</div>
|
||||
<div>
|
||||
<p>@T("Version History")</p>
|
||||
@Html.RadioButtonFor(m => m.DataImportChoice, "Published", new { id = "Published", Checked = "Checked" })
|
||||
<label for="@Html.FieldIdFor(m => m.DataImportChoice)" class="forcheckbox">@T("Only Published Versions")</label>
|
||||
<br />
|
||||
@Html.RadioButtonFor(m => m.DataImportChoice, "Draft", new { id = "Draft" })
|
||||
<label for="@Html.FieldIdFor(m => m.DataImportChoice)" class="forcheckbox">@T("Only Drafts")</label>
|
||||
@Html.RadioButtonFor(m => m.DataImportChoice, "Published", new {id = "Published", Checked = "Checked"})
|
||||
<label for="Published" class="forcheckbox">@T("Only Published Versions")</label>
|
||||
<br/>
|
||||
@Html.RadioButtonFor(m => m.DataImportChoice, "Draft", new {id = "Draft"})
|
||||
<label for="Draft" class="forcheckbox">@T("Only Drafts")</label>
|
||||
</div>
|
||||
<div>
|
||||
@Html.EditorFor(m => m.SiteSettings)
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.SiteSettings)">@T("Site Settings")</label><br />
|
||||
<label class="forcheckbox" for="@Html.FieldIdFor(m => m.SiteSettings)">@T("Site Settings")</label><br/>
|
||||
@Html.Hint(T("Please verify that you are not exporting confidential information, such as passwords or application keys."))
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>@T("Setup")</legend>
|
||||
<div>
|
||||
@Html.CheckBoxFor(m => m.SetupRecipe)
|
||||
@Html.LabelFor(m => m.SetupRecipe, T("Setup Recipe").ToString(), new {@class = "forcheckbox"})
|
||||
@Html.Hint(T("Check this option if you want to use the generated recipe as a setup recipe."))
|
||||
</div>
|
||||
<div data-controllerid="@Html.FieldIdFor(m => m.SetupRecipe)">
|
||||
<div>
|
||||
@Html.LabelFor(m => m.RecipeDescription, T("Description"))
|
||||
@Html.TextBoxFor(m => m.RecipeDescription, new {@class = "text large"})
|
||||
@Html.Hint(T("Optionally provide a description for the setup recipe."))
|
||||
</div>
|
||||
<div>
|
||||
@Html.LabelFor(m => m.RecipeWebsite, T("Website"))
|
||||
@Html.TextBoxFor(m => m.RecipeWebsite, new {@class = "text large"})
|
||||
@Html.Hint(T("Optionally provide a website URL for the setup recipe."))
|
||||
</div>
|
||||
<div>
|
||||
@Html.LabelFor(m => m.RecipeTags, T("Tags"))
|
||||
@Html.TextBoxFor(m => m.RecipeTags, new {@class = "text large"})
|
||||
@Html.Hint(T("Optionally provide tags for the setup recipe."))
|
||||
</div>
|
||||
<div>
|
||||
@Html.LabelFor(m => m.RecipeVersion, T("Version"))
|
||||
@Html.TextBoxFor(m => m.RecipeVersion, new { @class = "text small" })
|
||||
@Html.Hint(T("Optionally provide a version for the setup recipe."))
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
if (Model.CustomSteps.Any()) {
|
||||
<fieldset>
|
||||
<legend>@T("Choose the custom steps to execute in the export file:")</legend>
|
||||
<ol>
|
||||
@{ var customStepIndex = 0; }
|
||||
@foreach (var customStepEntry in Model.CustomSteps) {
|
||||
@for (var customStepIndex = 0; customStepIndex < Model.CustomSteps.Count; customStepIndex++) {
|
||||
<li>
|
||||
<input type="hidden" value="@Model.CustomSteps[customStepIndex].CustomStep" name="@Html.NameOf(m => m.CustomSteps[customStepIndex].CustomStep)"/>
|
||||
<input type="checkbox" value="true" name="@Html.NameOf(m => m.CustomSteps[customStepIndex].IsChecked)" id="@Html.NameOf(m => m.CustomSteps[customStepIndex].IsChecked)" />
|
||||
<label class="forcheckbox" for="@Html.NameOf(m => m.CustomSteps[customStepIndex].IsChecked)">@Model.CustomSteps[customStepIndex].CustomStep.CamelFriendly()</label>
|
||||
</li>
|
||||
customStepIndex = customStepIndex + 1;
|
||||
}
|
||||
</ol>
|
||||
</fieldset>
|
||||
|
||||
Reference in New Issue
Block a user