Incremental work on reset site action.

This commit is contained in:
Sipke Schoorstra
2015-07-15 19:32:53 +01:00
parent 665900214c
commit 22869b1960
6 changed files with 51 additions and 17 deletions

View File

@@ -6,6 +6,14 @@ Website: http://orchardproject.net
Version: 1.9.1 Version: 1.9.1
OrchardVersion: 1.9 OrchardVersion: 1.9
Description: Provides content item data import and export capability. Description: Provides content item data import and export capability.
FeatureDescription: Imports and exports content item data Features:
Orchard.ImportExport:
Name: Import Export
Description: Imports and exports content item data.
Category: Content Category: Content
Dependencies: Orchard.jQuery, Orchard.Recipes Dependencies: Orchard.jQuery, Orchard.Recipes
Orchard.ImportExport.ResetSite
Name: Reset Site Action
Description: Adds a Reset Site action to the Import screen.
Category: Hosting
Dependencies: Orchard.ImportExport, Orchard.MultiTenancy

View File

@@ -111,6 +111,10 @@
<Name>Orchard.Core</Name> <Name>Orchard.Core</Name>
<Private>false</Private> <Private>false</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Orchard.MultiTenancy\Orchard.MultiTenancy.csproj">
<Project>{72457126-e118-4171-a08f-9a709ee4b7fc}</Project>
<Name>Orchard.MultiTenancy</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Recipes\Orchard.Recipes.csproj"> <ProjectReference Include="..\Orchard.Recipes\Orchard.Recipes.csproj">
<Project>{fc1d74e8-7a4d-48f4-83de-95c6173780c4}</Project> <Project>{fc1d74e8-7a4d-48f4-83de-95c6173780c4}</Project>
<Name>Orchard.Recipes</Name> <Name>Orchard.Recipes</Name>

View File

@@ -1,9 +1,21 @@
using Orchard.ContentManagement; using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions;
using Orchard.ImportExport.Services; using Orchard.ImportExport.Services;
using Orchard.ImportExport.ViewModels; using Orchard.ImportExport.ViewModels;
using Orchard.MultiTenancy.Services;
namespace Orchard.ImportExport.Providers.ImportActions { namespace Orchard.ImportExport.Providers.ImportActions {
[OrchardFeature("Orchard.ImportExport.ResetSite")]
public class ResetSiteAction : ImportAction { public class ResetSiteAction : ImportAction {
private readonly ITenantService _tenantService;
private readonly ShellSettings _shellSettings;
public ResetSiteAction(ITenantService tenantService, ShellSettings shellSettings) {
_tenantService = tenantService;
_shellSettings = shellSettings;
}
public override string Name { get { return "ResetSite"; } } public override string Name { get { return "ResetSite"; } }
@@ -16,18 +28,24 @@ namespace Orchard.ImportExport.Providers.ImportActions {
} }
public bool ResetSite { get; set; } public bool ResetSite { get; set; }
public bool DropTables { get; set; }
public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater) { public override dynamic UpdateEditor(dynamic shapeFactory, IUpdateModel updater) {
var viewModel = new ResetSiteViewModel(); var viewModel = new ResetSiteViewModel();
if (updater != null) { if (updater != null) {
ResetSite = viewModel.ResetSite; ResetSite = viewModel.ResetSite;
DropTables = viewModel.DropTables;
} }
return shapeFactory.EditorTemplate(TemplateName: "ImportActions/ResetSite", Model: viewModel, Prefix: Prefix); return shapeFactory.EditorTemplate(TemplateName: "ImportActions/ResetSite", Model: viewModel, Prefix: Prefix);
} }
public override void Execute(ImportActionContext context) { public override void Execute(ImportActionContext context) {
// Reset site. _shellSettings.State = TenantState.Disabled;
_tenantService.ResetTenant(_shellSettings, DropTables);
_shellSettings.DataProvider = null;
_tenantService.UpdateTenant(_shellSettings);
context.ActionResult = new RedirectResult("~/");
} }
} }
} }

View File

@@ -1,11 +1,9 @@
using System; using System.IO;
using System.IO;
using System.Web; using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.Routing; using System.Web.Routing;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ImportExport.Services; using Orchard.ImportExport.Services;
using Orchard.UI.Notify;
namespace Orchard.ImportExport.Providers.ImportActions { namespace Orchard.ImportExport.Providers.ImportActions {
public class UploadRecipeAction : ImportAction { public class UploadRecipeAction : ImportAction {
@@ -29,19 +27,16 @@ namespace Orchard.ImportExport.Providers.ImportActions {
if (updater != null) { if (updater != null) {
var request = _orchardServices.WorkContext.HttpContext.Request; var request = _orchardServices.WorkContext.HttpContext.Request;
var file = request.Files["RecipeFile"]; File = request.Files["RecipeFile"];
if (String.IsNullOrEmpty(file.FileName)) {
updater.AddModelError("RecipeFile", T("Please choose a recipe file to import."));
_orchardServices.Notifier.Error(T("Please choose a recipe file to import."));
}
else
File = file;
} }
return shapeFactory.EditorTemplate(TemplateName: "ImportActions/UploadRecipe", Prefix: Prefix); return shapeFactory.EditorTemplate(TemplateName: "ImportActions/UploadRecipe", Prefix: Prefix);
} }
public override void Execute(ImportActionContext context) { public override void Execute(ImportActionContext context) {
if (File == null || File.ContentLength == 0)
return;
var executionId = _importExportService.Import(new StreamReader(File.InputStream).ReadToEnd()); var executionId = _importExportService.Import(new StreamReader(File.InputStream).ReadToEnd());
context.ActionResult = new RedirectToRouteResult(new RouteValueDictionary(new { action = "ImportResult", controller = "Admin", area = "Orchard.ImportExport", executionId = executionId })); context.ActionResult = new RedirectToRouteResult(new RouteValueDictionary(new { action = "ImportResult", controller = "Admin", area = "Orchard.ImportExport", executionId = executionId }));
} }

View File

@@ -1,5 +1,6 @@
namespace Orchard.ImportExport.ViewModels { namespace Orchard.ImportExport.ViewModels {
public class ResetSiteViewModel { public class ResetSiteViewModel {
public bool ResetSite { get; set; } public bool ResetSite { get; set; }
public bool DropTables { get; set; }
} }
} }

View File

@@ -1,8 +1,16 @@
@model Orchard.ImportExport.ViewModels.ResetSiteViewModel @model Orchard.ImportExport.ViewModels.ResetSiteViewModel
@{
Script.Require("ShapesBase");
}
<fieldset> <fieldset>
<div> <div>
@Html.CheckBoxFor(m => m.ResetSite) @Html.CheckBoxFor(m => m.ResetSite)
@Html.LabelFor(m => m.ResetSite, T("Reset Site").ToString(), new {@class = "forcheckbox"}) @Html.LabelFor(m => m.ResetSite, T("Reset Site").ToString(), new {@class = "forcheckbox"})
@Html.Hint(T("Check this option to completely clean your site before importing the uploaded recipe.")) @Html.Hint(T("Check this option to resets your site to its uninitialized state."))
</div>
<div data-controllerid="@Html.FieldIdFor(m => m.ResetSite)">
@Html.CheckBoxFor(m => m.DropTables)
@Html.LabelFor(m => m.DropTables, T("Drop Tables").ToString(), new { @class = "forcheckbox" })
@Html.Hint(T("Check this option to also drop all of the database tables of the current tenant."))
</div> </div>
</fieldset> </fieldset>