|
1 | 1 | using Microsoft.Extensions.DependencyInjection; |
| 2 | +using Microsoft.Extensions.Logging; |
2 | 3 | using Microsoft.Extensions.Options; |
3 | 4 | using Umbraco.Cms.Core; |
| 5 | +using Umbraco.Cms.Core.Cache; |
4 | 6 | using Umbraco.Cms.Core.Configuration; |
5 | 7 | using Umbraco.Cms.Core.Configuration.Models; |
6 | 8 | using Umbraco.Cms.Core.DependencyInjection; |
@@ -28,21 +30,47 @@ public class UnattendedUpgrader : INotificationAsyncHandler<RuntimeUnattendedUpg |
28 | 30 | private readonly IRuntimeState _runtimeState; |
29 | 31 | private readonly IUmbracoVersion _umbracoVersion; |
30 | 32 | private readonly UnattendedSettings _unattendedSettings; |
| 33 | + private readonly DistributedCache _distributedCache; |
| 34 | + private readonly ILogger<UnattendedUpgrader> _logger; |
31 | 35 |
|
| 36 | + [Obsolete("Please use the constructor taking all parameters. Scheduled for removal in Umbraco 19.")] |
32 | 37 | public UnattendedUpgrader( |
33 | 38 | IProfilingLogger profilingLogger, |
34 | 39 | IUmbracoVersion umbracoVersion, |
35 | 40 | DatabaseBuilder databaseBuilder, |
36 | 41 | IRuntimeState runtimeState, |
37 | 42 | PackageMigrationRunner packageMigrationRunner, |
38 | 43 | IOptions<UnattendedSettings> unattendedSettings) |
| 44 | + : this( |
| 45 | + profilingLogger, |
| 46 | + umbracoVersion, |
| 47 | + databaseBuilder, |
| 48 | + runtimeState, |
| 49 | + packageMigrationRunner, |
| 50 | + unattendedSettings, |
| 51 | + StaticServiceProvider.Instance.GetRequiredService<DistributedCache>(), |
| 52 | + StaticServiceProvider.Instance.GetRequiredService<ILogger<UnattendedUpgrader>>()) |
39 | 53 | { |
40 | | - _profilingLogger = profilingLogger ?? throw new ArgumentNullException(nameof(profilingLogger)); |
41 | | - _umbracoVersion = umbracoVersion ?? throw new ArgumentNullException(nameof(umbracoVersion)); |
42 | | - _databaseBuilder = databaseBuilder ?? throw new ArgumentNullException(nameof(databaseBuilder)); |
43 | | - _runtimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState)); |
| 54 | + } |
| 55 | + |
| 56 | + public UnattendedUpgrader( |
| 57 | + IProfilingLogger profilingLogger, |
| 58 | + IUmbracoVersion umbracoVersion, |
| 59 | + DatabaseBuilder databaseBuilder, |
| 60 | + IRuntimeState runtimeState, |
| 61 | + PackageMigrationRunner packageMigrationRunner, |
| 62 | + IOptions<UnattendedSettings> unattendedSettings, |
| 63 | + DistributedCache distributedCache, |
| 64 | + ILogger<UnattendedUpgrader> logger) |
| 65 | + { |
| 66 | + _profilingLogger = profilingLogger; |
| 67 | + _umbracoVersion = umbracoVersion; |
| 68 | + _databaseBuilder = databaseBuilder; |
| 69 | + _runtimeState = runtimeState; |
44 | 70 | _packageMigrationRunner = packageMigrationRunner; |
45 | 71 | _unattendedSettings = unattendedSettings.Value; |
| 72 | + _distributedCache = distributedCache; |
| 73 | + _logger = logger; |
46 | 74 | } |
47 | 75 |
|
48 | 76 | public async Task HandleAsync(RuntimeUnattendedUpgradeNotification notification, CancellationToken cancellationToken) |
@@ -109,8 +137,13 @@ private async Task RunPackageMigrationsAsync(RuntimeUnattendedUpgradeNotificatio |
109 | 137 | try |
110 | 138 | { |
111 | 139 | await _packageMigrationRunner.RunPackagePlansAsync(pendingMigrations); |
112 | | - notification.UnattendedUpgradeResult = RuntimeUnattendedUpgradeNotification.UpgradeResult |
113 | | - .PackageMigrationComplete; |
| 140 | + notification.UnattendedUpgradeResult = RuntimeUnattendedUpgradeNotification.UpgradeResult.PackageMigrationComplete; |
| 141 | + |
| 142 | + // Migration plans may have changed published content, so refresh the distributed cache to ensure consistency on first request. |
| 143 | + _distributedCache.RefreshAllPublishedSnapshot(); |
| 144 | + _logger.LogInformation( |
| 145 | + "Migration plans run: {Plans}. Triggered refresh of distributed published content cache.", |
| 146 | + string.Join(", ", pendingMigrations)); |
114 | 147 | } |
115 | 148 | catch (Exception ex) |
116 | 149 | { |
|
0 commit comments