Skip to content

Commit

Permalink
Merge pull request #8 from NikRimington/develop
Browse files Browse the repository at this point in the history
Beta 6
  • Loading branch information
NikRimington authored Sep 15, 2021
2 parents 440f056 + 015ea26 commit da5462e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public MenuRenderingNotificationHandler(IOptions<PageNotFound> 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;

Expand Down
33 changes: 22 additions & 11 deletions src/HC.PageNotFoundManager.Core/Migrations/InitialMigration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MigrateV8DataMigration> logger;

public PageNotFoundMigrationPlan()
: base("PageNotFoundManager") => DefinePlan();
public MigrateV8DataMigration(IMigrationContext context, ILogger<MigrateV8DataMigration> logger) : base(context)
{
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

}

protected override void Migrate()
{
logger.LogDebug("Starting migration - {migrationName}", MigrationName);

/// <inheritdoc/>
public override string InitialState => "{pagenotfound-init-state}";
if (TableExists("pageNotFoundConfig"))
MigrateLegacyData();
}

/// <summary>
/// Defines the plan.
/// </summary>
protected void DefinePlan()
private void MigrateLegacyData()
{
From("{pagenotfound-init-state}")
.To<InitialMigration>("{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<PageNotFoundInitialMigrationModel>(sql);
Database.InsertBatch(toMigrate);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Umbraco.Cms.Infrastructure.Migrations;

namespace HC.PageNotFoundManager.Core.Migrations
{
public class PageNotFoundMigrationPlan : MigrationPlan
{

public PageNotFoundMigrationPlan()
: base("PageNotFoundManager") => DefinePlan();

/// <inheritdoc/>
public override string InitialState => "{pagenotfound-init-state}";

/// <summary>
/// Defines the plan.
/// </summary>
protected void DefinePlan()
{
From("{pagenotfound-init-state}")
.To<InitialMigration>("{pagenotfound-init-complete}")
.To<MigrateV8DataMigration>("{pagenotfound-legacy-data-complete}");
}
}

}

0 comments on commit da5462e

Please sign in to comment.