Added the ability to generate a Setup recipe using the export feature.

This commit is contained in:
Sipke Schoorstra
2015-07-13 17:56:20 +01:00
parent dbc6f61b5c
commit 6d2832ef08
5 changed files with 71 additions and 22 deletions

View File

@@ -74,6 +74,7 @@ namespace Orchard.ImportExport.Controllers {
_customExportStep.Register(customSteps); _customExportStep.Register(customSteps);
var viewModel = new ExportViewModel { var viewModel = new ExportViewModel {
RecipeVersion = "1.0",
ContentTypes = new List<ContentTypeEntry>(), ContentTypes = new List<ContentTypeEntry>(),
CustomSteps = customSteps.Select(x => new CustomStepEntry { CustomStep = x }).ToList() CustomSteps = customSteps.Select(x => new CustomStepEntry { CustomStep = x }).ToList()
}; };
@@ -102,6 +103,11 @@ namespace Orchard.ImportExport.Controllers {
var exportOptions = new ExportOptions { var exportOptions = new ExportOptions {
ExportMetadata = viewModel.Metadata, ExportMetadata = viewModel.Metadata,
ExportSiteSettings = viewModel.SiteSettings, ExportSiteSettings = viewModel.SiteSettings,
SetupRecipe = viewModel.SetupRecipe,
RecipeDescription = viewModel.RecipeDescription,
RecipeWebsite = viewModel.RecipeWebsite,
RecipeTags = viewModel.RecipeTags,
RecipeVersion = viewModel.RecipeVersion,
CustomSteps = customSteps CustomSteps = customSteps
}; };

View File

@@ -8,6 +8,11 @@ namespace Orchard.ImportExport.Models {
public VersionHistoryOptions VersionHistoryOptions { get; set; } public VersionHistoryOptions VersionHistoryOptions { get; set; }
public bool ExportSiteSettings { get; set; } public bool ExportSiteSettings { get; set; }
public IEnumerable<string> CustomSteps { 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 { public enum VersionHistoryOptions {

View File

@@ -72,7 +72,7 @@ namespace Orchard.ImportExport.Services {
} }
public string Export(IEnumerable<string> contentTypes, IEnumerable<ContentItem> contentItems, ExportOptions exportOptions) { public string Export(IEnumerable<string> contentTypes, IEnumerable<ContentItem> contentItems, ExportOptions exportOptions) {
var exportDocument = CreateExportRoot(); var exportDocument = CreateExportRoot(exportOptions);
var context = new ExportContext { var context = new ExportContext {
Document = exportDocument, Document = exportDocument,
@@ -99,18 +99,23 @@ namespace Orchard.ImportExport.Services {
return WriteExportFile(exportDocument.ToString()); return WriteExportFile(exportDocument.ToString());
} }
private XDocument CreateExportRoot() { private XDocument CreateExportRoot(ExportOptions exportOptions) {
var exportRoot = new XDocument( var exportRoot = new XDocument(
new XDeclaration("1.0", "", "yes"), new XDeclaration("1.0", "", "yes"),
new XComment("Exported from Orchard"), new XComment("Exported from Orchard"),
new XElement("Orchard", new XElement("Orchard",
new XElement("Recipe", new XElement("Recipe",
new XElement("Name", "Generated by Orchard.ImportExport"), new XElement("Name", "Generated by Orchard.ImportExport"),
new XElement("Author", _orchardServices.WorkContext.CurrentUser.UserName), new XElement("Description", exportOptions.RecipeDescription),
new XElement("ExportUtc", XmlConvert.ToString(_clock.UtcNow, XmlDateTimeSerializationMode.Utc)) 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))
) )
); )
);
return exportRoot; return exportRoot;
} }

View File

@@ -9,6 +9,11 @@ namespace Orchard.ImportExport.ViewModels {
public int? ImportBatchSize { get; set; } public int? ImportBatchSize { get; set; }
public string DataImportChoice { get; set; } public string DataImportChoice { get; set; }
public bool SiteSettings { 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 { public class ContentTypeEntry {

View File

@@ -20,47 +20,75 @@
<fieldset> <fieldset>
<legend>@T("Choose what to save for these types:")</legend> <legend>@T("Choose what to save for these types:")</legend>
<div> <div>
@Html.EditorFor(m => m.Metadata) @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.")) @Html.Hint(T("Metadata is the definition of your content types: what parts and fields they have, with what settings."))
</div> </div>
<div> <div>
@Html.EditorFor(m => m.Data) @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.")) @Html.Hint(T("Data is the actual content of your site."))
</div> </div>
<div> <div>
@Html.LabelFor(m => m.ImportBatchSize, T("Batch Size")) @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.")) @Html.Hint(T("The batch size to use when importing the data. Leave empty to disable batched imports."))
</div> </div>
<div> <div>
<p>@T("Version History")</p> <p>@T("Version History")</p>
@Html.RadioButtonFor(m => m.DataImportChoice, "Published", new { id = "Published", Checked = "Checked" }) @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> <label for="Published" class="forcheckbox">@T("Only Published Versions")</label>
<br /> <br/>
@Html.RadioButtonFor(m => m.DataImportChoice, "Draft", new { id = "Draft" }) @Html.RadioButtonFor(m => m.DataImportChoice, "Draft", new {id = "Draft"})
<label for="@Html.FieldIdFor(m => m.DataImportChoice)" class="forcheckbox">@T("Only Drafts")</label> <label for="Draft" class="forcheckbox">@T("Only Drafts")</label>
</div> </div>
<div> <div>
@Html.EditorFor(m => m.SiteSettings) @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.")) @Html.Hint(T("Please verify that you are not exporting confidential information, such as passwords or application keys."))
</div> </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> </fieldset>
if (Model.CustomSteps.Any()) { if (Model.CustomSteps.Any()) {
<fieldset> <fieldset>
<legend>@T("Choose the custom steps to execute in the export file:")</legend> <legend>@T("Choose the custom steps to execute in the export file:")</legend>
<ol> <ol>
@{ var customStepIndex = 0; } @for (var customStepIndex = 0; customStepIndex < Model.CustomSteps.Count; customStepIndex++) {
@foreach (var customStepEntry in Model.CustomSteps) {
<li> <li>
<input type="hidden" value="@Model.CustomSteps[customStepIndex].CustomStep" name="@Html.NameOf(m => m.CustomSteps[customStepIndex].CustomStep)"/> <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)" /> <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> <label class="forcheckbox" for="@Html.NameOf(m => m.CustomSteps[customStepIndex].IsChecked)">@Model.CustomSteps[customStepIndex].CustomStep.CamelFriendly()</label>
</li> </li>
customStepIndex = customStepIndex + 1;
} }
</ol> </ol>
</fieldset> </fieldset>