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

upgrade of XbyK API to v29.4.1 #236

Merged
merged 2 commits into from
Sep 6, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,18 @@ private LoadMediaFileResult LoadMediaFileBinary(string? sourceMediaLibraryPath,
{
if (sourceMediaLibraryPath == null)
{
return new LoadMediaFileResult(false, null);
return new LoadMediaFileResult(false, null, null);
}

string filePath = Path.Combine(sourceMediaLibraryPath, relativeFilePath);
if (File.Exists(filePath))
{
byte[] data = File.ReadAllBytes(filePath);
var dummyFile = DummyUploadedFile.FromByteArray(data, contentType, data.LongLength, Path.GetFileName(filePath));
return new LoadMediaFileResult(true, dummyFile);
return new LoadMediaFileResult(true, dummyFile, filePath);
}

return new LoadMediaFileResult(false, null);
return new LoadMediaFileResult(false, null, filePath);
}

private async Task RequireMigratedMediaFiles(List<(IMediaLibrary sourceLibrary, ICmsSite sourceSite, MediaLibraryInfo targetLibrary)> migratedMediaLibraries, CancellationToken cancellationToken)
Expand Down Expand Up @@ -232,9 +232,10 @@ private async Task RequireMigratedMediaFiles(List<(IMediaLibrary sourceLibrary,

bool found = false;
IUploadedFile? uploadedFile = null;
string? searchedPath = null;
if (loadMediaFileData)
{
(found, uploadedFile) = LoadMediaFileBinary(sourceMediaLibraryPath, ksMediaFile.FilePath, ksMediaFile.FileMimeType);
(found, uploadedFile, searchedPath) = LoadMediaFileBinary(sourceMediaLibraryPath, ksMediaFile.FilePath, ksMediaFile.FileMimeType);
if (!found)
{
// report missing file (currently reported in mapper)
Expand All @@ -248,7 +249,7 @@ private async Task RequireMigratedMediaFiles(List<(IMediaLibrary sourceLibrary,
protocol.FetchedTarget(kxoMediaFile);

var source = new MediaFileInfoMapperSource(ksMediaFile, targetMediaLibrary.LibraryID, found ? uploadedFile : null,
librarySubfolder, toolkitConfiguration.MigrateOnlyMediaFileInfo.GetValueOrDefault(false));
librarySubfolder, toolkitConfiguration.MigrateOnlyMediaFileInfo.GetValueOrDefault(false), searchedPath);
var mapped = mediaFileInfoMapper.Map(source, kxoMediaFile);
protocol.MappedTarget(mapped);

Expand Down Expand Up @@ -299,5 +300,5 @@ private async Task RequireMigratedMediaFiles(List<(IMediaLibrary sourceLibrary,
}
}

private record LoadMediaFileResult(bool Found, IUploadedFile? File);
private record LoadMediaFileResult(bool Found, IUploadedFile? File, string? SearchedPath);
}
31 changes: 29 additions & 2 deletions KVA/Migration.Toolkit.Source/Mappers/ContentItemMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ protected override IEnumerable<IUmtModel> MapInternal(CmsTreeMapperSource source
{
(var cmsTree, string safeNodeName, var siteGuid, var nodeParentGuid, var cultureToLanguageGuid, string targetFormDefinition, string sourceFormDefinition, var migratedDocuments) = source;

logger.LogTrace("Mapping {Value}", new { cmsTree.NodeAliasPath, cmsTree.NodeName, cmsTree.NodeGUID, cmsTree.NodeSiteID });

var nodeClass = modelFacade.SelectById<ICmsClass>(cmsTree.NodeClassID) ?? throw new InvalidOperationException($"Fatal: node class is missing, class id '{cmsTree.NodeClassID}'");

var contentItemGuid = spoiledGuidContext.EnsureNodeGuid(cmsTree.NodeGUID, cmsTree.NodeSiteID, cmsTree.NodeID);
Expand Down Expand Up @@ -530,13 +532,15 @@ ICmsClass nodeClass
columnName.Equals(CmsClassMapper.GetLegacyDocumentName(newFormInfo, nodeClass.ClassName), StringComparison.InvariantCultureIgnoreCase)
)
{
logger.LogTrace("Skipping '{FieldName}'", columnName);
continue;
}

#pragma warning disable CS0618 // Type or member is obsolete
if (oldFormInfo.GetFormField(columnName)?.External is true)
#pragma warning restore CS0618 // Type or member is obsolete
{
logger.LogTrace("Skipping '{FieldName}' - is external", columnName);
continue;
}

Expand Down Expand Up @@ -568,7 +572,7 @@ ICmsClass nodeClass
if (fieldMigration?.Actions?.Contains(TcaDirective.ConvertToAsset) ?? false)
{
if (value is string link &&
MediaHelper.MatchMediaLink(link) is (true, var mediaLinkKind, var mediaKind, var path, var mediaGuid))
MediaHelper.MatchMediaLink(link) is (true, var mediaLinkKind, var mediaKind, var path, var mediaGuid) result)
{
if (mediaLinkKind == MediaLinkKind.Path)
{
Expand All @@ -581,11 +585,12 @@ ICmsClass nodeClass
{
mfis = new[] { mediaFileInfo };
hasMigratedMediaFile = true;
logger.LogTrace("'{FieldName}' migrated Match={Value}", columnName, result);
break;
}
default:
{
logger.LogTrace("Unsuccessful attachment migration '{Field}': '{Value}'", columnName, path);
logger.LogTrace("Unsuccessful attachment migration '{Field}': '{Value}' - {Match}", columnName, path, result);
break;
}
}
Expand All @@ -596,6 +601,7 @@ ICmsClass nodeClass
// _mediaFileFacade.GetMediaFile()
// TODO tomas.krch: 2023-03-07 get media file by path
// attachmentDocument.DocumentNode.NodeAliasPath
logger.LogTrace("'{FieldName}' Skipped Match={Value}", columnName, result);
}
}

Expand Down Expand Up @@ -632,6 +638,10 @@ ICmsClass nodeClass
hasMigratedMediaFile = true;
logger.LogTrace("MediaFile migrated from attachment '{Field}': '{Value}'", columnName, attachmentGuid);
}
else
{
logger.LogTrace("'{FieldName}' UserControlForFile Success={Success} AttachmentGUID={attachmentGuid}", columnName, success, attachmentGuid);
}
}
else if (value is string attachmentGuidStr && Guid.TryParse(attachmentGuidStr, out attachmentGuid))
{
Expand All @@ -642,6 +652,14 @@ ICmsClass nodeClass
hasMigratedMediaFile = true;
logger.LogTrace("MediaFile migrated from attachment '{Field}': '{Value}' (parsed)", columnName, attachmentGuid);
}
else
{
logger.LogTrace("'{FieldName}' UserControlForFile Success={Success} AttachmentGUID={attachmentGuid}", columnName, success, attachmentGuid);
}
}
else
{
logger.LogTrace("'{FieldName}' UserControlForFile AttachmentGUID={Value}", columnName, value);
}

break;
Expand All @@ -658,6 +676,10 @@ ICmsClass nodeClass
.Select(x => x.MediaFileInfo).ToArray();
hasMigratedMediaFile = true;
}
else
{
logger.LogTrace("'{FieldName}' UserControlForDocAttachments DocumentID={Value}", columnName, documentId);
}

break;
}
Expand All @@ -677,6 +699,11 @@ ICmsClass nodeClass
target.SetValueAsJson(columnName,
mfis.Select(x => new AssetRelatedItem { Identifier = x.FileGUID, Dimensions = new AssetDimensions { Height = x.FileImageHeight, Width = x.FileImageWidth }, Name = x.FileName, Size = x.FileSize })
);
logger.LogTrace("'{FieldName}' setting '{Value}'", columnName, target.GetValueOrDefault(columnName));
}
else
{
logger.LogTrace("'{FieldName}' leaving '{Value}'", columnName, target.GetValueOrDefault(columnName));
}

