Files
Umbraco-CMS/src/Umbraco.Infrastructure/Install/InstallSteps/DatabaseUpgradeStep.cs

91 lines
3.6 KiB
C#
Raw Normal View History

using Microsoft.Extensions.Logging;
2021-02-12 11:11:44 +01:00
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Install;
using Umbraco.Cms.Core.Install.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Migrations.Install;
using Umbraco.Cms.Infrastructure.Migrations.PostMigrations;
using Umbraco.Cms.Infrastructure.Migrations.Upgrade;
using Umbraco.Extensions;
2021-02-12 11:11:44 +01:00
namespace Umbraco.Cms.Infrastructure.Install.InstallSteps
{
merge release/10.0.0 into v10/dev commit 9ff06eec6e82bd90a29a37dd34ecba931859f5f5 Author: Ronald Barendse <ronald@barend.se> Date: Wed May 25 11:16:39 2022 +0200 v10: Instantly reload ConnectionStrings after saving configuration (#12475) * Do not replace DataDirectory placeholder when setting connection string * Ensure ConnectionStrings options are updated when configuration is reloaded * Use CurrentValue to get default Umbraco connection string commit fcee6dc06ad829519202a29c2b549c7c65c47785 Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 10:08:43 2022 +0100 Fix legacy scope provider no longer implementing ICoreScopeProvider (#12480) commit 88f3628d0a330374673d187da8843b56a2ee8f0b Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 09:49:33 2022 +0100 Fix options monitor setup for connectionstrings (#12472) commit 4eeb03e7fb8c05be615156410efba3ed30e0e9c1 Author: Johan Runsten <jrunestone@users.noreply.github.com> Date: Wed May 25 10:13:25 2022 +0200 Fixed null check typo in CacheInstructionService. Fixes #12473. (#12474) * Fixed null check typo. Fixes #12473. * Removed unneccessary null forgiving operator Co-authored-by: Johan Runsten <johan.runsten@toxic.se> commit d810d66e9a0dbbfd19432b4cab610b728a6944e0 Author: Asbjørn Riis-Knudsen <ar@jf-data.com> Date: Tue May 24 17:41:10 2022 +0200 Fix #12454 by having Coalesce handle null values (#12456) * Fix #12454 by having Coalesce handle null values * Allow null values in Html.Coalesce #12454 commit 963d4c5051f280770303c2e312e8ee9cb67d18cc Author: Paul Johnson <pmj@umbraco.com> Date: Tue May 24 13:55:39 2022 +0100 Ensure unique buildnumber for devops UI
2022-05-25 10:48:45 +01:00
[InstallSetupStep(InstallationType.Upgrade | InstallationType.NewInstall, "DatabaseUpgrade", 12, "")]
public class DatabaseUpgradeStep : InstallSetupStep<object>
{
2016-11-29 10:31:25 +01:00
private readonly DatabaseBuilder _databaseBuilder;
private readonly IRuntimeState _runtime;
private readonly ILogger<DatabaseUpgradeStep> _logger;
private readonly IUmbracoVersion _umbracoVersion;
private readonly IOptionsMonitor<ConnectionStrings> _connectionStrings;
public DatabaseUpgradeStep(
DatabaseBuilder databaseBuilder,
IRuntimeState runtime,
ILogger<DatabaseUpgradeStep> logger,
IUmbracoVersion umbracoVersion,
IOptionsMonitor<ConnectionStrings> connectionStrings)
{
2016-11-29 10:31:25 +01:00
_databaseBuilder = databaseBuilder;
_runtime = runtime;
_logger = logger;
_umbracoVersion = umbracoVersion;
_connectionStrings = connectionStrings;
}
public override Task<InstallSetupResult?> ExecuteAsync(object model)
{
2017-07-20 11:21:28 +02:00
var installSteps = InstallStatusTracker.GetStatus().ToArray();
var previousStep = installSteps.Single(x => x.Name == "DatabaseInstall");
var upgrade = previousStep.AdditionalData.ContainsKey("upgrade");
if (upgrade)
{
2020-09-15 08:45:40 +02:00
_logger.LogInformation("Running 'Upgrade' service");
var plan = new UmbracoPlan(_umbracoVersion);
2019-02-13 09:53:17 +01:00
plan.AddPostMigration<ClearCsrfCookies>(); // needed when running installer (back-office)
var result = _databaseBuilder.UpgradeSchemaAndData(plan);
2022-02-27 21:20:50 +01:00
if (result?.Success == false)
{
throw new InstallException("The database failed to upgrade. ERROR: " + result.Message);
}
}
return Task.FromResult((InstallSetupResult?)null);
}
public override bool RequiresExecution(object model)
{
merge release/10.0.0 into v10/dev commit 9ff06eec6e82bd90a29a37dd34ecba931859f5f5 Author: Ronald Barendse <ronald@barend.se> Date: Wed May 25 11:16:39 2022 +0200 v10: Instantly reload ConnectionStrings after saving configuration (#12475) * Do not replace DataDirectory placeholder when setting connection string * Ensure ConnectionStrings options are updated when configuration is reloaded * Use CurrentValue to get default Umbraco connection string commit fcee6dc06ad829519202a29c2b549c7c65c47785 Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 10:08:43 2022 +0100 Fix legacy scope provider no longer implementing ICoreScopeProvider (#12480) commit 88f3628d0a330374673d187da8843b56a2ee8f0b Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 09:49:33 2022 +0100 Fix options monitor setup for connectionstrings (#12472) commit 4eeb03e7fb8c05be615156410efba3ed30e0e9c1 Author: Johan Runsten <jrunestone@users.noreply.github.com> Date: Wed May 25 10:13:25 2022 +0200 Fixed null check typo in CacheInstructionService. Fixes #12473. (#12474) * Fixed null check typo. Fixes #12473. * Removed unneccessary null forgiving operator Co-authored-by: Johan Runsten <johan.runsten@toxic.se> commit d810d66e9a0dbbfd19432b4cab610b728a6944e0 Author: Asbjørn Riis-Knudsen <ar@jf-data.com> Date: Tue May 24 17:41:10 2022 +0200 Fix #12454 by having Coalesce handle null values (#12456) * Fix #12454 by having Coalesce handle null values * Allow null values in Html.Coalesce #12454 commit 963d4c5051f280770303c2e312e8ee9cb67d18cc Author: Paul Johnson <pmj@umbraco.com> Date: Tue May 24 13:55:39 2022 +0100 Ensure unique buildnumber for devops UI
2022-05-25 10:48:45 +01:00
// If it's properly configured (i.e. the versions match) then no upgrade necessary
if (_runtime.Level == RuntimeLevel.Run)
merge release/10.0.0 into v10/dev commit 9ff06eec6e82bd90a29a37dd34ecba931859f5f5 Author: Ronald Barendse <ronald@barend.se> Date: Wed May 25 11:16:39 2022 +0200 v10: Instantly reload ConnectionStrings after saving configuration (#12475) * Do not replace DataDirectory placeholder when setting connection string * Ensure ConnectionStrings options are updated when configuration is reloaded * Use CurrentValue to get default Umbraco connection string commit fcee6dc06ad829519202a29c2b549c7c65c47785 Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 10:08:43 2022 +0100 Fix legacy scope provider no longer implementing ICoreScopeProvider (#12480) commit 88f3628d0a330374673d187da8843b56a2ee8f0b Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 09:49:33 2022 +0100 Fix options monitor setup for connectionstrings (#12472) commit 4eeb03e7fb8c05be615156410efba3ed30e0e9c1 Author: Johan Runsten <jrunestone@users.noreply.github.com> Date: Wed May 25 10:13:25 2022 +0200 Fixed null check typo in CacheInstructionService. Fixes #12473. (#12474) * Fixed null check typo. Fixes #12473. * Removed unneccessary null forgiving operator Co-authored-by: Johan Runsten <johan.runsten@toxic.se> commit d810d66e9a0dbbfd19432b4cab610b728a6944e0 Author: Asbjørn Riis-Knudsen <ar@jf-data.com> Date: Tue May 24 17:41:10 2022 +0200 Fix #12454 by having Coalesce handle null values (#12456) * Fix #12454 by having Coalesce handle null values * Allow null values in Html.Coalesce #12454 commit 963d4c5051f280770303c2e312e8ee9cb67d18cc Author: Paul Johnson <pmj@umbraco.com> Date: Tue May 24 13:55:39 2022 +0100 Ensure unique buildnumber for devops UI
2022-05-25 10:48:45 +01:00
{
return false;
merge release/10.0.0 into v10/dev commit 9ff06eec6e82bd90a29a37dd34ecba931859f5f5 Author: Ronald Barendse <ronald@barend.se> Date: Wed May 25 11:16:39 2022 +0200 v10: Instantly reload ConnectionStrings after saving configuration (#12475) * Do not replace DataDirectory placeholder when setting connection string * Ensure ConnectionStrings options are updated when configuration is reloaded * Use CurrentValue to get default Umbraco connection string commit fcee6dc06ad829519202a29c2b549c7c65c47785 Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 10:08:43 2022 +0100 Fix legacy scope provider no longer implementing ICoreScopeProvider (#12480) commit 88f3628d0a330374673d187da8843b56a2ee8f0b Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 09:49:33 2022 +0100 Fix options monitor setup for connectionstrings (#12472) commit 4eeb03e7fb8c05be615156410efba3ed30e0e9c1 Author: Johan Runsten <jrunestone@users.noreply.github.com> Date: Wed May 25 10:13:25 2022 +0200 Fixed null check typo in CacheInstructionService. Fixes #12473. (#12474) * Fixed null check typo. Fixes #12473. * Removed unneccessary null forgiving operator Co-authored-by: Johan Runsten <johan.runsten@toxic.se> commit d810d66e9a0dbbfd19432b4cab610b728a6944e0 Author: Asbjørn Riis-Knudsen <ar@jf-data.com> Date: Tue May 24 17:41:10 2022 +0200 Fix #12454 by having Coalesce handle null values (#12456) * Fix #12454 by having Coalesce handle null values * Allow null values in Html.Coalesce #12454 commit 963d4c5051f280770303c2e312e8ee9cb67d18cc Author: Paul Johnson <pmj@umbraco.com> Date: Tue May 24 13:55:39 2022 +0100 Ensure unique buildnumber for devops UI
2022-05-25 10:48:45 +01:00
}
merge release/10.0.0 into v10/dev commit 9ff06eec6e82bd90a29a37dd34ecba931859f5f5 Author: Ronald Barendse <ronald@barend.se> Date: Wed May 25 11:16:39 2022 +0200 v10: Instantly reload ConnectionStrings after saving configuration (#12475) * Do not replace DataDirectory placeholder when setting connection string * Ensure ConnectionStrings options are updated when configuration is reloaded * Use CurrentValue to get default Umbraco connection string commit fcee6dc06ad829519202a29c2b549c7c65c47785 Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 10:08:43 2022 +0100 Fix legacy scope provider no longer implementing ICoreScopeProvider (#12480) commit 88f3628d0a330374673d187da8843b56a2ee8f0b Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 09:49:33 2022 +0100 Fix options monitor setup for connectionstrings (#12472) commit 4eeb03e7fb8c05be615156410efba3ed30e0e9c1 Author: Johan Runsten <jrunestone@users.noreply.github.com> Date: Wed May 25 10:13:25 2022 +0200 Fixed null check typo in CacheInstructionService. Fixes #12473. (#12474) * Fixed null check typo. Fixes #12473. * Removed unneccessary null forgiving operator Co-authored-by: Johan Runsten <johan.runsten@toxic.se> commit d810d66e9a0dbbfd19432b4cab610b728a6944e0 Author: Asbjørn Riis-Knudsen <ar@jf-data.com> Date: Tue May 24 17:41:10 2022 +0200 Fix #12454 by having Coalesce handle null values (#12456) * Fix #12454 by having Coalesce handle null values * Allow null values in Html.Coalesce #12454 commit 963d4c5051f280770303c2e312e8ee9cb67d18cc Author: Paul Johnson <pmj@umbraco.com> Date: Tue May 24 13:55:39 2022 +0100 Ensure unique buildnumber for devops UI
2022-05-25 10:48:45 +01:00
// This step relies on the previous one completed - because it has stored some information we need
var installSteps = InstallStatusTracker.GetStatus().ToArray();
if (installSteps.Any(x => x.Name == "DatabaseInstall" && x.AdditionalData.ContainsKey("upgrade")) == false)
{
return false;
}
2017-07-20 11:21:28 +02:00
merge release/10.0.0 into v10/dev commit 9ff06eec6e82bd90a29a37dd34ecba931859f5f5 Author: Ronald Barendse <ronald@barend.se> Date: Wed May 25 11:16:39 2022 +0200 v10: Instantly reload ConnectionStrings after saving configuration (#12475) * Do not replace DataDirectory placeholder when setting connection string * Ensure ConnectionStrings options are updated when configuration is reloaded * Use CurrentValue to get default Umbraco connection string commit fcee6dc06ad829519202a29c2b549c7c65c47785 Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 10:08:43 2022 +0100 Fix legacy scope provider no longer implementing ICoreScopeProvider (#12480) commit 88f3628d0a330374673d187da8843b56a2ee8f0b Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 09:49:33 2022 +0100 Fix options monitor setup for connectionstrings (#12472) commit 4eeb03e7fb8c05be615156410efba3ed30e0e9c1 Author: Johan Runsten <jrunestone@users.noreply.github.com> Date: Wed May 25 10:13:25 2022 +0200 Fixed null check typo in CacheInstructionService. Fixes #12473. (#12474) * Fixed null check typo. Fixes #12473. * Removed unneccessary null forgiving operator Co-authored-by: Johan Runsten <johan.runsten@toxic.se> commit d810d66e9a0dbbfd19432b4cab610b728a6944e0 Author: Asbjørn Riis-Knudsen <ar@jf-data.com> Date: Tue May 24 17:41:10 2022 +0200 Fix #12454 by having Coalesce handle null values (#12456) * Fix #12454 by having Coalesce handle null values * Allow null values in Html.Coalesce #12454 commit 963d4c5051f280770303c2e312e8ee9cb67d18cc Author: Paul Johnson <pmj@umbraco.com> Date: Tue May 24 13:55:39 2022 +0100 Ensure unique buildnumber for devops UI
2022-05-25 10:48:45 +01:00
if (_connectionStrings.CurrentValue.IsConnectionStringConfigured())
{
merge release/10.0.0 into v10/dev commit 9ff06eec6e82bd90a29a37dd34ecba931859f5f5 Author: Ronald Barendse <ronald@barend.se> Date: Wed May 25 11:16:39 2022 +0200 v10: Instantly reload ConnectionStrings after saving configuration (#12475) * Do not replace DataDirectory placeholder when setting connection string * Ensure ConnectionStrings options are updated when configuration is reloaded * Use CurrentValue to get default Umbraco connection string commit fcee6dc06ad829519202a29c2b549c7c65c47785 Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 10:08:43 2022 +0100 Fix legacy scope provider no longer implementing ICoreScopeProvider (#12480) commit 88f3628d0a330374673d187da8843b56a2ee8f0b Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 09:49:33 2022 +0100 Fix options monitor setup for connectionstrings (#12472) commit 4eeb03e7fb8c05be615156410efba3ed30e0e9c1 Author: Johan Runsten <jrunestone@users.noreply.github.com> Date: Wed May 25 10:13:25 2022 +0200 Fixed null check typo in CacheInstructionService. Fixes #12473. (#12474) * Fixed null check typo. Fixes #12473. * Removed unneccessary null forgiving operator Co-authored-by: Johan Runsten <johan.runsten@toxic.se> commit d810d66e9a0dbbfd19432b4cab610b728a6944e0 Author: Asbjørn Riis-Knudsen <ar@jf-data.com> Date: Tue May 24 17:41:10 2022 +0200 Fix #12454 by having Coalesce handle null values (#12456) * Fix #12454 by having Coalesce handle null values * Allow null values in Html.Coalesce #12454 commit 963d4c5051f280770303c2e312e8ee9cb67d18cc Author: Paul Johnson <pmj@umbraco.com> Date: Tue May 24 13:55:39 2022 +0100 Ensure unique buildnumber for devops UI
2022-05-25 10:48:45 +01:00
// A connection string was present, determine whether this is an install/upgrade
// Return true (upgrade) if there is an installed version, else false (install)
2018-12-18 10:39:39 +01:00
var result = _databaseBuilder.ValidateSchema();
return result?.DetermineHasInstalledVersion() ?? false;
}
merge release/10.0.0 into v10/dev commit 9ff06eec6e82bd90a29a37dd34ecba931859f5f5 Author: Ronald Barendse <ronald@barend.se> Date: Wed May 25 11:16:39 2022 +0200 v10: Instantly reload ConnectionStrings after saving configuration (#12475) * Do not replace DataDirectory placeholder when setting connection string * Ensure ConnectionStrings options are updated when configuration is reloaded * Use CurrentValue to get default Umbraco connection string commit fcee6dc06ad829519202a29c2b549c7c65c47785 Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 10:08:43 2022 +0100 Fix legacy scope provider no longer implementing ICoreScopeProvider (#12480) commit 88f3628d0a330374673d187da8843b56a2ee8f0b Author: Paul Johnson <pmj@umbraco.com> Date: Wed May 25 09:49:33 2022 +0100 Fix options monitor setup for connectionstrings (#12472) commit 4eeb03e7fb8c05be615156410efba3ed30e0e9c1 Author: Johan Runsten <jrunestone@users.noreply.github.com> Date: Wed May 25 10:13:25 2022 +0200 Fixed null check typo in CacheInstructionService. Fixes #12473. (#12474) * Fixed null check typo. Fixes #12473. * Removed unneccessary null forgiving operator Co-authored-by: Johan Runsten <johan.runsten@toxic.se> commit d810d66e9a0dbbfd19432b4cab610b728a6944e0 Author: Asbjørn Riis-Knudsen <ar@jf-data.com> Date: Tue May 24 17:41:10 2022 +0200 Fix #12454 by having Coalesce handle null values (#12456) * Fix #12454 by having Coalesce handle null values * Allow null values in Html.Coalesce #12454 commit 963d4c5051f280770303c2e312e8ee9cb67d18cc Author: Paul Johnson <pmj@umbraco.com> Date: Tue May 24 13:55:39 2022 +0100 Ensure unique buildnumber for devops UI
2022-05-25 10:48:45 +01:00
// No connection string configured, probably a fresh install
return false;
}
}
2017-07-20 11:21:28 +02:00
}