PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Umbraco.Web/Install/InstallSteps/MajorVersion7UpgradeReport.cs

https://github.com/solracnapod/Umbraco-CMS
C# | 119 lines | 98 code | 14 blank | 7 comment | 14 complexity | ecee8bd63897f26cc1cc742cf4a62994 MD5 | raw file
Possible License(s): MIT, Apache-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Umbraco.Core;
  5. using Umbraco.Core.Configuration;
  6. using Umbraco.Core.Persistence;
  7. using Umbraco.Core.Persistence.SqlSyntax;
  8. using Umbraco.Core.PropertyEditors;
  9. using Umbraco.Web.Install.Models;
  10. namespace Umbraco.Web.Install.InstallSteps
  11. {
  12. [InstallSetupStep(InstallationType.Upgrade,
  13. "MajorVersion7UpgradeReport", 1, "")]
  14. internal class MajorVersion7UpgradeReport : InstallSetupStep<object>
  15. {
  16. private readonly ApplicationContext _applicationContext;
  17. public MajorVersion7UpgradeReport(ApplicationContext applicationContext)
  18. {
  19. _applicationContext = applicationContext;
  20. }
  21. public override InstallSetupResult Execute(object model)
  22. {
  23. //we cannot run this step if the db is not configured.
  24. if (_applicationContext.DatabaseContext.IsDatabaseConfigured == false)
  25. {
  26. return null;
  27. }
  28. var result = _applicationContext.DatabaseContext.ValidateDatabaseSchema();
  29. var determinedVersion = result.DetermineInstalledVersion();
  30. return new InstallSetupResult("version7upgradereport",
  31. new
  32. {
  33. currentVersion = determinedVersion.ToString(),
  34. newVersion = UmbracoVersion.Current.ToString(),
  35. errors = CreateReport()
  36. });
  37. }
  38. public override bool RequiresExecution(object model)
  39. {
  40. //if it's configured, then no need to run
  41. if (_applicationContext.IsConfigured)
  42. {
  43. return false;
  44. }
  45. try
  46. {
  47. //we cannot run this step if the db is not configured.
  48. if (_applicationContext.DatabaseContext.IsDatabaseConfigured == false)
  49. {
  50. return false;
  51. }
  52. }
  53. catch (InvalidOperationException)
  54. {
  55. //if there is no db context
  56. return false;
  57. }
  58. var result = _applicationContext.DatabaseContext.ValidateDatabaseSchema();
  59. var determinedVersion = result.DetermineInstalledVersion();
  60. if ((string.IsNullOrWhiteSpace(GlobalSettings.ConfigurationStatus) == false || determinedVersion.Equals(new Version(0, 0, 0)) == false)
  61. && UmbracoVersion.Current.Major > determinedVersion.Major)
  62. {
  63. //it's an upgrade to a major version so we're gonna show this step if there are issues
  64. var report = CreateReport();
  65. return report.Any();
  66. }
  67. return false;
  68. }
  69. private IEnumerable<string> CreateReport()
  70. {
  71. var errorReport = new List<string>();
  72. var sql = new Sql();
  73. sql
  74. .Select(
  75. SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumn("cmsDataType", "controlId"),
  76. SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumn("umbracoNode", "text"))
  77. .From(SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName("cmsDataType"))
  78. .InnerJoin(SqlSyntaxContext.SqlSyntaxProvider.GetQuotedTableName("umbracoNode"))
  79. .On(
  80. SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumn("cmsDataType", "nodeId") + " = " +
  81. SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumn("umbracoNode", "id"));
  82. var list = _applicationContext.DatabaseContext.Database.Fetch<dynamic>(sql);
  83. foreach (var item in list)
  84. {
  85. Guid legacyId = item.controlId;
  86. //check for a map entry
  87. var alias = LegacyPropertyEditorIdToAliasConverter.GetAliasFromLegacyId(legacyId);
  88. if (alias != null)
  89. {
  90. //check that the new property editor exists with that alias
  91. var editor = PropertyEditorResolver.Current.GetByAlias(alias);
  92. if (editor == null)
  93. {
  94. errorReport.Add(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));
  95. }
  96. }
  97. else
  98. {
  99. errorReport.Add(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));
  100. }
  101. }
  102. return errorReport;
  103. }
  104. }
  105. }