From e88264d0f740d34681e00fac28a327f3496f88e2 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 16 Jan 2015 11:08:00 +1100 Subject: [PATCH] Decouples more LogHelper --- src/Umbraco.Core/DatabaseContext.cs | 2 +- .../Persistence/Migrations/MigrationRunner.cs | 27 ++++++++++++++----- .../AlterTagRelationsTable.cs | 2 +- .../UpdateRelatedLinksData.cs | 4 +-- .../UpdateToNewMemberPropertyAliases.cs | 4 +-- .../Migrations/AlterMigrationTests.cs | 4 +-- .../Migrations/FindingMigrationsTest.cs | 2 +- .../Migrations/MigrationRunnerTests.cs | 6 ++--- .../TargetVersionSixthMigrationsTest.cs | 4 +-- .../Migrations/Upgrades/BaseUpgradeTest.cs | 2 +- .../Upgrades/SqlCeDataUpgradeTest.cs | 2 +- .../Upgrades/ValidateV7TagsUpgradeTest.cs | 2 +- .../Upgrades/ValidateV7UpgradeTest.cs | 4 +-- .../config/ClientDependency.config | 2 +- 14 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/Umbraco.Core/DatabaseContext.cs b/src/Umbraco.Core/DatabaseContext.cs index 53ea6bda7e..414c68bab0 100644 --- a/src/Umbraco.Core/DatabaseContext.cs +++ b/src/Umbraco.Core/DatabaseContext.cs @@ -639,7 +639,7 @@ namespace Umbraco.Core ? installedVersion : new Version(GlobalSettings.ConfigurationStatus); var targetVersion = UmbracoVersion.Current; - var runner = new MigrationRunner(currentVersion, targetVersion, GlobalSettings.UmbracoMigrationName); + var runner = new MigrationRunner(_logger, currentVersion, targetVersion, GlobalSettings.UmbracoMigrationName); var upgraded = runner.Execute(database, true); message = message + "

Upgrade completed!

