case 4221
This commit is contained in:
@@ -233,12 +233,13 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Permanently erase all data and all attachments
|
/// Permanently erase most data and all attachments for seeding or migration purposes
|
||||||
///
|
///
|
||||||
/// Posting to this route causes AyaNova completely erase all data in it's database and erase all attachment files
|
/// This route is used by the v8-migration utility and by the AyaNova UI when seeding a trial database
|
||||||
/// returning the database to an empty state
|
|
||||||
///
|
///
|
||||||
/// The only items retained are the SuperUser account and the license key
|
/// Items retained are documented here with the exception of Tax codes:
|
||||||
|
/// https://ayanova.com/docs/adm-license/#erase-database
|
||||||
|
/// However not Tax Codes as documented because seeding or migration will create tax codes
|
||||||
///
|
///
|
||||||
/// (Only *the* SuperUser account can use this route)
|
/// (Only *the* SuperUser account can use this route)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -265,7 +266,51 @@ namespace AyaNova.Api.Controllers
|
|||||||
|
|
||||||
|
|
||||||
//empty the db
|
//empty the db
|
||||||
await AyaNova.Util.DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log, Guid.Empty, serverState.IsMigrateMode);
|
await AyaNova.Util.DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log);
|
||||||
|
|
||||||
|
//Log
|
||||||
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.Global, AyaEvent.EraseAllData), ct);
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Permanently erase most data and all attachments
|
||||||
|
///
|
||||||
|
/// This route is used by the by the AyaNova UI when a user selects to manually erase the database
|
||||||
|
/// or when they are evaluating and request another trial period with a database that already has a trial license in it
|
||||||
|
///
|
||||||
|
/// Items retained are documented here:
|
||||||
|
/// https://ayanova.com/docs/adm-license/#erase-database
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// (Only *the* SuperUser account can use this route)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="acceptCode">Must be "I understand"</param>
|
||||||
|
/// <returns>HTTP 204 No Content result code on success or fail code with explanation</returns>
|
||||||
|
[HttpPost("permanently-erase-all-data-keep-tax-codes")]
|
||||||
|
public async Task<IActionResult> RemoveAllDataKeepTaxCodes([FromBody] string acceptCode)
|
||||||
|
{
|
||||||
|
if (serverState.IsClosed)
|
||||||
|
{
|
||||||
|
//Exception for SuperUser account to handle licensing issues
|
||||||
|
if (UserIdFromContext.Id(HttpContext.Items) != 1)
|
||||||
|
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
|
||||||
|
}
|
||||||
|
if (!ModelState.IsValid)
|
||||||
|
return BadRequest(new ApiErrorResponse(ModelState));
|
||||||
|
|
||||||
|
long UserId = UserIdFromContext.Id(HttpContext.Items);
|
||||||
|
|
||||||
|
//SuperUser only and must have accept code
|
||||||
|
if (UserId != 1 || string.IsNullOrWhiteSpace(acceptCode) || acceptCode.ToLowerInvariant() != "i understand")
|
||||||
|
return StatusCode(403, new ApiNotAuthorizedResponse());
|
||||||
|
|
||||||
|
|
||||||
|
//empty the db
|
||||||
|
await AyaNova.Util.DbUtil.EmptyBizDataFromDatabaseForSeedingOrImportingAsync(log, true);
|
||||||
|
|
||||||
//Log
|
//Log
|
||||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.Global, AyaEvent.EraseAllData), ct);
|
await EventLogProcessor.LogEventToDatabaseAsync(new Event(1, 0, AyaType.Global, AyaEvent.EraseAllData), ct);
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ namespace AyaNova.Util
|
|||||||
// Erase all user entered data from the db
|
// Erase all user entered data from the db
|
||||||
// This is called by seeder for trial seeding purposes
|
// This is called by seeder for trial seeding purposes
|
||||||
// and by v8 migrate and by license controller when erasing db
|
// and by v8 migrate and by license controller when erasing db
|
||||||
internal static async Task EmptyBizDataFromDatabaseForSeedingOrImportingAsync(ILogger _log, Guid jobIdToKeep, bool isMigrate = false)
|
internal static async Task EmptyBizDataFromDatabaseForSeedingOrImportingAsync(ILogger _log, bool keepTaxCodes=false)
|
||||||
{
|
{
|
||||||
//case 4221
|
//case 4221
|
||||||
//erase plan to use truncate table instead of slower delete method
|
//erase plan to use truncate table instead of slower delete method
|
||||||
@@ -408,7 +408,7 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool forSeeding = jobIdToKeep != Guid.Empty;
|
|
||||||
|
|
||||||
_log.LogInformation("Erasing Database \"{0}\"", _dbName);
|
_log.LogInformation("Erasing Database \"{0}\"", _dbName);
|
||||||
AyaNova.Api.ControllerHelpers.ApiServerState apiServerState = (AyaNova.Api.ControllerHelpers.ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(AyaNova.Api.ControllerHelpers.ApiServerState));
|
AyaNova.Api.ControllerHelpers.ApiServerState apiServerState = (AyaNova.Api.ControllerHelpers.ApiServerState)ServiceProviderProvider.Provider.GetService(typeof(AyaNova.Api.ControllerHelpers.ApiServerState));
|
||||||
@@ -455,18 +455,18 @@ namespace AyaNova.Util
|
|||||||
cmd.CommandText = "update aworkorderitem set fromcsrid=null;";
|
cmd.CommandText = "update aworkorderitem set fromcsrid=null;";
|
||||||
await cmd.ExecuteNonQueryAsync();
|
await cmd.ExecuteNonQueryAsync();
|
||||||
|
|
||||||
if (jobIdToKeep != Guid.Empty)
|
// if (jobIdToKeep != Guid.Empty)
|
||||||
{
|
// {
|
||||||
//delete from aopsjoblog where jobid <> '8acec231-aab4-4fdc-b01e-8908378a0e7f';
|
// //delete from aopsjoblog where jobid <> '8acec231-aab4-4fdc-b01e-8908378a0e7f';
|
||||||
//delete from aopsjob where gid <> '8acec231-aab4-4fdc-b01e-8908378a0e7f';
|
// //delete from aopsjob where gid <> '8acec231-aab4-4fdc-b01e-8908378a0e7f';
|
||||||
cmd.CommandText = $"delete from aopsjoblog where jobid <> '{jobIdToKeep}'";
|
// cmd.CommandText = $"delete from aopsjoblog where jobid <> '{jobIdToKeep}'";
|
||||||
await cmd.ExecuteNonQueryAsync();
|
// await cmd.ExecuteNonQueryAsync();
|
||||||
cmd.CommandText = $"delete from aopsjob where gid <> '{jobIdToKeep}'";
|
// cmd.CommandText = $"delete from aopsjob where gid <> '{jobIdToKeep}'";
|
||||||
await cmd.ExecuteNonQueryAsync();
|
// await cmd.ExecuteNonQueryAsync();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
if (forSeeding || isMigrate)
|
if (!keepTaxCodes)
|
||||||
{
|
{
|
||||||
cmd.CommandText = "update aglobalbizsettings set taxpartpurchaseid=null,taxpartsaleid=null,taxratesaleid=null;";
|
cmd.CommandText = "update aglobalbizsettings set taxpartpurchaseid=null,taxpartsaleid=null,taxratesaleid=null;";
|
||||||
await cmd.ExecuteNonQueryAsync();
|
await cmd.ExecuteNonQueryAsync();
|
||||||
@@ -613,7 +613,7 @@ namespace AyaNova.Util
|
|||||||
|
|
||||||
await EraseTableAsync("aservicerate", conn);
|
await EraseTableAsync("aservicerate", conn);
|
||||||
await EraseTableAsync("atravelrate", conn);
|
await EraseTableAsync("atravelrate", conn);
|
||||||
if (forSeeding || isMigrate)
|
if (!keepTaxCodes)
|
||||||
await EraseTableAsync("ataxcode", conn);
|
await EraseTableAsync("ataxcode", conn);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user