2017-07-20 11:21:28 +02:00
|
|
|
|
using System;
|
2014-03-04 19:20:36 +11:00
|
|
|
|
using System.Configuration;
|
2014-02-26 16:30:25 +01:00
|
|
|
|
using System.Linq;
|
2019-01-11 14:30:04 +11:00
|
|
|
|
using System.Threading.Tasks;
|
2014-02-26 16:30:25 +01:00
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
2017-12-18 18:26:32 +01:00
|
|
|
|
using Umbraco.Core.Migrations.Install;
|
2019-02-13 09:53:17 +01:00
|
|
|
|
using Umbraco.Core.Migrations.Upgrade;
|
2014-02-26 16:30:25 +01:00
|
|
|
|
using Umbraco.Web.Install.Models;
|
2019-02-13 09:53:17 +01:00
|
|
|
|
using Umbraco.Web.Migrations;
|
|
|
|
|
|
using Umbraco.Web.Migrations.PostMigrations;
|
2014-02-26 16:30:25 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Install.InstallSteps
|
|
|
|
|
|
{
|
2014-10-01 14:58:30 +10:00
|
|
|
|
[InstallSetupStep(InstallationType.Upgrade | InstallationType.NewInstall,
|
2014-03-05 20:03:45 +01:00
|
|
|
|
"DatabaseUpgrade", 12, "")]
|
2014-02-26 16:30:25 +01:00
|
|
|
|
internal class DatabaseUpgradeStep : InstallSetupStep<object>
|
|
|
|
|
|
{
|
2016-11-29 10:31:25 +01:00
|
|
|
|
private readonly DatabaseBuilder _databaseBuilder;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
private readonly IRuntimeState _runtime;
|
2016-09-11 19:57:33 +02:00
|
|
|
|
private readonly ILogger _logger;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
|
2017-12-22 12:29:56 +01:00
|
|
|
|
public DatabaseUpgradeStep(DatabaseBuilder databaseBuilder, IRuntimeState runtime, ILogger logger)
|
2014-02-26 16:30:25 +01:00
|
|
|
|
{
|
2016-11-29 10:31:25 +01:00
|
|
|
|
_databaseBuilder = databaseBuilder;
|
2016-09-01 19:06:08 +02:00
|
|
|
|
_runtime = runtime;
|
2016-09-11 19:57:33 +02:00
|
|
|
|
_logger = logger;
|
2014-02-26 16:30:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-11 14:30:04 +11:00
|
|
|
|
public override Task<InstallSetupResult> ExecuteAsync(object model)
|
2014-02-26 16:30:25 +01:00
|
|
|
|
{
|
2017-07-20 11:21:28 +02:00
|
|
|
|
var installSteps = InstallStatusTracker.GetStatus().ToArray();
|
2014-03-05 12:21:49 +11:00
|
|
|
|
var previousStep = installSteps.Single(x => x.Name == "DatabaseInstall");
|
2014-02-26 16:30:25 +01:00
|
|
|
|
var upgrade = previousStep.AdditionalData.ContainsKey("upgrade");
|
|
|
|
|
|
|
|
|
|
|
|
if (upgrade)
|
|
|
|
|
|
{
|
2016-09-11 19:57:33 +02:00
|
|
|
|
_logger.Info<DatabaseUpgradeStep>("Running 'Upgrade' service");
|
2014-02-26 16:30:25 +01:00
|
|
|
|
|
2019-02-13 09:53:17 +01:00
|
|
|
|
var plan = new UmbracoPlan();
|
|
|
|
|
|
plan.AddPostMigration<ClearCsrfCookies>(); // needed when running installer (back-office)
|
|
|
|
|
|
|
|
|
|
|
|
var result = _databaseBuilder.UpgradeSchemaAndData(plan);
|
2014-02-26 16:30:25 +01:00
|
|
|
|
|
2014-03-13 21:47:08 +11:00
|
|
|
|
if (result.Success == false)
|
|
|
|
|
|
{
|
2014-03-20 17:35:51 +11:00
|
|
|
|
throw new InstallException("The database failed to upgrade. ERROR: " + result.Message);
|
2014-03-13 21:47:08 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-11 19:57:33 +02:00
|
|
|
|
DatabaseInstallStep.HandleConnectionStrings(_logger);
|
2014-02-26 16:30:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-11 14:30:04 +11:00
|
|
|
|
return Task.FromResult<InstallSetupResult>(null);
|
2014-02-26 16:30:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-03-05 14:30:17 +11:00
|
|
|
|
public override bool RequiresExecution(object model)
|
2014-03-04 11:16:42 +11:00
|
|
|
|
{
|
2014-03-04 19:20:36 +11:00
|
|
|
|
//if it's properly configured (i.e. the versions match) then no upgrade necessary
|
2016-09-01 19:06:08 +02:00
|
|
|
|
if (_runtime.Level == RuntimeLevel.Run)
|
2014-03-04 19:20:36 +11:00
|
|
|
|
return false;
|
2014-03-05 12:21:49 +11:00
|
|
|
|
|
|
|
|
|
|
var installSteps = InstallStatusTracker.GetStatus().ToArray();
|
2014-10-01 14:58:30 +10:00
|
|
|
|
//this step relies on the previous one completed - because it has stored some information we need
|
2014-03-05 12:21:49 +11:00
|
|
|
|
if (installSteps.Any(x => x.Name == "DatabaseInstall" && x.AdditionalData.ContainsKey("upgrade")) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
|
2017-05-12 14:49:44 +02:00
|
|
|
|
var databaseSettings = ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName];
|
2014-03-04 19:20:36 +11:00
|
|
|
|
|
2016-11-29 10:31:25 +01:00
|
|
|
|
if (_databaseBuilder.IsConnectionStringConfigured(databaseSettings))
|
2014-03-04 19:20:36 +11:00
|
|
|
|
{
|
2018-12-18 10:39:39 +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)
|
|
|
|
|
|
var result = _databaseBuilder.ValidateSchema();
|
|
|
|
|
|
return result.DetermineHasInstalledVersion();
|
2014-03-04 19:20:36 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//no connection string configured, probably a fresh install
|
|
|
|
|
|
return false;
|
2014-03-04 11:16:42 +11:00
|
|
|
|
}
|
2014-02-26 16:30:25 +01:00
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|