mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Added a /Force option to the tenant reset command.
This commit is contained in:
@@ -30,6 +30,8 @@ namespace Orchard.MultiTenancy.Commands {
|
|||||||
public string Modules { get; set; }
|
public string Modules { get; set; }
|
||||||
[OrchardSwitch]
|
[OrchardSwitch]
|
||||||
public bool DropDatabaseTables { get; set; }
|
public bool DropDatabaseTables { get; set; }
|
||||||
|
[OrchardSwitch]
|
||||||
|
public bool Force { get; set; }
|
||||||
|
|
||||||
[CommandHelp("tenant list\r\n\t" + "Display current tenants of the site.")]
|
[CommandHelp("tenant list\r\n\t" + "Display current tenants of the site.")]
|
||||||
[CommandName("tenant list")]
|
[CommandName("tenant list")]
|
||||||
@@ -178,9 +180,9 @@ namespace Orchard.MultiTenancy.Commands {
|
|||||||
_tenantService.UpdateTenant(tenant);
|
_tenantService.UpdateTenant(tenant);
|
||||||
}
|
}
|
||||||
|
|
||||||
[CommandHelp("tenant reset <tenantName> /DropDatabaseTables:<true|false>\r\n\t" + "Reset the tenant <tenantName> to its uninitialized, optionally dropping its tables from the database.")]
|
[CommandHelp("tenant reset <tenantName> /DropDatabaseTables:true|false /Force:true|false\r\n\t" + "Reset the tenant <tenantName> to its uninitialized, optionally dropping its tables from the database.")]
|
||||||
[CommandName("tenant reset")]
|
[CommandName("tenant reset")]
|
||||||
[OrchardSwitches("DropDatabaseTables")]
|
[OrchardSwitches("DropDatabaseTables,Force")]
|
||||||
public void Reset(string tenantName) {
|
public void Reset(string tenantName) {
|
||||||
Context.Output.WriteLine(T("Resetting tenant '{0}'...", tenantName));
|
Context.Output.WriteLine(T("Resetting tenant '{0}'...", tenantName));
|
||||||
|
|
||||||
@@ -190,7 +192,7 @@ namespace Orchard.MultiTenancy.Commands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_tenantService.ResetTenant(tenant, DropDatabaseTables);
|
_tenantService.ResetTenant(tenant, DropDatabaseTables, Force);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ namespace Orchard.MultiTenancy.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_tenantService.ResetTenant(tenant, viewModel.DropDatabaseTables);
|
_tenantService.ResetTenant(tenant, viewModel.DropDatabaseTables, force: false);
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ namespace Orchard.MultiTenancy.Services {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="settings">A ShellSettings object to identify the tenant to reset.</param>
|
/// <param name="settings">A ShellSettings object to identify the tenant to reset.</param>
|
||||||
/// <param name="dropDatabaseTables">A boolean indicated whether tenant database tables should be dropped also.</param>
|
/// <param name="dropDatabaseTables">A boolean indicated whether tenant database tables should be dropped also.</param>
|
||||||
void ResetTenant(ShellSettings settings, bool dropDatabaseTables);
|
/// <param name="force">A boolean indicating whether reset should be performed even if the tenant state is <c>TenantState.Running</c>.</param>
|
||||||
|
void ResetTenant(ShellSettings settings, bool dropDatabaseTables, bool force);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list of all known database tables in a tenant.
|
/// Returns a list of all known database tables in a tenant.
|
||||||
|
|||||||
@@ -43,9 +43,13 @@ namespace Orchard.MultiTenancy.Services {
|
|||||||
_shellSettingsManager.SaveSettings(settings);
|
_shellSettingsManager.SaveSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetTenant(ShellSettings settings, bool dropDatabaseTables) {
|
public void ResetTenant(ShellSettings settings, bool dropDatabaseTables, bool force) {
|
||||||
if (settings.State != TenantState.Disabled)
|
if (settings.State == TenantState.Uninitialized)
|
||||||
throw new InvalidOperationException(String.Format("Tenant state is '{0}'; must be '{1}' to perform reset action.", settings.State, TenantState.Disabled));
|
return;
|
||||||
|
if (settings.State == TenantState.Invalid)
|
||||||
|
throw new InvalidOperationException(String.Format("Tenant reset action cannot be performed when tenant state is '{0}'.", settings.State));
|
||||||
|
if (!force && settings.State != TenantState.Disabled)
|
||||||
|
throw new InvalidOperationException(String.Format("Tenant state is '{0}'; must be '{1}' to perform reset action. The 'force' option can be used to override this.", settings.State, TenantState.Disabled));
|
||||||
|
|
||||||
ExecuteOnTenantScope(settings, environment => {
|
ExecuteOnTenantScope(settings, environment => {
|
||||||
ExecuteResetEventHandlers(environment);
|
ExecuteResetEventHandlers(environment);
|
||||||
|
|||||||
Reference in New Issue
Block a user