diff --git a/src/Orchard.Web/Modules/Orchard.ImportExport/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.ImportExport/Controllers/AdminController.cs index 5fede7055..70722eb8c 100644 --- a/src/Orchard.Web/Modules/Orchard.ImportExport/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.ImportExport/Controllers/AdminController.cs @@ -1,6 +1,9 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Web.Mvc; +using Orchard.ContentManagement.MetaData; using Orchard.ImportExport.Services; using Orchard.ImportExport.ViewModels; using Orchard.Localization; @@ -9,9 +12,11 @@ using Orchard.UI.Notify; namespace Orchard.ImportExport.Controllers { public class AdminController : Controller { private readonly IImportExportService _importExportService; + private readonly IContentDefinitionManager _contentDefinitionManager; - public AdminController(IOrchardServices services, IImportExportService importExportService) { + public AdminController(IOrchardServices services, IImportExportService importExportService, IContentDefinitionManager contentDefinitionManager) { _importExportService = importExportService; + _contentDefinitionManager = contentDefinitionManager; Services = services; T = NullLocalizer.Instance; } @@ -46,9 +51,32 @@ namespace Orchard.ImportExport.Controllers { } public ActionResult Export() { - var viewModel = new ExportViewModel(); - + var viewModel = new ExportViewModel { ContentTypes = new List() }; + foreach (var contentType in _contentDefinitionManager.ListTypeDefinitions()) { + viewModel.ContentTypes.Add(new ContentTypeEntry { ContentTypeName = contentType.Name }); + } return View(viewModel); } + + [HttpPost, ActionName("Export")] + public ActionResult ExportPOST() { + if (!Services.Authorizer.Authorize(Permissions.Export, T("Not allowed to export."))) + return new HttpUnauthorizedResult(); + + var viewModel = new ExportViewModel { ContentTypes = new List() }; + + try { + UpdateModel(viewModel); + var contentTypesToExport = viewModel.ContentTypes.Where(c => c.IsChecked).Select(c => c.ContentTypeName); + var exportFile = _importExportService.Export(contentTypesToExport, viewModel.Metadata, viewModel.Data, viewModel.SiteSettings); + Services.Notifier.Information(T("Your export file has been created at ", exportFile)); + + return RedirectToAction("Export"); + } + catch (Exception exception) { + Services.Notifier.Error(T("Export failed: {0}", exception.Message)); + return View(viewModel); + } + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ImportExport/Services/IImportExportService.cs b/src/Orchard.Web/Modules/Orchard.ImportExport/Services/IImportExportService.cs index 904c11752..2326dd60f 100644 --- a/src/Orchard.Web/Modules/Orchard.ImportExport/Services/IImportExportService.cs +++ b/src/Orchard.Web/Modules/Orchard.ImportExport/Services/IImportExportService.cs @@ -1,6 +1,9 @@ -namespace Orchard.ImportExport.Services { +using System.Collections.Generic; + +namespace Orchard.ImportExport.Services { public interface IImportExportService : IDependency { void Import(string recipeText); + string Export(IEnumerable contentTypes, bool exportMetadata, bool exportData, bool exportSettings); } } diff --git a/src/Orchard.Web/Modules/Orchard.ImportExport/Services/ImportExportService.cs b/src/Orchard.Web/Modules/Orchard.ImportExport/Services/ImportExportService.cs index 919520d6a..f2d26066a 100644 --- a/src/Orchard.Web/Modules/Orchard.ImportExport/Services/ImportExportService.cs +++ b/src/Orchard.Web/Modules/Orchard.ImportExport/Services/ImportExportService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using JetBrains.Annotations; using Orchard.Environment.Descriptor; using Orchard.Localization; @@ -31,6 +32,10 @@ namespace Orchard.ImportExport.Services { UpdateShell(); } + public string Export(IEnumerable contentTypes, bool exportMetadata, bool exportData, bool exportSettings) { + return String.Empty; + } + private void CheckRecipeSteps(Recipe recipe) { foreach (var step in recipe.RecipeSteps) { switch (step.Name) { diff --git a/src/Orchard.Web/Modules/Orchard.ImportExport/ViewModels/ExportViewModel.cs b/src/Orchard.Web/Modules/Orchard.ImportExport/ViewModels/ExportViewModel.cs index ba64fa457..dc2facd4b 100644 --- a/src/Orchard.Web/Modules/Orchard.ImportExport/ViewModels/ExportViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.ImportExport/ViewModels/ExportViewModel.cs @@ -1,4 +1,15 @@ -namespace Orchard.ImportExport.ViewModels { +using System.Collections.Generic; + +namespace Orchard.ImportExport.ViewModels { public class ExportViewModel { + public IList ContentTypes { get; set; } + public virtual bool Metadata { get; set; } + public virtual bool Data { get; set; } + public virtual bool SiteSettings { get; set; } } -} \ No newline at end of file + + public class ContentTypeEntry { + public string ContentTypeName { get; set; } + public bool IsChecked { get; set; } + } +} diff --git a/src/Orchard.Web/Modules/Orchard.ImportExport/Views/Admin/Export.cshtml b/src/Orchard.Web/Modules/Orchard.ImportExport/Views/Admin/Export.cshtml index cd1c11c3b..03f5fe8d5 100644 --- a/src/Orchard.Web/Modules/Orchard.ImportExport/Views/Admin/Export.cshtml +++ b/src/Orchard.Web/Modules/Orchard.ImportExport/Views/Admin/Export.cshtml @@ -2,3 +2,38 @@ @{ Layout.Title = T("Export").ToString(); } +@using(Html.BeginFormAntiForgeryPost()) { + Html.ValidationSummary(); +
+ @T("Choose the types to include in the export file:")
+
+ @T("Content Types") + @{var contentTypeIndex = 0;} + @foreach (var contentTypeEntry in Model.ContentTypes) { +
+ + + + contentTypeIndex = contentTypeIndex + 1; + } +
+


+ @T("Choose what to save for these types:")
+
+ @Html.EditorFor(m => m.Metadata) + +

@T("Metadata is the definition of your content types: what parts and fields they have, with what settings.")


+
+
+ @Html.EditorFor(m => m.Data) + +

@T("Data is the actual content of your site.")


+
+
+ @Html.EditorFor(m => m.SiteSettings) +
+

@T("Please verify that you are not exporting confidential information, such as passwords or application keys.")


+
+
+ +}