DocSpace-buildtools/common/ASC.Data.Backup.Core/Tasks/Modules/TenantsModuleSpecifics.cs

93 lines
4.0 KiB
C#
Raw Normal View History

namespace ASC.Data.Backup.Tasks.Modules;
public class TenantsModuleSpecifics : ModuleSpecificsBase
2020-05-20 15:14:44 +00:00
{
public override string ConnectionStringName => "core";
public override ModuleName ModuleName => ModuleName.Tenants;
public override IEnumerable<TableInfo> Tables => _tables;
public override IEnumerable<RelationInfo> TableRelations => _tableRelations;
2020-05-20 15:14:44 +00:00
private readonly CoreSettings _coreSettings;
2020-08-27 14:01:37 +00:00
private readonly TableInfo[] _tables = new[]
{
2022-02-09 18:33:50 +00:00
new TableInfo("tenants_quota", "tenant"),
new TableInfo("tenants_tariff", "tenant", "id"),
new TableInfo("tenants_tenants", "id", "id")
2020-05-20 15:14:44 +00:00
{
2022-02-09 18:33:50 +00:00
DateColumns = new Dictionary<string, bool> {{"creationdatetime", false}, {"statuschanged", false}, {"version_changed", false}}
},
new TableInfo("tenants_quotarow", "tenant") {InsertMethod = InsertMethod.Replace},
new TableInfo("tenants_partners", "tenant_id"),
new TableInfo("core_user", "tenant", "id", IdType.Guid)
2020-05-20 15:14:44 +00:00
{
2022-02-09 18:33:50 +00:00
DateColumns = new Dictionary<string, bool> {{"workfromdate", false}, {"terminateddate", false}, {"last_modified", false}}
},
new TableInfo("core_group", "tenant", "id", IdType.Guid),
new TableInfo("tenants_iprestrictions", "tenant", "id", IdType.Autoincrement)
};
2020-05-20 15:14:44 +00:00
private readonly RelationInfo[] _tableRelations = new[]
{
2022-02-09 18:33:50 +00:00
new RelationInfo("tenants_tenants", "id", "tenants_quota", "tenant"),
new RelationInfo("tenants_tenants", "id", "tenants_tariff", "tenant"),
new RelationInfo("tenants_tenants", "id", "tenants_tariff", "tariff", x => Convert.ToInt32(x["tariff"]) > 0),
new RelationInfo("tenants_tenants", "id", "tenants_partners", "tenant_id"),
new RelationInfo("core_user", "id", "tenants_tenants", "owner_id", null, null, RelationImportance.Low)
};
2020-05-20 15:14:44 +00:00
public TenantsModuleSpecifics(CoreSettings coreSettings, Helpers helpers)
: base(helpers)
{
_coreSettings = coreSettings;
}
protected override bool TryPrepareRow(bool dump, DbConnection connection, ColumnMapper columnMapper, TableInfo table, DataRowInfo row, out Dictionary<string, object> preparedRow)
{
if (table.Name == "tenants_tenants" && string.IsNullOrEmpty(Convert.ToString(row["payment_id"])))
2020-05-20 15:14:44 +00:00
{
var oldTenantID = Convert.ToInt32(row["id"]);
columnMapper.SetMapping("tenants_tenants", "payment_id", row["payment_id"], _coreSettings.GetKey(oldTenantID));
2020-05-20 15:14:44 +00:00
}
return base.TryPrepareRow(dump, connection, columnMapper, table, row, out preparedRow);
}
protected override bool TryPrepareValue(DbConnection connection, ColumnMapper columnMapper, TableInfo table, string columnName, ref object value)
{
//we insert tenant as suspended so it can't be accessed before restore operation is finished
if (table.Name.Equals("tenants_tenants", StringComparison.InvariantCultureIgnoreCase) &&
columnName.Equals("status", StringComparison.InvariantCultureIgnoreCase))
2020-05-20 15:14:44 +00:00
{
value = (int)TenantStatus.Restoring;
2022-02-09 18:33:50 +00:00
return true;
2020-05-20 15:14:44 +00:00
}
if (table.Name.Equals("tenants_tenants", StringComparison.InvariantCultureIgnoreCase) &&
columnName.Equals("last_modified", StringComparison.InvariantCultureIgnoreCase))
2020-05-20 15:14:44 +00:00
{
value = DateTime.UtcNow;
2022-02-09 18:33:50 +00:00
return true;
}
2022-02-09 18:33:50 +00:00
if (table.Name.Equals("tenants_quotarow", StringComparison.InvariantCultureIgnoreCase) &&
columnName.Equals("last_modified", StringComparison.InvariantCultureIgnoreCase))
{
value = DateTime.UtcNow;
2020-05-20 15:14:44 +00:00
return true;
}
2022-02-09 18:33:50 +00:00
if ((table.Name == "core_user" || table.Name == "core_group") && columnName == "last_modified")
{
value = DateTime.UtcNow.AddMinutes(2);
2020-05-20 15:14:44 +00:00
return true;
2020-05-20 15:14:44 +00:00
}
return base.TryPrepareValue(connection, columnMapper, table, columnName, ref value);
2020-05-20 15:14:44 +00:00
}
}