2014-02-26 16:30:25 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
using Umbraco.Web.Install.Models;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Install.InstallSteps
|
|
|
|
|
{
|
2014-03-04 11:42:11 +11:00
|
|
|
[InstallSetupStep("DatabaseUpgrade", 5, "Upgrading your database to the latest version")]
|
2014-02-26 16:30:25 +01:00
|
|
|
internal class DatabaseUpgradeStep : InstallSetupStep<object>
|
|
|
|
|
{
|
|
|
|
|
private readonly ApplicationContext _applicationContext;
|
2014-03-04 11:16:42 +11:00
|
|
|
private readonly InstallStatusType _status;
|
2014-02-26 16:30:25 +01:00
|
|
|
|
2014-03-04 11:16:42 +11:00
|
|
|
public DatabaseUpgradeStep(ApplicationContext applicationContext, InstallStatusType status)
|
2014-02-26 16:30:25 +01:00
|
|
|
{
|
|
|
|
|
_applicationContext = applicationContext;
|
2014-03-04 11:16:42 +11:00
|
|
|
_status = status;
|
2014-02-26 16:30:25 +01:00
|
|
|
}
|
|
|
|
|
|
2014-03-04 11:16:42 +11:00
|
|
|
public override InstallSetupResult Execute(object model)
|
2014-02-26 16:30:25 +01:00
|
|
|
{
|
2014-03-04 11:16:42 +11:00
|
|
|
if (_status == InstallStatusType.NewInstall) return null;
|
|
|
|
|
|
2014-02-26 16:30:25 +01:00
|
|
|
var installSteps = InstallStatusTracker.GetStatus();
|
|
|
|
|
//this step relies on the preious one completed - because it has stored some information we need
|
|
|
|
|
if (installSteps.Any(x => x.Key == "DatabaseConfigure") == false)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Could not find previous step: DatabaseConfigure of the installation, package install cannot continue");
|
|
|
|
|
}
|
|
|
|
|
var previousStep = installSteps["DatabaseConfigure"];
|
|
|
|
|
var upgrade = previousStep.AdditionalData.ContainsKey("upgrade");
|
|
|
|
|
|
|
|
|
|
if (upgrade)
|
|
|
|
|
{
|
|
|
|
|
LogHelper.Info<DatabaseUpgradeStep>("Running 'Upgrade' service");
|
|
|
|
|
|
|
|
|
|
var result = _applicationContext.DatabaseContext.UpgradeSchemaAndData();
|
|
|
|
|
|
|
|
|
|
DatabaseInstallStep.HandleConnectionStrings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-04 11:16:42 +11:00
|
|
|
public override bool RequiresExecution()
|
|
|
|
|
{
|
|
|
|
|
return _status != InstallStatusType.NewInstall;
|
|
|
|
|
}
|
2014-02-26 16:30:25 +01:00
|
|
|
}
|
|
|
|
|
}
|