continue;
Expand Down
7 changes: 4 additions & 3 deletions KVA/Migration.Toolkit.Source/Mappers/MediaFileInfoMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public record MediaFileInfoMapperSource(
int TargetLibraryId,
IUploadedFile? File,
string? LibrarySubFolder,
bool MigrateOnlyMediaFileInfo);
bool MigrateOnlyMediaFileInfo,
string? SearchedPath);

public class MediaFileInfoMapper(
ILogger<MediaFileInfoMapper> logger,
Expand All @@ -47,7 +48,7 @@ ModelFacade modelFacade

protected override MediaFileInfo MapInternal(MediaFileInfoMapperSource args, MediaFileInfo target, bool newInstance, MappingHelper mappingHelper, AddFailure addFailure)
{
(var mediaFile, int targetLibraryId, var file, _, bool migrateOnlyMediaFileInfo) = args;
(var mediaFile, int targetLibraryId, var file, _, bool migrateOnlyMediaFileInfo, string? searchedPath) = args;

target.FileName = mediaFile.FileName;
target.FileTitle = mediaFile.FileTitle;
Expand Down Expand Up @@ -97,7 +98,7 @@ protected override MediaFileInfo MapInternal(MediaFileInfoMapperSource args, Med
{
addFailure(HandbookReferences.MediaFileIsMissingOnSourceFilesystem
.WithId(nameof(mediaFile.FileID), mediaFile.FileID)
.WithData(new { mediaFile.FilePath, mediaFile.FileGUID, mediaFile.FileLibraryID, mediaFile.FileSiteID })
.WithData(new { mediaFile.FilePath, mediaFile.FileGUID, mediaFile.FileLibraryID, mediaFile.FileSiteID, SearchedPath = searchedPath })
.AsFailure<MediaFileInfo>()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.4.0" />
<PackageReference Include="Kentico.Xperience.UMT" Version="1.6.1" />
<PackageReference Include="MediatR" Version="12.4.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Migration.Toolkit.Common/Migration.Toolkit.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.4.0" />
<PackageReference Include="Kentico.Xperience.UMT" Version="1.6.1" />
<PackageReference Include="MediatR" Version="12.4.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.UMT" Version="1.4.0" />
<PackageReference Include="Kentico.Xperience.UMT" Version="1.6.1" />
<PackageReference Include="MediatR" Version="12.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Migration.Toolkit.KXP.Api/Migration.Toolkit.KXP.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.Admin" Version="29.3.3" />
<PackageReference Include="Kentico.Xperience.Core" Version="29.3.3" />
<PackageReference Include="Kentico.Xperience.Admin" Version="29.4.1" />
<PackageReference Include="Kentico.Xperience.Core" Version="29.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.Core" Version="29.3.3" />
<PackageReference Include="Kentico.Xperience.WebApp" Version="29.3.3" />
<PackageReference Include="Kentico.Xperience.Core" Version="29.4.1" />
<PackageReference Include="Kentico.Xperience.WebApp" Version="29.4.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5"/>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Migration.Toolkit.Tests/Migration.Toolkit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading