2018-03-29 11:31:33 +02:00
using System ;
2019-01-11 14:30:04 +11:00
using System.Threading.Tasks ;
2021-02-18 11:06:02 +01:00
using Umbraco.Cms.Core.Configuration ;
using Umbraco.Cms.Core.Install.Models ;
using Umbraco.Cms.Core.Semver ;
using Umbraco.Cms.Core.Services ;
2021-08-10 19:31:27 +02:00
using Umbraco.Extensions ;
2021-02-18 11:06:02 +01:00
namespace Umbraco.Cms.Core.Install.InstallSteps
2014-03-04 19:20:36 +11:00
{
/// <summary>
/// This step is purely here to show the button to commence the upgrade
/// </summary>
2018-03-27 10:04:07 +02:00
[InstallSetupStep(InstallationType.Upgrade, "Upgrade", "upgrade", 1, "Upgrading Umbraco to the latest and greatest version.")]
2020-04-20 12:20:47 +02:00
public class UpgradeStep : InstallSetupStep < object >
2014-03-04 19:20:36 +11:00
{
2018-03-29 11:31:33 +02:00
public override bool RequiresExecution ( object model ) = > true ;
2019-11-19 23:15:11 +00:00
private readonly IUmbracoVersion _umbracoVersion ;
2020-02-17 14:58:34 +01:00
private readonly IRuntimeState _runtimeState ;
2019-11-19 23:15:11 +00:00
2020-02-17 14:58:34 +01:00
public UpgradeStep ( IUmbracoVersion umbracoVersion , IRuntimeState runtimeState )
2019-11-19 23:15:11 +00:00
{
_umbracoVersion = umbracoVersion ;
2020-02-17 14:58:34 +01:00
_runtimeState = runtimeState ;
2019-11-19 23:15:11 +00:00
}
2014-03-04 19:20:36 +11:00
2022-01-13 09:27:37 +01:00
public override Task < InstallSetupResult ? > ExecuteAsync ( object model ) = > Task . FromResult < InstallSetupResult ? > ( null ) ;
2016-07-12 15:57:48 +01:00
public override object ViewModel
{
get
{
2022-02-27 21:20:50 +01:00
string FormatGuidState ( string? value )
2018-03-30 10:16:21 +02:00
{
if ( string . IsNullOrWhiteSpace ( value ) ) value = "unknown" ;
else if ( Guid . TryParse ( value , out var currentStateGuid ) )
value = currentStateGuid . ToString ( "N" ) . Substring ( 0 , 8 ) ;
return value ;
}
2020-02-17 14:58:34 +01:00
var currentState = FormatGuidState ( _runtimeState . CurrentMigrationState ) ;
var newState = FormatGuidState ( _runtimeState . FinalMigrationState ) ;
2022-01-13 09:27:37 +01:00
var newVersion = _umbracoVersion . SemanticVersion ? . ToSemanticStringWithoutBuild ( ) ;
var oldVersion = new SemVersion ( _umbracoVersion . SemanticVersion ? . Major ? ? 0 , 0 , 0 ) . ToString ( ) ; //TODO can we find the old version somehow? e.g. from current state
2018-03-29 11:31:33 +02:00
2020-04-29 16:11:56 +02:00
var reportUrl = $"https://our.umbraco.com/contribute/releases/compare?from={oldVersion}&to={newVersion}¬es=1" ;
2016-07-26 16:19:17 +02:00
2020-04-29 16:11:56 +02:00
return new { oldVersion , newVersion , currentState , newState , reportUrl } ;
2016-07-12 15:57:48 +01:00
}
}
2014-03-04 19:20:36 +11:00
}
2017-07-20 11:21:28 +02:00
}