From 575784dd012dab7b6651dac81ccad9ab9ca68f35 Mon Sep 17 00:00:00 2001 From: SuhorukovAnton Date: Thu, 22 Dec 2022 18:17:21 +0300 Subject: [PATCH] fix migration --- .../MigrationCreator.cs | 13 ++++++++----- .../MigrationRunner.cs | 9 ++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/common/Tools/ASC.MigrationPersonalToDocspace/MigrationCreator.cs b/common/Tools/ASC.MigrationPersonalToDocspace/MigrationCreator.cs index fe4144826a..9bd7f0c12a 100644 --- a/common/Tools/ASC.MigrationPersonalToDocspace/MigrationCreator.cs +++ b/common/Tools/ASC.MigrationPersonalToDocspace/MigrationCreator.cs @@ -37,6 +37,7 @@ public class MigrationCreator private readonly StorageFactory _storageFactory; private readonly StorageFactoryConfig _storageFactoryConfig; private readonly ModuleProvider _moduleProvider; + private readonly CreatorDbContext _creatorDbContext; private List _modules; private string _pathToSave; @@ -61,7 +62,8 @@ public class MigrationCreator DbFactory dbFactory, StorageFactory storageFactory, StorageFactoryConfig storageFactoryConfig, - ModuleProvider moduleProvider) + ModuleProvider moduleProvider, + CreatorDbContext сreatorDbContext) { _hostEnvironment = hostEnvironment; _configuration = configuration; @@ -71,6 +73,7 @@ public class MigrationCreator _storageFactory = storageFactory; _storageFactoryConfig = storageFactoryConfig; _moduleProvider = moduleProvider; + _creatorDbContext = сreatorDbContext; } @@ -104,7 +107,7 @@ public class MigrationCreator { try { - var userDbContext = _dbFactory.CreateDbContext(); + var userDbContext = _creatorDbContext.CreateDbContext(); return userDbContext.Users.FirstOrDefault(q => q.Tenant == _tenant && q.Status == EmployeeStatus.Active && q.UserName == _userName).Id; } catch (Exception) @@ -199,7 +202,7 @@ public class MigrationCreator private List GetAliases() { - using var dbContext = _dbFactory.CreateDbContext(_toRegion); + using var dbContext = _creatorDbContext.CreateDbContext(_toRegion); var tenants = dbContext.Tenants.Select(t => t.Alias).ToList(); var forbidens = dbContext.TenantForbiden.Select(tf => tf.Address).ToList(); return tenants.Union(forbidens).ToList(); @@ -246,7 +249,7 @@ public class MigrationCreator { var files = (await GetFilesToProcess(id)).ToList(); - var backupsContext = _dbFactory.CreateDbContext(); + var backupsContext = _creatorDbContext.CreateDbContext(); var exclude = backupsContext.Backups.AsQueryable().Where(b => b.TenantId == _tenant && b.StorageType == 0 && b.StoragePath != null).ToList(); files = files.Where(f => !exclude.Any(e => f.Path.Replace('\\', '/').Contains($"/file_{e.StoragePath}/"))).ToList(); @@ -274,7 +277,7 @@ public class MigrationCreator .ToListAsync()); } - var filesDbContext = _dbFactory.CreateDbContext(); + var filesDbContext = _creatorDbContext.CreateDbContext(); files = files.Where(f => UserIsFileOwner(id, f, filesDbContext)).ToList(); return files.Distinct(); } diff --git a/common/Tools/ASC.MigrationPersonalToDocspace/MigrationRunner.cs b/common/Tools/ASC.MigrationPersonalToDocspace/MigrationRunner.cs index 9ea1fc4724..9c374d0f9e 100644 --- a/common/Tools/ASC.MigrationPersonalToDocspace/MigrationRunner.cs +++ b/common/Tools/ASC.MigrationPersonalToDocspace/MigrationRunner.cs @@ -33,7 +33,8 @@ public class MigrationRunner private readonly StorageFactory _storageFactory; private readonly StorageFactoryConfig _storageFactoryConfig; private readonly ModuleProvider _moduleProvider; - private readonly ILogger _logger; + private readonly ILogger _logger; + private readonly CreatorDbContext _creatorDbContext; private string _backupFile; private string _region; @@ -52,13 +53,15 @@ public class MigrationRunner StorageFactory storageFactory, StorageFactoryConfig storageFactoryConfig, ModuleProvider moduleProvider, - ILogger logger) + ILogger logger, + CreatorDbContext creatorDbContext) { _dbFactory = dbFactory; _storageFactory = storageFactory; _storageFactoryConfig = storageFactoryConfig; _moduleProvider = moduleProvider; _logger = logger; + _creatorDbContext = creatorDbContext; } public async Task Run(string backupFile, string region) @@ -132,7 +135,7 @@ public class MigrationRunner private void SetTenantActive(int tenantId) { - using var dbContext = _dbFactory.CreateDbContext(_region); + using var dbContext = _creatorDbContext.CreateDbContext(_region); var tenant = dbContext.Tenants.Single(t=> t.Id == tenantId); tenant.Status = TenantStatus.Active;