2014-03-04 11:16:42 +11:00
using System ;
using System.Collections.Generic ;
using Umbraco.Core ;
using Umbraco.Core.Configuration ;
using Umbraco.Core.Persistence ;
using Umbraco.Core.Persistence.SqlSyntax ;
using Umbraco.Core.PropertyEditors ;
using Umbraco.Web.Install.Models ;
namespace Umbraco.Web.Install.InstallSteps
{
2014-03-04 19:20:36 +11:00
[ InstallSetupStep ( InstallationType . Upgrade ,
"MajorVersion7UpgradeReport" , 1 , "Checking for compatibility issues with upgrade" ) ]
2014-03-04 11:16:42 +11:00
internal class MajorVersion7UpgradeReport : InstallSetupStep < object >
{
private readonly ApplicationContext _applicationContext ;
2014-03-04 19:20:36 +11:00
public MajorVersion7UpgradeReport ( ApplicationContext applicationContext )
2014-03-04 11:16:42 +11:00
{
_applicationContext = applicationContext ;
}
public override InstallSetupResult Execute ( object model )
{
//we cannot run this step if the db is not configured.
if ( _applicationContext . DatabaseContext . IsDatabaseConfigured = = false )
{
return null ;
}
return new InstallSetupResult ( "version7upgradereport" , CreateReport ( ) ) ;
}
2014-03-04 19:20:36 +11:00
2014-03-04 11:16:42 +11:00
public override bool RequiresExecution ( )
{
2014-03-04 19:20:36 +11:00
//if it's configured, then no need to run
if ( _applicationContext . IsConfigured )
2014-03-04 11:16:42 +11:00
{
return false ;
}
2014-03-04 16:40:23 +11:00
try
{
//we cannot run this step if the db is not configured.
if ( _applicationContext . DatabaseContext . IsDatabaseConfigured = = false )
{
return false ;
}
}
catch ( InvalidOperationException )
2014-03-04 11:16:42 +11:00
{
2014-03-04 16:40:23 +11:00
//if there is no db context
2014-03-04 11:16:42 +11:00
return false ;
}
var result = _applicationContext . DatabaseContext . ValidateDatabaseSchema ( ) ;
var determinedVersion = result . DetermineInstalledVersion ( ) ;
if ( ( string . IsNullOrWhiteSpace ( GlobalSettings . ConfigurationStatus ) = = false | | determinedVersion . Equals ( new Version ( 0 , 0 , 0 ) ) = = false )
& & UmbracoVersion . Current . Major > determinedVersion . Major )
{
//it's an upgrade to a major version so we're gonna show this step
return true ;
}
return false ;
}
private IEnumerable < Tuple < bool , string > > CreateReport ( )
{
var errorReport = new List < Tuple < bool , string > > ( ) ;
var sql = new Sql ( ) ;
sql
. Select (
SqlSyntaxContext . SqlSyntaxProvider . GetQuotedColumn ( "cmsDataType" , "controlId" ) ,
SqlSyntaxContext . SqlSyntaxProvider . GetQuotedColumn ( "umbracoNode" , "text" ) )
. From ( SqlSyntaxContext . SqlSyntaxProvider . GetQuotedTableName ( "cmsDataType" ) )
. InnerJoin ( SqlSyntaxContext . SqlSyntaxProvider . GetQuotedTableName ( "umbracoNode" ) )
. On (
SqlSyntaxContext . SqlSyntaxProvider . GetQuotedColumn ( "cmsDataType" , "nodeId" ) + " = " +
SqlSyntaxContext . SqlSyntaxProvider . GetQuotedColumn ( "umbracoNode" , "id" ) ) ;
var list = _applicationContext . DatabaseContext . Database . Fetch < dynamic > ( sql ) ;
foreach ( var item in list )
{
Guid legacyId = item . controlId ;
//check for a map entry
var alias = LegacyPropertyEditorIdToAliasConverter . GetAliasFromLegacyId ( legacyId ) ;
if ( alias ! = null )
{
//check that the new property editor exists with that alias
var editor = PropertyEditorResolver . Current . GetByAlias ( alias ) ;
if ( editor = = null )
{
errorReport . Add ( new Tuple < bool , string > ( false , string . Format ( "Property Editor with ID '{0}' (assigned to Data Type '{1}') has a valid GUID -> Alias map but no property editor was found. It will be replaced with a Readonly/Label property editor." , item . controlId , item . text ) ) ) ;
}
}
else
{
errorReport . Add ( new Tuple < bool , string > ( false , string . Format ( "Property Editor with ID '{0}' (assigned to Data Type '{1}') does not have a valid GUID -> Alias map. It will be replaced with a Readonly/Label property editor." , item . controlId , item . text ) ) ) ;
}
}
return errorReport ;
}
}
}