diff --git a/src/HC.PageNotFoundManager.Core/Backoffice/MenuRenderingNotificationHandler.cs b/src/HC.PageNotFoundManager.Core/Backoffice/MenuRenderingNotificationHandler.cs index 5ed0b6c..6b48408 100644 --- a/src/HC.PageNotFoundManager.Core/Backoffice/MenuRenderingNotificationHandler.cs +++ b/src/HC.PageNotFoundManager.Core/Backoffice/MenuRenderingNotificationHandler.cs @@ -28,7 +28,7 @@ public MenuRenderingNotificationHandler(IOptions settings, IBackOf public void Handle(MenuRenderingNotification notification) { if (notification.TreeAlias != Umbraco.Cms.Core.Constants.Trees.Content - && int.TryParse(notification.NodeId, out var nodeId) && nodeId <= 0) return; + || int.TryParse(notification.NodeId, out var nodeId) && nodeId <= 0) return; if (backOfficeSecurity.BackOfficeSecurity.CurrentUser == null) return; diff --git a/src/HC.PageNotFoundManager.Core/Migrations/InitialMigration.cs b/src/HC.PageNotFoundManager.Core/Migrations/InitialMigration.cs index a886b35..91d7fdb 100644 --- a/src/HC.PageNotFoundManager.Core/Migrations/InitialMigration.cs +++ b/src/HC.PageNotFoundManager.Core/Migrations/InitialMigration.cs @@ -28,22 +28,33 @@ protected override void Migrate() } } - public class PageNotFoundMigrationPlan : MigrationPlan + public class MigrateV8DataMigration : MigrationBase { + public const string MigrationName = "page-not-found-manager-migration-legacy-data"; + private readonly ILogger logger; - public PageNotFoundMigrationPlan() - : base("PageNotFoundManager") => DefinePlan(); + public MigrateV8DataMigration(IMigrationContext context, ILogger logger) : base(context) + { + this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); + + } + + protected override void Migrate() + { + logger.LogDebug("Starting migration - {migrationName}", MigrationName); - /// - public override string InitialState => "{pagenotfound-init-state}"; + if (TableExists("pageNotFoundConfig")) + MigrateLegacyData(); + } - /// - /// Defines the plan. - /// - protected void DefinePlan() + private void MigrateLegacyData() { - From("{pagenotfound-init-state}") - .To("{pagenotfound-init-complete}"); + var sql = this.Sql().Select("unP.uniqueId as ParentId", "unF.uniqueId as NotFoundPageId").From("pageNotFoundConfig as org") + .LeftJoin("umbracoNode as unP").On("org.ParentId = unP.id") + .LeftJoin("umbracoNode as unF").On("org.NotFoundPageId = unF.id"); + + var toMigrate = Database.Fetch(sql); + Database.InsertBatch(toMigrate); } } diff --git a/src/HC.PageNotFoundManager.Core/Migrations/PageNotFoundMigrationPlan.cs b/src/HC.PageNotFoundManager.Core/Migrations/PageNotFoundMigrationPlan.cs new file mode 100644 index 0000000..5c4f6ba --- /dev/null +++ b/src/HC.PageNotFoundManager.Core/Migrations/PageNotFoundMigrationPlan.cs @@ -0,0 +1,25 @@ +using Umbraco.Cms.Infrastructure.Migrations; + +namespace HC.PageNotFoundManager.Core.Migrations +{ + public class PageNotFoundMigrationPlan : MigrationPlan + { + + public PageNotFoundMigrationPlan() + : base("PageNotFoundManager") => DefinePlan(); + + /// + public override string InitialState => "{pagenotfound-init-state}"; + + /// + /// Defines the plan. + /// + protected void DefinePlan() + { + From("{pagenotfound-init-state}") + .To("{pagenotfound-init-complete}") + .To("{pagenotfound-legacy-data-complete}"); + } + } + +}