* Rename Umbraco.Core namespace to Umbraco.Cms.Core * Move extension methods in core project to Umbraco.Extensions * Move extension methods in core project to Umbraco.Extensions * Rename Umbraco.Examine namespace to Umbraco.Cms.Examine * Move examine extensions to Umbraco.Extensions namespace * Reflect changed namespaces in Builder and fix unit tests * Adjust namespace in Umbraco.ModelsBuilder.Embedded * Adjust namespace in Umbraco.Persistence.SqlCe * Adjust namespace in Umbraco.PublishedCache.NuCache * Align namespaces in Umbraco.Web.BackOffice * Align namespaces in Umbraco.Web.Common * Ensure that SqlCeSupport is still enabled after changing the namespace * Align namespaces in Umbraco.Web.Website * Align namespaces in Umbraco.Web.UI.NetCore * Align namespaces in Umbraco.Tests.Common * Align namespaces in Umbraco.Tests.UnitTests * Align namespaces in Umbraco.Tests.Integration * Fix errors caused by changed namespaces * Fix integration tests * Undo the Umbraco.Examine.Lucene namespace change This breaks integration tests on linux, since the namespace wont exists there because it's only used on windows. * Fix merge * Fix Merge
97 lines
3.7 KiB
C#
97 lines
3.7 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Options;
|
|
using Microsoft.Extensions.Logging;
|
|
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.Core;
|
|
using Umbraco.Core.Configuration;
|
|
using Umbraco.Core.Migrations.Install;
|
|
using Umbraco.Core.Migrations.Upgrade;
|
|
using Umbraco.Extensions;
|
|
using Umbraco.Web.Migrations.PostMigrations;
|
|
|
|
namespace Umbraco.Web.Install.InstallSteps
|
|
{
|
|
[InstallSetupStep(InstallationType.Upgrade | InstallationType.NewInstall,
|
|
"DatabaseUpgrade", 12, "")]
|
|
public class DatabaseUpgradeStep : InstallSetupStep<object>
|
|
{
|
|
private readonly DatabaseBuilder _databaseBuilder;
|
|
private readonly IRuntimeState _runtime;
|
|
private readonly ILogger<DatabaseUpgradeStep> _logger;
|
|
private readonly IUmbracoVersion _umbracoVersion;
|
|
private readonly ConnectionStrings _connectionStrings;
|
|
|
|
public DatabaseUpgradeStep(
|
|
DatabaseBuilder databaseBuilder,
|
|
IRuntimeState runtime,
|
|
ILogger<DatabaseUpgradeStep> logger,
|
|
IUmbracoVersion umbracoVersion,
|
|
IOptions<ConnectionStrings> connectionStrings)
|
|
{
|
|
_databaseBuilder = databaseBuilder;
|
|
_runtime = runtime;
|
|
_logger = logger;
|
|
_umbracoVersion = umbracoVersion;
|
|
_connectionStrings = connectionStrings.Value ?? throw new ArgumentNullException(nameof(connectionStrings));
|
|
}
|
|
|
|
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
|
{
|
|
var installSteps = InstallStatusTracker.GetStatus().ToArray();
|
|
var previousStep = installSteps.Single(x => x.Name == "DatabaseInstall");
|
|
var upgrade = previousStep.AdditionalData.ContainsKey("upgrade");
|
|
|
|
if (upgrade)
|
|
{
|
|
_logger.LogInformation("Running 'Upgrade' service");
|
|
|
|
var plan = new UmbracoPlan(_umbracoVersion);
|
|
plan.AddPostMigration<ClearCsrfCookies>(); // needed when running installer (back-office)
|
|
|
|
var result = _databaseBuilder.UpgradeSchemaAndData(plan);
|
|
|
|
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)
|
|
{
|
|
//if it's properly configured (i.e. the versions match) then no upgrade necessary
|
|
if (_runtime.Level == RuntimeLevel.Run)
|
|
return false;
|
|
|
|
var installSteps = InstallStatusTracker.GetStatus().ToArray();
|
|
//this step relies on the previous one completed - because it has stored some information we need
|
|
if (installSteps.Any(x => x.Name == "DatabaseInstall" && x.AdditionalData.ContainsKey("upgrade")) == false)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var databaseSettings = _connectionStrings.UmbracoConnectionString;
|
|
|
|
if (databaseSettings.IsConnectionStringConfigured())
|
|
{
|
|
// a connection string was present, determine whether this is an install/upgrade
|
|
// return true (upgrade) if there is an installed version, else false (install)
|
|
var result = _databaseBuilder.ValidateSchema();
|
|
return result.DetermineHasInstalledVersion();
|
|
}
|
|
|
|
//no connection string configured, probably a fresh install
|
|
return false;
|
|
}
|
|
}
|
|
}
|