V12: Reset cache on migrating (#14133)

* Reset cache when migrating

* Manually delete cache file

* Rewrite migration to delete files

---------

Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
Nikolaj Geisle
2023-04-25 14:50:17 +02:00
committed by GitHub
parent 7e117d2496
commit 7e49493c8c
2 changed files with 34 additions and 5 deletions

View File

@@ -1,9 +1,5 @@
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_10_0_0;
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_10_2_0;
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_10_5_0;
using Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_12_0_0;
namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade;
@@ -76,6 +72,7 @@ public class UmbracoPlan : MigrationPlan
To<V_11_3_0.AddDomainSortOrder>("{BB3889ED-E2DE-49F2-8F71-5FD8616A2661}");
// To 12.0.0
To<UseNvarcharInsteadOfNText>("{888A0D5D-51E4-4C7E-AA0A-01306523C7FB}");
To<V_12_0_0.UseNvarcharInsteadOfNText>("{888A0D5D-51E4-4C7E-AA0A-01306523C7FB}");
To<V_12_0_0.ResetCache>("{539F2F83-FBA7-4C48-81A3-75081A56BB9D}");
}
}

View File

@@ -0,0 +1,32 @@
using Microsoft.Extensions.Hosting;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Extensions;
namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_12_0_0;
public class ResetCache : MigrationBase
{
private readonly IHostEnvironment _hostEnvironment;
public ResetCache(IMigrationContext context, IHostEnvironment hostEnvironment)
: base(context) => _hostEnvironment = hostEnvironment;
protected override void Migrate()
{
RebuildCache = true;
var distCacheFolderAbsolutePath = _hostEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempData + "/DistCache");
var nuCacheFolderAbsolutePath = _hostEnvironment.MapPathContentRoot(Constants.SystemDirectories.TempData + "/NuCache");
DeleteAllFilesInFolder(distCacheFolderAbsolutePath);
DeleteAllFilesInFolder(nuCacheFolderAbsolutePath);
}
private void DeleteAllFilesInFolder(string path)
{
var directoryInfo = new DirectoryInfo(path);
foreach (FileInfo file in directoryInfo.GetFiles())
{
file.Delete();
}
}
}