DocSpace-client/common/ASC.Data.Backup.Core/Tasks/DeletePortalTask.cs

105 lines
4.8 KiB
C#
Raw Normal View History

2020-05-20 15:14:44 +00:00
/*
*
* (c) Copyright Ascensio System Limited 2010-2020
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
*
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System.Linq;
2020-06-08 10:40:26 +00:00
2020-05-20 15:14:44 +00:00
using ASC.Common.Logging;
using ASC.Data.Backup.Exceptions;
using ASC.Data.Backup.Extensions;
using ASC.Data.Backup.Tasks.Data;
using ASC.Data.Backup.Tasks.Modules;
2021-08-31 09:40:28 +00:00
using ASC.Data.Storage;
2020-05-20 15:14:44 +00:00
using Microsoft.Extensions.Options;
namespace ASC.Data.Backup.Tasks
{
public class DeletePortalTask : PortalTaskBase
{
2020-06-10 12:35:10 +00:00
public DeletePortalTask(DbFactory dbFactory, IOptionsMonitor<ILog> options, int tenantId, string configPath, StorageFactory storageFactory, StorageFactoryConfig storageFactoryConfig, ModuleProvider moduleProvider)
2020-06-15 08:19:40 +00:00
: base(dbFactory, options, storageFactory, storageFactoryConfig, moduleProvider)
2020-05-20 15:14:44 +00:00
{
2020-06-08 10:40:26 +00:00
Init(tenantId, configPath);
2020-05-20 15:14:44 +00:00
}
public override void RunJob()
{
Logger.DebugFormat("begin delete {0}", TenantId);
2020-05-29 14:50:39 +00:00
var modulesToProcess = GetModulesToProcess().Reverse().ToList();
2020-05-20 15:14:44 +00:00
SetStepsCount(ProcessStorage ? modulesToProcess.Count + 1 : modulesToProcess.Count);
foreach (var module in modulesToProcess)
{
2020-06-10 12:35:10 +00:00
DoDeleteModule(module);
2020-05-20 15:14:44 +00:00
}
if (ProcessStorage)
{
DoDeleteStorage();
}
Logger.DebugFormat("end delete {0}", TenantId);
}
2020-06-10 12:35:10 +00:00
private void DoDeleteModule(IModuleSpecifics module)
2020-05-20 15:14:44 +00:00
{
Logger.DebugFormat("begin delete data for module ({0})", module.ModuleName);
2020-05-29 14:50:39 +00:00
var tablesCount = module.Tables.Count();
var tablesProcessed = 0;
2020-06-10 12:35:10 +00:00
using (var connection = DbFactory.OpenConnection())
2020-05-20 15:14:44 +00:00
{
foreach (var table in module.GetTablesOrdered().Reverse().Where(t => !IgnoredTables.Contains(t.Name)))
{
ActionInvoker.Try(state =>
{
var t = (TableInfo)state;
module.CreateDeleteCommand(connection.Fix(), TenantId, t).WithTimeout(120).ExecuteNonQuery();
}, table, 5, onFailure: error => { throw ThrowHelper.CantDeleteTable(table.Name, error); });
2022-01-21 13:46:30 +00:00
SetCurrentStepProgress((int)(++tablesProcessed * 100 / (double)tablesCount));
2020-05-20 15:14:44 +00:00
}
}
Logger.DebugFormat("end delete data for module ({0})", module.ModuleName);
}
private void DoDeleteStorage()
{
Logger.Debug("begin delete storage");
2020-06-08 10:40:26 +00:00
var storageModules = StorageFactoryConfig.GetModuleList(ConfigPath).Where(IsStorageModuleAllowed).ToList();
2020-05-29 14:50:39 +00:00
var modulesProcessed = 0;
foreach (var module in storageModules)
2020-05-20 15:14:44 +00:00
{
2020-06-08 10:40:26 +00:00
var storage = StorageFactory.GetStorage(ConfigPath, TenantId.ToString(), module);
2022-01-19 10:46:21 +00:00
var domains = StorageFactoryConfig.GetDomainList(ConfigPath, module);
2020-05-20 15:14:44 +00:00
foreach (var domain in domains)
{
2022-01-25 09:29:11 +00:00
ActionInvoker.Try(state => storage.DeleteFilesAsync((string)state, "\\", "*.*", true).Wait(), domain, 5,
2020-05-20 15:14:44 +00:00
onFailure: error => Logger.WarnFormat("Can't delete files for domain {0}: \r\n{1}", domain, error));
}
2022-01-25 09:29:11 +00:00
storage.DeleteFilesAsync("\\", "*.*", true).Wait();
2022-01-21 13:46:30 +00:00
SetCurrentStepProgress((int)(++modulesProcessed * 100 / (double)storageModules.Count));
2020-05-20 15:14:44 +00:00
}
Logger.Debug("end delete storage");
}
}
}