"; diff --git a/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs b/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs index 6c077dd987..beacd2014d 100644 --- a/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs +++ b/src/Umbraco.Core/Persistence/Migrations/MigrationRunner.cs @@ -13,12 +13,25 @@ namespace Umbraco.Core.Persistence.Migrations /// public class MigrationRunner { + private readonly ILogger _logger; private readonly Version _currentVersion; private readonly Version _targetVersion; private readonly string _productName; + [Obsolete("Use the ctor that specifies all dependencies instead")] public MigrationRunner(Version currentVersion, Version targetVersion, string productName) + : this(LoggerResolver.Current.Logger, currentVersion, targetVersion, productName) { + } + + public MigrationRunner(ILogger logger, Version currentVersion, Version targetVersion, string productName) + { + if (logger == null) throw new ArgumentNullException("logger"); + if (currentVersion == null) throw new ArgumentNullException("currentVersion"); + if (targetVersion == null) throw new ArgumentNullException("targetVersion"); + Mandate.ParameterNotNullOrEmpty(productName, "productName"); + + _logger = logger; _currentVersion = currentVersion; _targetVersion = targetVersion; _productName = productName; @@ -44,7 +57,7 @@ namespace Umbraco.Core.Persistence.Migrations /// True if migrations were applied, otherwise False public virtual bool Execute(Database database, DatabaseProviders databaseProvider, bool isUpgrade = true) { - LogHelper.Info("Initializing database migrations"); + _logger.Info("Initializing database migrations"); var foundMigrations = FindMigrations(); @@ -142,7 +155,7 @@ namespace Umbraco.Core.Persistence.Migrations internal MigrationContext InitializeMigrations(List migrations, Database database, DatabaseProviders databaseProvider, bool isUpgrade = true) { //Loop through migrations to generate sql - var context = new MigrationContext(databaseProvider, database); + var context = new MigrationContext(databaseProvider, database, _logger); foreach (var migration in migrations) { @@ -152,12 +165,12 @@ namespace Umbraco.Core.Persistence.Migrations if (isUpgrade) { baseMigration.GetUpExpressions(context); - LogHelper.Info(string.Format("Added UPGRADE migration '{0}' to context", baseMigration.GetType().Name)); + _logger.Info(string.Format("Added UPGRADE migration '{0}' to context", baseMigration.GetType().Name)); } else { baseMigration.GetDownExpressions(context); - LogHelper.Info(string.Format("Added DOWNGRADE migration '{0}' to context", baseMigration.GetType().Name)); + _logger.Info(string.Format("Added DOWNGRADE migration '{0}' to context", baseMigration.GetType().Name)); } } else @@ -166,12 +179,12 @@ namespace Umbraco.Core.Persistence.Migrations if (isUpgrade) { migration.Up(); - LogHelper.Info(string.Format("Added UPGRADE migration '{0}' to context", migration.GetType().Name)); + _logger.Info(string.Format("Added UPGRADE migration '{0}' to context", migration.GetType().Name)); } else { migration.Down(); - LogHelper.Info(string.Format("Added DOWNGRADE migration '{0}' to context", migration.GetType().Name)); + _logger.Info(string.Format("Added DOWNGRADE migration '{0}' to context", migration.GetType().Name)); } } } @@ -194,7 +207,7 @@ namespace Umbraco.Core.Persistence.Migrations continue; } - LogHelper.Info("Executing sql statement " + i + ": " + sql); + _logger.Info("Executing sql statement " + i + ": " + sql); database.Execute(sql); i++; } diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AlterTagRelationsTable.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AlterTagRelationsTable.cs index 31cfeb7997..7cb5c9db03 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AlterTagRelationsTable.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/AlterTagRelationsTable.cs @@ -95,7 +95,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven var propertyTypes = propertyTypeIdRef.Where(x => x.NodeId == tr.NodeId).ToArray(); if (propertyTypes.Length == 0) { - LogHelper.Warn("There was no cmsContent reference for cmsTagRelationship for nodeId " + Logger.Warn("There was no cmsContent reference for cmsTagRelationship for nodeId " + tr.NodeId + ". The new tag system only supports tags with references to content in the cmsContent and cmsPropertyType tables. This row will be deleted: " + string.Format("nodeId: {0}, tagId: {1}", tr.NodeId, tr.TagId)); diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/UpdateRelatedLinksData.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/UpdateRelatedLinksData.cs index 89630c7ab5..218724e053 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/UpdateRelatedLinksData.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSeven/UpdateRelatedLinksData.cs @@ -23,7 +23,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven Execute.Code(UpdateRelatedLinksDataDo); } - public static string UpdateRelatedLinksDataDo(Database database) + public string UpdateRelatedLinksDataDo(Database database) { if (database != null) { @@ -66,7 +66,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSeven } catch (Exception ex) { - LogHelper.Error("The data stored for property id " + data.Id + " on document " + data.NodeId + + Logger.Error("The data stored for property id " + data.Id + " on document " + data.NodeId + " is not valid XML, the data will be removed because it cannot be converted to the new format. The value was: " + data.Text, ex); data.Text = ""; diff --git a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSixTwoZero/UpdateToNewMemberPropertyAliases.cs b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSixTwoZero/UpdateToNewMemberPropertyAliases.cs index 555c0bcdf1..127aa92d22 100644 --- a/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSixTwoZero/UpdateToNewMemberPropertyAliases.cs +++ b/src/Umbraco.Core/Persistence/Migrations/Upgrades/TargetVersionSixTwoZero/UpdateToNewMemberPropertyAliases.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSixTwoZero Execute.Code(Update); } - internal static string Update(Database database) + internal string Update(Database database) { if (database != null) { @@ -75,7 +75,7 @@ WHERE umbracoNode.nodeObjectType = @objectType"; } catch (Exception ex) { - LogHelper.Error("Exception was thrown when trying to upgrade old member aliases to the new ones", ex); + Logger.Error("Exception was thrown when trying to upgrade old member aliases to the new ones", ex); throw; } } diff --git a/src/Umbraco.Tests/Migrations/AlterMigrationTests.cs b/src/Umbraco.Tests/Migrations/AlterMigrationTests.cs index 16fcb8d1a2..94e8802ca4 100644 --- a/src/Umbraco.Tests/Migrations/AlterMigrationTests.cs +++ b/src/Umbraco.Tests/Migrations/AlterMigrationTests.cs @@ -18,7 +18,7 @@ namespace Umbraco.Tests.Migrations public void Drop_Foreign_Key() { // Arrange - var context = new MigrationContext(DatabaseProviders.SqlServerCE, null); + var context = new MigrationContext(DatabaseProviders.SqlServerCE, null, Mock.Of()); var stub = new DropForeignKeyMigrationStub(new SqlCeSyntaxProvider(), Mock.Of()); // Act @@ -35,7 +35,7 @@ namespace Umbraco.Tests.Migrations public void Can_Get_Up_Migration_From_MigrationStub() { // Arrange - var context = new MigrationContext(DatabaseProviders.SqlServerCE, null); + var context = new MigrationContext(DatabaseProviders.SqlServerCE, null, Mock.Of()); var stub = new AlterUserTableMigrationStub(new SqlCeSyntaxProvider(), Mock.Of()); // Act diff --git a/src/Umbraco.Tests/Migrations/FindingMigrationsTest.cs b/src/Umbraco.Tests/Migrations/FindingMigrationsTest.cs index 5d9632c39c..b7859c5326 100644 --- a/src/Umbraco.Tests/Migrations/FindingMigrationsTest.cs +++ b/src/Umbraco.Tests/Migrations/FindingMigrationsTest.cs @@ -62,7 +62,7 @@ namespace Umbraco.Tests.Migrations Assert.That(list.Count, Is.EqualTo(3)); - var context = new MigrationContext(DatabaseProviders.SqlServerCE, null); + var context = new MigrationContext(DatabaseProviders.SqlServerCE, null, Mock.Of()); foreach (var migration1 in list) { var migration = (MigrationBase) migration1; diff --git a/src/Umbraco.Tests/Migrations/MigrationRunnerTests.cs b/src/Umbraco.Tests/Migrations/MigrationRunnerTests.cs index 9ad4d87b38..01ddf4a871 100644 --- a/src/Umbraco.Tests/Migrations/MigrationRunnerTests.cs +++ b/src/Umbraco.Tests/Migrations/MigrationRunnerTests.cs @@ -17,7 +17,7 @@ namespace Umbraco.Tests.Migrations [Test] public void Executes_Only_One_Migration_For_Spanning_Multiple_Targets() { - var runner = new MigrationRunner(new Version(4, 0, 0), new Version(6, 0, 0), "Test"); + var runner = new MigrationRunner(Mock.Of(), new Version(4, 0, 0), new Version(6, 0, 0), "Test"); var migrations = runner.OrderedUpgradeMigrations(new List { new MultiMigration(new SqlCeSyntaxProvider(), Mock.Of()) }); @@ -33,7 +33,7 @@ namespace Umbraco.Tests.Migrations [Test] public void Executes_Migration_For_Spanning_One_Target_1() { - var runner = new MigrationRunner(new Version(4, 0, 0), new Version(5, 0, 0), "Test"); + var runner = new MigrationRunner(Mock.Of(), new Version(4, 0, 0), new Version(5, 0, 0), "Test"); var migrations = runner.OrderedUpgradeMigrations(new List { new MultiMigration(new SqlCeSyntaxProvider(), Mock.Of()) }); @@ -49,7 +49,7 @@ namespace Umbraco.Tests.Migrations [Test] public void Executes_Migration_For_Spanning_One_Target_2() { - var runner = new MigrationRunner(new Version(5, 0, 1), new Version(6, 0, 0), "Test"); + var runner = new MigrationRunner(Mock.Of(), new Version(5, 0, 1), new Version(6, 0, 0), "Test"); var migrations = runner.OrderedUpgradeMigrations(new List { new MultiMigration(new SqlCeSyntaxProvider(), Mock.Of()) }); diff --git a/src/Umbraco.Tests/Migrations/TargetVersionSixthMigrationsTest.cs b/src/Umbraco.Tests/Migrations/TargetVersionSixthMigrationsTest.cs index 6fbc3705b5..a3b72cade6 100644 --- a/src/Umbraco.Tests/Migrations/TargetVersionSixthMigrationsTest.cs +++ b/src/Umbraco.Tests/Migrations/TargetVersionSixthMigrationsTest.cs @@ -84,10 +84,10 @@ namespace Umbraco.Tests.Migrations var targetVersion = new Version("6.0.0"); var foundMigrations = MigrationResolver.Current.Migrations; - var migrationRunner = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName); + var migrationRunner = new MigrationRunner(Logger, configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName); var migrations = migrationRunner.OrderedUpgradeMigrations(foundMigrations).ToList(); - var context = new MigrationContext(DatabaseProviders.SqlServerCE, db); + var context = new MigrationContext(DatabaseProviders.SqlServerCE, db, Logger); foreach (MigrationBase migration in migrations) { migration.GetUpExpressions(context); diff --git a/src/Umbraco.Tests/Migrations/Upgrades/BaseUpgradeTest.cs b/src/Umbraco.Tests/Migrations/Upgrades/BaseUpgradeTest.cs index 6b2157bdfa..afa0158677 100644 --- a/src/Umbraco.Tests/Migrations/Upgrades/BaseUpgradeTest.cs +++ b/src/Umbraco.Tests/Migrations/Upgrades/BaseUpgradeTest.cs @@ -79,7 +79,7 @@ namespace Umbraco.Tests.Migrations.Upgrades } //Setup the MigrationRunner - var migrationRunner = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName); + var migrationRunner = new MigrationRunner(Mock.Of(), configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName); bool upgraded = migrationRunner.Execute(db, provider, true); Assert.That(upgraded, Is.True); diff --git a/src/Umbraco.Tests/Migrations/Upgrades/SqlCeDataUpgradeTest.cs b/src/Umbraco.Tests/Migrations/Upgrades/SqlCeDataUpgradeTest.cs index 7a6f3baf72..a3b0623f34 100644 --- a/src/Umbraco.Tests/Migrations/Upgrades/SqlCeDataUpgradeTest.cs +++ b/src/Umbraco.Tests/Migrations/Upgrades/SqlCeDataUpgradeTest.cs @@ -26,7 +26,7 @@ namespace Umbraco.Tests.Migrations.Upgrades var fix = new PublishAfterUpgradeToVersionSixth(); //Setup the MigrationRunner - var migrationRunner = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName); + var migrationRunner = new MigrationRunner(Mock.Of(), configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName); bool upgraded = migrationRunner.Execute(db, provider, true); Assert.That(upgraded, Is.True); diff --git a/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7TagsUpgradeTest.cs b/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7TagsUpgradeTest.cs index e5c8bd52e0..e8fccc48f8 100644 --- a/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7TagsUpgradeTest.cs +++ b/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7TagsUpgradeTest.cs @@ -120,7 +120,7 @@ namespace Umbraco.Tests.Migrations.Upgrades var migration = new AlterTagRelationsTable(); - var migrationContext = new MigrationContext(DatabaseProviders.SqlServerCE, DatabaseContext.Database); + var migrationContext = new MigrationContext(DatabaseProviders.SqlServerCE, DatabaseContext.Database, Logger); migration.GetUpExpressions(migrationContext); Assert.AreEqual( diff --git a/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7UpgradeTest.cs b/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7UpgradeTest.cs index 8e23e26855..973cfdfe70 100644 --- a/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7UpgradeTest.cs +++ b/src/Umbraco.Tests/Migrations/Upgrades/ValidateV7UpgradeTest.cs @@ -18,7 +18,7 @@ namespace Umbraco.Tests.Migrations.Upgrades public void Validate_AddIndexToCmsMacroTable() { var migration = new AddIndexToCmsMacroTable(true, new SqlCeSyntaxProvider(), Mock.Of()); - var migrationContext = new MigrationContext(DatabaseProviders.SqlServerCE, null); + var migrationContext = new MigrationContext(DatabaseProviders.SqlServerCE, null, Mock.Of()); migration.GetUpExpressions(migrationContext); Assert.AreEqual(1, migrationContext.Expressions.Count); @@ -32,7 +32,7 @@ namespace Umbraco.Tests.Migrations.Upgrades public void Validate_AddIndexToCmsMacroPropertyTable() { var migration = new AddIndexToCmsMacroPropertyTable(true, new SqlCeSyntaxProvider(), Mock.Of()); - var migrationContext = new MigrationContext(DatabaseProviders.SqlServerCE, null); + var migrationContext = new MigrationContext(DatabaseProviders.SqlServerCE, null, Mock.Of()); migration.GetUpExpressions(migrationContext); Assert.AreEqual(1, migrationContext.Expressions.Count); diff --git a/src/Umbraco.Web.UI/config/ClientDependency.config b/src/Umbraco.Web.UI/config/ClientDependency.config index e0485d14ab..32b39b9d50 100644 --- a/src/Umbraco.Web.UI/config/ClientDependency.config +++ b/src/Umbraco.Web.UI/config/ClientDependency.config @@ -10,7 +10,7 @@ NOTES: * Compression/Combination/Minification is not enabled unless debug="false" is specified on the 'compiliation' element in the web.config * A new version will invalidate both client and server cache and create new persisted files --> - +