mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-23 15:30:34 -04:00
Removed old manual migrations (config change, cover images) that are from many releases ago. (#1054)
This commit is contained in:
parent
1871de1cff
commit
f0d7f480ad
@ -14,7 +14,8 @@ namespace API.Data;
|
|||||||
public static class MigrateBookmarks
|
public static class MigrateBookmarks
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This will migrate existing bookmarks to bookmark folder based
|
/// This will migrate existing bookmarks to bookmark folder based.
|
||||||
|
/// If the bookmarks folder already exists, this will not run.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>Bookmark directory is configurable. This will always use the default bookmark directory.</remarks>
|
/// <remarks>Bookmark directory is configurable. This will always use the default bookmark directory.</remarks>
|
||||||
/// <param name="directoryService"></param>
|
/// <param name="directoryService"></param>
|
||||||
|
@ -5,11 +5,23 @@ using Microsoft.AspNetCore.Identity;
|
|||||||
|
|
||||||
namespace API.Data;
|
namespace API.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// New role introduced in v0.5.1. Adds the role to all users.
|
||||||
|
/// </summary>
|
||||||
public static class MigrateChangePasswordRoles
|
public static class MigrateChangePasswordRoles
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Will not run if any users have the ChangePassword role already
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="unitOfWork"></param>
|
||||||
|
/// <param name="userManager"></param>
|
||||||
public static async Task Migrate(IUnitOfWork unitOfWork, UserManager<AppUser> userManager)
|
public static async Task Migrate(IUnitOfWork unitOfWork, UserManager<AppUser> userManager)
|
||||||
{
|
{
|
||||||
foreach (var user in await unitOfWork.UserRepository.GetAllUsers())
|
var usersWithRole = await userManager.GetUsersInRoleAsync(PolicyConstants.ChangePasswordRole);
|
||||||
|
if (usersWithRole.Count != 0) return;
|
||||||
|
|
||||||
|
var allUsers = await unitOfWork.UserRepository.GetAllUsers();
|
||||||
|
foreach (var user in allUsers)
|
||||||
{
|
{
|
||||||
await userManager.RemoveFromRoleAsync(user, "ChangePassword");
|
await userManager.RemoveFromRoleAsync(user, "ChangePassword");
|
||||||
await userManager.AddToRoleAsync(user, PolicyConstants.ChangePasswordRole);
|
await userManager.AddToRoleAsync(user, PolicyConstants.ChangePasswordRole);
|
||||||
|
@ -36,7 +36,7 @@ namespace API
|
|||||||
|
|
||||||
|
|
||||||
var directoryService = new DirectoryService(null, new FileSystem());
|
var directoryService = new DirectoryService(null, new FileSystem());
|
||||||
MigrateConfigFiles.Migrate(isDocker, directoryService);
|
//MigrateConfigFiles.Migrate(isDocker, directoryService);
|
||||||
|
|
||||||
// Before anything, check if JWT has been generated properly or if user still has default
|
// Before anything, check if JWT has been generated properly or if user still has default
|
||||||
if (!Configuration.CheckIfJwtTokenSet() &&
|
if (!Configuration.CheckIfJwtTokenSet() &&
|
||||||
|
@ -144,7 +144,6 @@ namespace API
|
|||||||
{
|
{
|
||||||
// Apply all migrations on startup
|
// Apply all migrations on startup
|
||||||
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
|
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
|
||||||
var context = serviceProvider.GetRequiredService<DataContext>();
|
|
||||||
var userManager = serviceProvider.GetRequiredService<UserManager<AppUser>>();
|
var userManager = serviceProvider.GetRequiredService<UserManager<AppUser>>();
|
||||||
|
|
||||||
|
|
||||||
@ -152,30 +151,7 @@ namespace API
|
|||||||
logger, cacheService);
|
logger, cacheService);
|
||||||
|
|
||||||
// Only run this if we are upgrading
|
// Only run this if we are upgrading
|
||||||
var usersWithRole = await userManager.GetUsersInRoleAsync(PolicyConstants.ChangePasswordRole);
|
await MigrateChangePasswordRoles.Migrate(unitOfWork, userManager);
|
||||||
if (usersWithRole.Count == 0)
|
|
||||||
{
|
|
||||||
await MigrateChangePasswordRoles.Migrate(unitOfWork, userManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
var requiresCoverImageMigration = !Directory.Exists(directoryService.CoverImageDirectory);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// If this is a new install, tables wont exist yet
|
|
||||||
if (requiresCoverImageMigration)
|
|
||||||
{
|
|
||||||
MigrateCoverImages.ExtractToImages(context, directoryService, imageService);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
requiresCoverImageMigration = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (requiresCoverImageMigration)
|
|
||||||
{
|
|
||||||
await MigrateCoverImages.UpdateDatabaseWithImages(context, directoryService);
|
|
||||||
}
|
|
||||||
}).GetAwaiter()
|
}).GetAwaiter()
|
||||||
.GetResult();
|
.GetResult();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user