Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phase6/main clone #297

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions MyMigrations/DTGEMigrator/DTGEMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
using Umbraco.Cms.Core.Models;
using Umbraco.Extensions;

using uSync.Migrations.Core;
using uSync.Migrations.Core.Context;
using uSync.Migrations.Core.Migrators;
using uSync.Migrations.Core.Migrators.Models;

namespace MyMigrations.DTGEMigrator;

[SyncMigrator(Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Grid)]
[SyncMigrator(uSyncMigrations.EditorAliases.Grid)]
[SyncMigratorVersion(7, 8)]
[SyncDefaultMigrator]
public class DTGEMigrator : SyncPropertyMigratorBase
Expand All @@ -33,9 +34,9 @@ public DTGEMigrator(
}

public override string GetEditorAlias(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
=> Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Grid;
=> uSyncMigrations.EditorAliases.Grid;

public override string GetDatabaseType(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
public override string GetDatabaseType(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
=> nameof(ValueStorageType.Ntext);

public override object? GetConfigValues(SyncMigrationDataTypeProperty dataTypeProperty, SyncMigrationContext context)
Expand Down Expand Up @@ -106,13 +107,13 @@ private Dictionary<string, object> GetPropertyValues(GridValue.GridControl contr

foreach (var (propertyAlias, value) in elementValue)
{
var editorAlias = context.ContentTypes.GetEditorAliasByTypeAndProperty(contentTypeAlias, propertyAlias);
if (context.ContentTypes.TryGetEditorAliasByTypeAndProperty(contentTypeAlias, propertyAlias, out var editorAlias) is false) { continue; }

if (editorAlias == null) continue;

var migrator = context.Migrators.TryGetMigrator("DTGE." + editorAlias.OriginalEditorAlias);
if (migrator == null)
migrator = context.Migrators.TryGetMigrator(editorAlias.OriginalEditorAlias);
if (context.Migrators.TryGetMigrator("DTGE." + editorAlias.OriginalEditorAlias, out var migrator) is false
&& context.Migrators.TryGetMigrator(editorAlias.OriginalEditorAlias, out migrator) is false)
{
return propertyValues;
}

var propertyValue = value;

Expand Down
38 changes: 11 additions & 27 deletions MyMigrations/DTGEMigrator/DTGENestedContentMigrator.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using Newtonsoft.Json;

using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Extensions;

using uSync.Migrations.Core;
using uSync.Migrations.Core.Context;
using uSync.Migrations.Core.Legacy;
using uSync.Migrations.Core.Migrators;
using uSync.Migrations.Core.Migrators.Models;
using uSync.Migrations.Migrators.Core;

namespace MyMigrations.DTGEMigrator;

[SyncMigrator("DTGE." + Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.NestedContent, typeof(NestedContentConfiguration), IsDefaultAlias = true)]
[SyncMigrator("DTGE.Our.Umbraco.NestedContent")]
[SyncMigrator("DTGE." + uSyncMigrations.EditorAliases.NestedContent, typeof(LegacyNestedContentConfiguration), IsDefaultAlias = true)]
[SyncMigrator("DTGE." + uSyncMigrations.EditorAliases.NestedContentCommunity)]
[SyncDefaultMigrator]
public class DTGENestedContentMigrator : NestedContentMigrator
{
Expand All @@ -24,7 +25,7 @@ public DTGENestedContentMigrator()
{
if (string.IsNullOrWhiteSpace(contentProperty.Value)) return string.Empty;

var rowValues = JsonConvert.DeserializeObject<IList<NestedContentRowValue>>(contentProperty.Value);
var rowValues = JsonConvert.DeserializeObject<IList<LegacyNestedContentRowValue>>(contentProperty.Value);
if (rowValues == null) return string.Empty;

foreach (var row in rowValues)
Expand All @@ -36,15 +37,15 @@ public DTGENestedContentMigrator()

foreach (var property in row.RawPropertyValues)
{
var editorAlias = context.ContentTypes.GetEditorAliasByTypeAndProperty(row.ContentTypeAlias, property.Key);
if (editorAlias == null) continue;
if (context.ContentTypes.TryGetEditorAliasByTypeAndProperty(row.ContentTypeAlias, property.Key, out var editorAlias) is false) { continue; }

try
{
var migrator = context.Migrators.TryGetMigrator("DTGE." + editorAlias.OriginalEditorAlias)
?? context.Migrators.TryGetMigrator(editorAlias.OriginalEditorAlias);

if (migrator == null) continue;
if (context.Migrators.TryGetMigrator("DTGE." + editorAlias.OriginalEditorAlias, out var migrator) is false &&
context.Migrators.TryGetMigrator(editorAlias.OriginalEditorAlias, out migrator) is false)
{
continue;
}

var contentValue = migrator.GetContentValue(
new SyncMigrationContentProperty(
Expand All @@ -68,22 +69,5 @@ public DTGENestedContentMigrator()

return JsonConvert.SerializeObject(rowValues, Formatting.Indented);
}


}

internal class NestedContentRowValue
{
[JsonProperty("key")]
public Guid Id { get; set; }

[JsonProperty("name")]
public string? Name { get; set; }

[JsonProperty("ncContentTypeAlias")]
public string ContentTypeAlias { get; set; } = null!;

[JsonExtensionData]
public IDictionary<string, object?> RawPropertyValues { get; set; } = null!;
}

3 changes: 2 additions & 1 deletion MyMigrations/GridToBlockListMigrator.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Umbraco.Cms.Core.Composing;

using uSync.Migrations.Core;
using uSync.Migrations.Core.Context;
using uSync.Migrations.Core.Migrators;
using uSync.Migrations.Core.Migrators.Models;

namespace MyMigrations;

[SyncMigrator(Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Grid)]
[SyncMigrator(uSyncMigrations.EditorAliases.Grid)]
[HideFromTypeFinder] // hide from type if you don't want to automatically load this one (you have to replace in a composer)
// [SyncDefaultMigrator] // set it to default if you do load it and always want it to be the one you use. (can be overriden by preferred)
internal class GridToBlockListMigrator : SyncPropertyMigratorBase
Expand Down
5 changes: 3 additions & 2 deletions MyMigrations/Mergers/SimpleMergePlan.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using uSync.Migrations.Core.Configuration.Models;
using uSync.Migrations.Core.Models;
using uSync.Migrations.Core.Models;
using uSync.Migrations.Core.Plans;
using uSync.Migrations.Core.Plans.Models;

namespace MyMigrations.Mergers;
internal class SimpleMergePlan : ISyncMigrationPlan
Expand Down
2 changes: 1 addition & 1 deletion MyMigrations/MyMigrationComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Umbraco.Cms.Core.Models;

using uSync.Core;
using uSync.Migrations.Core.Composing;
using uSync.Migrations.Core;
using uSync.Migrations.Core.Notifications;
using uSync.Migrations.Migrators.Core;

Expand Down
9 changes: 5 additions & 4 deletions MyMigrations/MyMigrationProfile.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Umbraco.Cms.Core.Models;

using uSync.Migrations.Core;
using uSync.Migrations.Core.Composing;
using uSync.Migrations.Core.Configuration.Models;
using uSync.Migrations.Core.Extensions;
using uSync.Migrations.Core.Handlers;
using uSync.Migrations.Core.Plans;
using uSync.Migrations.Core.Plans.Models;
using uSync.Migrations.Migrators.Optional;

namespace MyMigrations;
Expand Down Expand Up @@ -46,8 +47,8 @@ public MyMigrationProfile(SyncMigrationHandlerCollection migrationHandlers)
// for this migrator we want to use our special grid migrator.
PreferredMigrators = new Dictionary<string, string>()
{
// { Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Grid, nameof(GridToBlockListMigrator) }
{ Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.NestedContent, nameof(NestedToBlockListMigrator) }
// { uSyncMigrations.EditorAliases.Grid, nameof(GridToBlockListMigrator) }
{ uSyncMigrations.EditorAliases.NestedContent, nameof(NestedToBlockListMigrator) }
},

// eveything beneath is optional...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
using uSync.BackOffice;
using uSync.BackOffice.Hubs;
using uSync.BackOffice.Services;
using uSync.Migrations.Client.Plans;
using uSync.Migrations.Core;
using uSync.Migrations.Core.Configuration;
using uSync.Migrations.Core.Configuration.CoreProfiles;
using uSync.Migrations.Core.Configuration.Models;
using uSync.Migrations.Core.Models;
using uSync.Migrations.Core.Plans;
using uSync.Migrations.Core.Plans.CoreProfiles;
using uSync.Migrations.Core.Plans.Models;
using uSync.Migrations.Core.Services;

namespace uSync.Migrations.Client.Controllers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
namespace uSync.Migrations.Client.Controllers;

[Tree(UmbConstants.Applications.Settings,
uSyncMigrations.TreeName,
uSyncMigrationsClient.TreeName,
TreeGroup = "sync",
TreeTitle = "uSync Migrations",
SortOrder = 99)]
[PluginController(uSyncMigrations.TreeName)]
[PluginController(uSyncMigrationsClient.TreeName)]
public class uSyncMigrationsTreeController : TreeController
{
private readonly IMenuItemCollectionFactory _menuItemCollectionFactory;
Expand All @@ -39,8 +39,8 @@ public uSyncMigrationsTreeController(

if (root.Value != null)
{
root.Value.RoutePath = $"{SectionAlias}/{uSyncMigrations.TreeName}/dashboard";
root.Value.Icon = uSyncMigrations.Icon;
root.Value.RoutePath = $"{SectionAlias}/{uSyncMigrationsClient.TreeName}/dashboard";
root.Value.Icon = uSyncMigrationsClient.Icon;
root.Value.HasChildren = false;
root.Value.MenuUrl = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
using uSync.Migrations.Core.Handlers.Shared;
using uSync.Migrations.Core.Services;

namespace uSync.Migrations.Core.Handlers.Seven;
namespace uSync.Migrations.Client.Handlers.Seven;

internal abstract class ContentBaseMigrationHandler<TEntity> : SharedContentBaseHandler<TEntity>
public abstract class ContentBaseMigrationHandler<TEntity> : SharedContentBaseHandler<TEntity>
where TEntity : ContentBase
{
public ContentBaseMigrationHandler(
Expand All @@ -41,7 +41,7 @@ protected override string GetContentType(XElement source, SyncMigrationContext c
=> context.ContentTypes.GetReplacementAlias(source.Attribute("nodeTypeAlias").ValueOrDefault(string.Empty));

protected override string GetPath(string alias, Guid parent, SyncMigrationContext context)
=> context.Content.GetContentPath(parent) + "/" + alias.ToSafeAlias(_shortStringHelper);
=> context.Content.GetContentPathOrDefault(parent, string.Empty) + "/" + alias.ToSafeAlias(_shortStringHelper);

protected override IEnumerable<XElement>? GetProperties(XElement source)
=> source.Elements();
Expand Down Expand Up @@ -77,7 +77,7 @@ protected override XElement GetBaseXml(XElement source, Guid parent, string cont
new XAttribute("Alias", alias),
new XAttribute("Level", level),
new XElement("Info",
new XElement("Parent", new XAttribute("Key", parent), context.Content.GetAliasByKey(parent)),
new XElement("Parent", new XAttribute("Key", parent), context.Content.TryGetAliasByKey(parent, out alias) is true ? alias : string.Empty),
new XElement("Path", path),
new XElement("Trashed", false),
new XElement("ContentType", contentType),
Expand All @@ -96,8 +96,9 @@ protected override XElement GetBaseXml(XElement source, Guid parent, string cont
info.Add(new XElement("Schedule"));

if (string.IsNullOrWhiteSpace(template) == false)
{
info.Add(new XElement("Template", new XAttribute("Key", context.Templates.GetKeyByAlias(template)), template));
{
info.Add(new XElement("Template",
new XAttribute("Key", context.Templates.TryGetKeyByAlias(template, out var templateKey) is true ? templateKey : Guid.Empty), template));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Strings;

using uSync.Migrations.Core;
using uSync.Migrations.Core.Handlers;
using uSync.Migrations.Core.Services;

namespace uSync.Migrations.Core.Handlers.Seven;
namespace uSync.Migrations.Client.Handlers.Seven;

[SyncMigrationHandler(BackOfficeConstants.Groups.Content, uSyncMigrations.Priorities.Content,
SourceVersion = 7,
SourceFolderName = "Content",
TargetFolderName = "Content")]
internal class ContentMigrationHandler : ContentBaseMigrationHandler<Content>, ISyncMigrationHandler
public class ContentMigrationHandler : ContentBaseMigrationHandler<Content>, ISyncMigrationHandler
{
public ContentMigrationHandler(
IEventAggregator eventAggregator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
using Umbraco.Extensions;

using uSync.Core;
using uSync.Migrations.Core.Composing;
using uSync.Migrations.Core.Context;
using uSync.Migrations.Core.Extensions;
using uSync.Migrations.Core.Handlers;
using uSync.Migrations.Core.Handlers.Shared;
using uSync.Migrations.Core.Services;

namespace uSync.Migrations.Core.Handlers.Seven;
namespace uSync.Migrations.Client.Handlers.Seven;

internal abstract class ContentTypeBaseMigrationHandler<TEntity> : SharedContentTypeBaseHandler<TEntity>
public abstract class ContentTypeBaseMigrationHandler<TEntity> : SharedContentTypeBaseHandler<TEntity>
where TEntity : ContentTypeBase
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;

using uSync.Migrations.Core.Composing;
using uSync.Migrations.Core;
using uSync.Migrations.Core.Handlers;
using uSync.Migrations.Core.Services;

namespace uSync.Migrations.Core.Handlers.Seven;
namespace uSync.Migrations.Client.Handlers.Seven;

[SyncMigrationHandler(BackOfficeConstants.Groups.Settings, uSyncMigrations.Priorities.ContentTypes,
SourceVersion = 7,
SourceFolderName = "DocumentType",
TargetFolderName = "ContentTypes")]
internal class ContentTypeMigrationHandler : ContentTypeBaseMigrationHandler<ContentType>, ISyncMigrationHandler
public class ContentTypeMigrationHandler : ContentTypeBaseMigrationHandler<ContentType>, ISyncMigrationHandler
{
public ContentTypeMigrationHandler(
IEventAggregator eventAggregator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
using Umbraco.Extensions;

using uSync.Core;
using uSync.Migrations.Core.Composing;
using uSync.Migrations.Core;
using uSync.Migrations.Core.Context;
using uSync.Migrations.Core.Extensions;
using uSync.Migrations.Core.Handlers;
using uSync.Migrations.Core.Handlers.Shared;
using uSync.Migrations.Core.Migrators;
using uSync.Migrations.Core.Migrators.Models;
Expand All @@ -19,13 +20,13 @@
using uSync.Migrations.Core.Validation;


namespace uSync.Migrations.Core.Handlers.Seven;
namespace uSync.Migrations.Client.Handlers.Seven;

[SyncMigrationHandler(BackOfficeConstants.Groups.Settings, uSyncMigrations.Priorities.DataTypes,
SourceVersion = 7,
SourceFolderName = "DataType",
TargetFolderName = "DataTypes")]
internal class DataTypeMigrationHandler : SharedDataTypeHandler, ISyncMigrationHandler, ISyncMigrationValidator
public class DataTypeMigrationHandler : SharedDataTypeHandler, ISyncMigrationHandler, ISyncMigrationValidator
{
private readonly SyncPropertyMigratorCollection _migrators;

Expand Down Expand Up @@ -61,15 +62,15 @@ protected override (string alias, Guid key) GetAliasAndKey(XElement source, Sync
//
// replacements
//
var migrator = context.Migrators.TryGetMigrator(editorAlias);
if (migrator != null && migrator is ISyncReplacablePropertyMigrator replacablePropertyMigrator)
if (context.Migrators.TryGetMigrator(editorAlias, out var migrator) is false
|| migrator is not ISyncReplacablePropertyMigrator replaceablePropertyMigrator)
{
return replacablePropertyMigrator.GetReplacementEditorId(
new SyncMigrationDataTypeProperty(dataTypeAlias, editorAlias, databaseType, GetPreValues(source)),
context);
return null;
}

return null;
return replaceablePropertyMigrator.GetReplacementEditorId(
new SyncMigrationDataTypeProperty(dataTypeAlias, editorAlias, databaseType, GetPreValues(source)),
context);
}

protected override string GetEditorAlias(XElement source)
Expand Down
Loading