Skip to content

Commit

Permalink
#187 correctly migrated fields with pages selector
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrch committed Jul 15, 2024
1 parent bc16a47 commit 3d725da
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion KVA/Migration.Toolkit.Source/Mappers/ContentItemMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ ICmsClass nodeClass
if (fieldMigration.Actions?.Contains(TcaDirective.ConvertToPages) ?? false)
{
// relation to other document
var convertedRelation = relationshipService.GetNodeRelationships(cmsTree.NodeID)
var convertedRelation = relationshipService.GetNodeRelationships(cmsTree.NodeID, nodeClass.ClassName, field.Guid)
.Select(r => new WebPageRelatedItem { WebPageGuid = r.RightNode.NodeGUID });

target.SetValueAsJson(columnName, convertedRelation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void WalkProperties(JObject properties, List<EditingFormControlModel>? f
{
case Kx13FormComponents.Kentico_AttachmentSelector when newFormComponent == FormComponents.AdminAssetSelectorComponent:
{
if (value?.ToObject<List<Migration.Toolkit.Source.Services.Model.AttachmentSelectorItem>>() is { Count: > 0 } items)
if (value?.ToObject<List<AttachmentSelectorItem>>() is { Count: > 0 } items)
{
properties[key] = JToken.FromObject(items.Select(x => new AssetRelatedItem { Identifier = x.FileGuid }).ToList());
}
Expand Down
6 changes: 3 additions & 3 deletions KVA/Migration.Toolkit.Source/Model/CmsUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static CmsUserK12 FromReader(IDataReader reader, SemanticVersion version)
);
}
};
public partial record CmsUserK13(int UserID, string UserName, string? FirstName, string? MiddleName, string? LastName, string? FullName, string? Email, string UserPassword, string? PreferredCultureCode, string? PreferredUICultureCode, bool UserEnabled, bool? UserIsExternal, string? UserPasswordFormat, DateTime? UserCreated, DateTime? LastLogon, string? UserStartingAliasPath, Guid UserGUID, DateTime UserLastModified, string? UserLastLogonInfo, bool? UserIsHidden, bool? UserIsDomain, bool? UserHasAllowedCultures, bool? UserMFRequired, int UserPrivilegeLevel, string? UserSecurityStamp, byte[]? UserMFSecret, long? UserMFTimestep, string? CustomizedField1) : ICmsUser, ISourceModel<CmsUserK13>
public partial record CmsUserK13(int UserID, string UserName, string? FirstName, string? MiddleName, string? LastName, string? FullName, string? Email, string UserPassword, string? PreferredCultureCode, string? PreferredUICultureCode, bool UserEnabled, bool? UserIsExternal, string? UserPasswordFormat, DateTime? UserCreated, DateTime? LastLogon, string? UserStartingAliasPath, Guid UserGUID, DateTime UserLastModified, string? UserLastLogonInfo, bool? UserIsHidden, bool? UserIsDomain, bool? UserHasAllowedCultures, bool? UserMFRequired, int UserPrivilegeLevel, string? UserSecurityStamp, byte[]? UserMFSecret, long? UserMFTimestep) : ICmsUser, ISourceModel<CmsUserK13>
{
public static bool IsAvailable(SemanticVersion version) => true;
public static string GetPrimaryKeyName(SemanticVersion version) => "UserID";
Expand All @@ -114,13 +114,13 @@ public partial record CmsUserK13(int UserID, string UserName, string? FirstName,
static CmsUserK13 ISourceModel<CmsUserK13>.FromReader(IDataReader reader, SemanticVersion version)
{
return new CmsUserK13(
reader.Unbox<int>("UserID"), reader.Unbox<string>("UserName"), reader.Unbox<string?>("FirstName"), reader.Unbox<string?>("MiddleName"), reader.Unbox<string?>("LastName"), reader.Unbox<string?>("FullName"), reader.Unbox<string?>("Email"), reader.Unbox<string>("UserPassword"), reader.Unbox<string?>("PreferredCultureCode"), reader.Unbox<string?>("PreferredUICultureCode"), reader.Unbox<bool>("UserEnabled"), reader.Unbox<bool?>("UserIsExternal"), reader.Unbox<string?>("UserPasswordFormat"), reader.Unbox<DateTime?>("UserCreated"), reader.Unbox<DateTime?>("LastLogon"), reader.Unbox<string?>("UserStartingAliasPath"), reader.Unbox<Guid>("UserGUID"), reader.Unbox<DateTime>("UserLastModified"), reader.Unbox<string?>("UserLastLogonInfo"), reader.Unbox<bool?>("UserIsHidden"), reader.Unbox<bool?>("UserIsDomain"), reader.Unbox<bool?>("UserHasAllowedCultures"), reader.Unbox<bool?>("UserMFRequired"), reader.Unbox<int>("UserPrivilegeLevel"), reader.Unbox<string?>("UserSecurityStamp"), reader.Unbox<byte[]?>("UserMFSecret"), reader.Unbox<long?>("UserMFTimestep"), reader.Unbox<string?>("CustomizedField1")
reader.Unbox<int>("UserID"), reader.Unbox<string>("UserName"), reader.Unbox<string?>("FirstName"), reader.Unbox<string?>("MiddleName"), reader.Unbox<string?>("LastName"), reader.Unbox<string?>("FullName"), reader.Unbox<string?>("Email"), reader.Unbox<string>("UserPassword"), reader.Unbox<string?>("PreferredCultureCode"), reader.Unbox<string?>("PreferredUICultureCode"), reader.Unbox<bool>("UserEnabled"), reader.Unbox<bool?>("UserIsExternal"), reader.Unbox<string?>("UserPasswordFormat"), reader.Unbox<DateTime?>("UserCreated"), reader.Unbox<DateTime?>("LastLogon"), reader.Unbox<string?>("UserStartingAliasPath"), reader.Unbox<Guid>("UserGUID"), reader.Unbox<DateTime>("UserLastModified"), reader.Unbox<string?>("UserLastLogonInfo"), reader.Unbox<bool?>("UserIsHidden"), reader.Unbox<bool?>("UserIsDomain"), reader.Unbox<bool?>("UserHasAllowedCultures"), reader.Unbox<bool?>("UserMFRequired"), reader.Unbox<int>("UserPrivilegeLevel"), reader.Unbox<string?>("UserSecurityStamp"), reader.Unbox<byte[]?>("UserMFSecret"), reader.Unbox<long?>("UserMFTimestep")
);
}
public static CmsUserK13 FromReader(IDataReader reader, SemanticVersion version)
{
return new CmsUserK13(
reader.Unbox<int>("UserID"), reader.Unbox<string>("UserName"), reader.Unbox<string?>("FirstName"), reader.Unbox<string?>("MiddleName"), reader.Unbox<string?>("LastName"), reader.Unbox<string?>("FullName"), reader.Unbox<string?>("Email"), reader.Unbox<string>("UserPassword"), reader.Unbox<string?>("PreferredCultureCode"), reader.Unbox<string?>("PreferredUICultureCode"), reader.Unbox<bool>("UserEnabled"), reader.Unbox<bool?>("UserIsExternal"), reader.Unbox<string?>("UserPasswordFormat"), reader.Unbox<DateTime?>("UserCreated"), reader.Unbox<DateTime?>("LastLogon"), reader.Unbox<string?>("UserStartingAliasPath"), reader.Unbox<Guid>("UserGUID"), reader.Unbox<DateTime>("UserLastModified"), reader.Unbox<string?>("UserLastLogonInfo"), reader.Unbox<bool?>("UserIsHidden"), reader.Unbox<bool?>("UserIsDomain"), reader.Unbox<bool?>("UserHasAllowedCultures"), reader.Unbox<bool?>("UserMFRequired"), reader.Unbox<int>("UserPrivilegeLevel"), reader.Unbox<string?>("UserSecurityStamp"), reader.Unbox<byte[]?>("UserMFSecret"), reader.Unbox<long?>("UserMFTimestep"), reader.Unbox<string?>("CustomizedField1")
reader.Unbox<int>("UserID"), reader.Unbox<string>("UserName"), reader.Unbox<string?>("FirstName"), reader.Unbox<string?>("MiddleName"), reader.Unbox<string?>("LastName"), reader.Unbox<string?>("FullName"), reader.Unbox<string?>("Email"), reader.Unbox<string>("UserPassword"), reader.Unbox<string?>("PreferredCultureCode"), reader.Unbox<string?>("PreferredUICultureCode"), reader.Unbox<bool>("UserEnabled"), reader.Unbox<bool?>("UserIsExternal"), reader.Unbox<string?>("UserPasswordFormat"), reader.Unbox<DateTime?>("UserCreated"), reader.Unbox<DateTime?>("LastLogon"), reader.Unbox<string?>("UserStartingAliasPath"), reader.Unbox<Guid>("UserGUID"), reader.Unbox<DateTime>("UserLastModified"), reader.Unbox<string?>("UserLastLogonInfo"), reader.Unbox<bool?>("UserIsHidden"), reader.Unbox<bool?>("UserIsDomain"), reader.Unbox<bool?>("UserHasAllowedCultures"), reader.Unbox<bool?>("UserMFRequired"), reader.Unbox<int>("UserPrivilegeLevel"), reader.Unbox<string?>("UserSecurityStamp"), reader.Unbox<byte[]?>("UserMFSecret"), reader.Unbox<long?>("UserMFTimestep")
);
}
};
24 changes: 14 additions & 10 deletions KVA/Migration.Toolkit.Source/Services/CmsRelationshipService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@ namespace Migration.Toolkit.Source.Services;
using Migration.Toolkit.Source.Model;

public class CmsRelationshipService(
ILogger<CmsRelationshipService> logger,
ModelFacade modelFacade)
{
public record NodeRelationShipResult(ICmsRelationship Relationship, ICmsTree? RightNode);
public IEnumerable<NodeRelationShipResult> GetNodeRelationships(int nodeId)
public IEnumerable<NodeRelationShipResult> GetNodeRelationships(int nodeId, string className, Guid fieldGuid)
{
var relationships = modelFacade.SelectWhere<ICmsRelationship>("LeftNodeId = @nodeId", new SqlParameter("nodeId", nodeId));
var relationshipName = $"{className}_{fieldGuid}";
var relationships = modelFacade.SelectWhere<ICmsRelationship>("""
LeftNodeId = @nodeId AND
EXISTS(
SELECT 1 FROM CMS_RelationshipName
WHERE CMS_Relationship.RelationshipNameID = CMS_RelationshipName.RelationshipNameID AND
RelationshipName = @relationshipName
)
""",
new SqlParameter("nodeId", nodeId),
new SqlParameter("relationshipName", relationshipName)
);

foreach (var cmsRelationship in relationships)
{
yield return new(cmsRelationship, modelFacade.SelectById<ICmsTree>(cmsRelationship.RightNodeID));
}
// foreach (var cmsRelationship in kx13Context.CmsRelationships
// .Include(r => r.RelationshipName)
// .Include(r => r.RightNode)
// .Where(r => r.LeftNodeId == nodeId))
// {
// yield return cmsRelationship;
// }
}
}

0 comments on commit 3d725da

Please sign in to comment.