Bugfixes (#2862)
Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
parent
5a7fd25548
commit
8f4e1fbb36
14 changed files with 92 additions and 1287 deletions
|
@ -82,6 +82,7 @@ public class AccountController : BaseApiController
|
|||
{
|
||||
var user = await _userManager.Users.SingleOrDefaultAsync(x => x.UserName == resetPasswordDto.UserName);
|
||||
if (user == null) return Ok(); // Don't report BadRequest as that would allow brute forcing to find accounts on system
|
||||
|
||||
_logger.LogInformation("{UserName} is changing {ResetUser}'s password", User.GetUsername(), resetPasswordDto.UserName);
|
||||
if (User.IsInRole(PolicyConstants.ReadOnlyRole))
|
||||
return BadRequest(await _localizationService.Translate(User.GetUserId(), "permission-denied"));
|
||||
|
|
51
API/Data/ManualMigrations/MigrateLowestSeriesFolderPath.cs
Normal file
51
API/Data/ManualMigrations/MigrateLowestSeriesFolderPath.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Entities;
|
||||
using API.Services.Tasks.Scanner.Parser;
|
||||
using Kavita.Common.EnvironmentInfo;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace API.Data.ManualMigrations;
|
||||
|
||||
/// <summary>
|
||||
/// v0.8.0 released with a bug around LowestSeriesPath. This resets it for all users.
|
||||
/// </summary>
|
||||
public static class MigrateLowestSeriesFolderPath
|
||||
{
|
||||
public static async Task Migrate(DataContext dataContext, IUnitOfWork unitOfWork, ILogger<Program> logger)
|
||||
{
|
||||
if (await dataContext.ManualMigrationHistory.AnyAsync(m => m.Name == "MigrateLowestSeriesFolderPath"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
logger.LogCritical(
|
||||
"Running MigrateLowestSeriesFolderPath migration - Please be patient, this may take some time. This is not an error");
|
||||
|
||||
var series = await dataContext.Series.Where(s => !string.IsNullOrEmpty(s.LowestFolderPath)).ToListAsync();
|
||||
foreach (var s in series)
|
||||
{
|
||||
s.LowestFolderPath = string.Empty;
|
||||
unitOfWork.SeriesRepository.Update(s);
|
||||
}
|
||||
|
||||
// Save changes after processing all series
|
||||
if (dataContext.ChangeTracker.HasChanges())
|
||||
{
|
||||
await dataContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
dataContext.ManualMigrationHistory.Add(new ManualMigrationHistory()
|
||||
{
|
||||
Name = "MigrateLowestSeriesFolderPath",
|
||||
ProductVersion = BuildInfo.Version.ToString(),
|
||||
RanAt = DateTime.UtcNow
|
||||
});
|
||||
|
||||
await dataContext.SaveChangesAsync();
|
||||
logger.LogCritical(
|
||||
"Running MigrateLowestSeriesFolderPath migration - Completed. This is not an error");
|
||||
}
|
||||
}
|
|
@ -596,14 +596,12 @@ public class DirectoryService : IDirectoryService
|
|||
/// <returns></returns>
|
||||
public string? FindLowestDirectoriesFromFiles(IEnumerable<string> libraryFolders, IList<string> filePaths)
|
||||
{
|
||||
|
||||
|
||||
var stopLookingForDirectories = false;
|
||||
var dirs = new Dictionary<string, string>();
|
||||
foreach (var folder in libraryFolders.Select(Tasks.Scanner.Parser.Parser.NormalizePath))
|
||||
var normalizedFilePaths = filePaths.Select(Parser.NormalizePath).ToList();
|
||||
|
||||
foreach (var folder in libraryFolders.Select(Parser.NormalizePath))
|
||||
{
|
||||
if (stopLookingForDirectories) break;
|
||||
foreach (var file in filePaths.Select(Tasks.Scanner.Parser.Parser.NormalizePath))
|
||||
foreach (var file in normalizedFilePaths)
|
||||
{
|
||||
if (!file.Contains(folder)) continue;
|
||||
|
||||
|
@ -619,8 +617,16 @@ public class DirectoryService : IDirectoryService
|
|||
if (dirs.Keys.Count == 1) return dirs.Keys.First();
|
||||
if (dirs.Keys.Count > 1)
|
||||
{
|
||||
return dirs.Keys.Last();
|
||||
// For each key, validate that each file exists in the key path
|
||||
foreach (var folder in dirs.Keys)
|
||||
{
|
||||
if (normalizedFilePaths.TrueForAll(filePath => filePath.Contains(Parser.NormalizePath(folder))))
|
||||
{
|
||||
return folder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -265,7 +265,7 @@ public class TaskScheduler : ITaskScheduler
|
|||
public void ScheduleUpdaterTasks()
|
||||
{
|
||||
_logger.LogInformation("Scheduling Auto-Update tasks");
|
||||
RecurringJob.AddOrUpdate(CheckForUpdateId, () => CheckForUpdate(), $"0 */{Rnd.Next(1, 2)} * * *", RecurringJobOptions);
|
||||
RecurringJob.AddOrUpdate(CheckForUpdateId, () => CheckForUpdate(), $"0 */{Rnd.Next(4, 6)} * * *", RecurringJobOptions);
|
||||
BackgroundJob.Enqueue(() => CheckForUpdate());
|
||||
}
|
||||
|
||||
|
|
|
@ -463,7 +463,7 @@ public class ParseScannedFiles
|
|||
chapter.IssueOrder = counter;
|
||||
counter++;
|
||||
}
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
@ -479,7 +479,7 @@ public class ParseScannedFiles
|
|||
chapter.IssueOrder = counter;
|
||||
counter++;
|
||||
}
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
chapters = infos
|
||||
|
|
|
@ -263,6 +263,9 @@ public class Startup
|
|||
await MigrateMangaFilePath.Migrate(dataContext, logger);
|
||||
await MigrateCollectionTagToUserCollections.Migrate(dataContext, unitOfWork, logger);
|
||||
|
||||
// v0.8.1
|
||||
await MigrateLowestSeriesFolderPath.Migrate(dataContext, unitOfWork, logger);
|
||||
|
||||
// Update the version in the DB after all migrations are run
|
||||
var installVersion = await unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.InstallVersion);
|
||||
installVersion.Value = BuildInfo.Version.ToString();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue