mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Hard deletes user themes, restores damaged bundled themes and fixes the web theme service DI lifetime
This commit is contained in:
1 parent
bf8faba24d
commit
45dc3f5706
7 files changed
+126
-10
No files matched your search
@@ -1,8 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -15,7 +16,8 @@ namespace Lumina.Application.Common.DataAccess.Repositories.Themes;
|
||||
public interface IThemeRepository : IRepository<ThemeEntity>,
|
||||
IGetAllRepositoryAction<ThemeEntity>,
|
||||
IInsertRepositoryAction<ThemeEntity>,
|
||||
IUpdateRepositoryAction<ThemeEntity>
|
||||
IUpdateRepositoryAction<ThemeEntity>,
|
||||
IDeleteByIdRepositoryAction<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a theme identified by its manifest <paramref name="themeId"/> from the storage medium.
|
||||
|
||||
@@ -95,6 +95,13 @@ public interface IThemeService
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Success>> RestoreBundledThemeAsync(string themeId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the stored pack files of a theme still exist.
|
||||
/// </summary>
|
||||
/// <param name="themeId">The manifest id of the theme.</param>
|
||||
/// <returns><see langword="true"/> when the theme pack files exist, <see langword="false"/> otherwise.</returns>
|
||||
bool HasThemePack(string themeId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the paths of the theme pack archives shipped with the application.
|
||||
/// </summary>
|
||||
|
||||
+16
-5
@@ -112,11 +112,22 @@ public class DeleteThemeCommandHandler : ICommandHandler<DeleteThemeCommand, Res
|
||||
await _unitOfWork.ThemeRepository.UpdateAsync(replacementTheme, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
theme.IsDeleted = true;
|
||||
theme.IsCurrent = null;
|
||||
theme.UpdatedOnUtc = DateTime.UtcNow;
|
||||
theme.UpdatedBy = userId;
|
||||
await _unitOfWork.ThemeRepository.UpdateAsync(theme, cancellationToken).ConfigureAwait(false);
|
||||
if (theme.InstallSource == ThemeInstallSource.Bundled)
|
||||
{
|
||||
// bundled themes are soft deleted, so they can be restored automatically later, as long as the user did not delete them
|
||||
theme.IsDeleted = true;
|
||||
theme.IsCurrent = null;
|
||||
theme.UpdatedOnUtc = DateTime.UtcNow;
|
||||
theme.UpdatedBy = userId;
|
||||
await _unitOfWork.ThemeRepository.UpdateAsync(theme, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// user themes are removed entirely, because their files are not shipped with the application and could never be restored
|
||||
Result<Deleted> deleteResult = await _unitOfWork.ThemeRepository.DeleteByIdAsync(theme.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteResult.IsFailure)
|
||||
return deleteResult.Errors;
|
||||
}
|
||||
|
||||
await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
|
||||
Reference in new issue
Block a user