From 7d32e1904ad7a59847b3e832a6fc4416b7509002 Mon Sep 17 00:00:00 2001 From: akfakmot Date: Mon, 11 Nov 2024 11:48:39 +0100 Subject: [PATCH] Enhance logging Enhance logging --- .../Mappers/MediaFileInfoMapper.cs | 5 +++-- .../Services/AttachmentMigratorToContentItem.cs | 7 ++++++- .../Services/AttachmentMigratorToMediaLibrary.cs | 7 ++++++- .../MigrationProtocol/HandbookReference.cs | 12 +++++++++++- .../Handlers/MigrateUsersCommandHandler.cs | 4 ++++ .../Handlers/MigrateUsersCommandHandler.cs | 4 ++++ .../Handlers/MigrateUsersCommandHandler.cs | 4 ++++ 7 files changed, 38 insertions(+), 5 deletions(-) diff --git a/KVA/Migration.Tool.Source/Mappers/MediaFileInfoMapper.cs b/KVA/Migration.Tool.Source/Mappers/MediaFileInfoMapper.cs index 563469cb..e6f72265 100644 --- a/KVA/Migration.Tool.Source/Mappers/MediaFileInfoMapper.cs +++ b/KVA/Migration.Tool.Source/Mappers/MediaFileInfoMapper.cs @@ -47,9 +47,9 @@ ToolConfiguration toolConfiguration return new MediaFileInfo(); } - protected override MediaFileInfo MapInternal(MediaFileInfoMapperSource args, MediaFileInfo target, bool newInstance, MappingHelper mappingHelper, AddFailure addFailure) + protected override MediaFileInfo MapInternal(MediaFileInfoMapperSource source, MediaFileInfo target, bool newInstance, MappingHelper mappingHelper, AddFailure addFailure) { - (string fullMediaFilePath, var mediaFile, int targetLibraryId, var file, _, bool migrateOnlyMediaFileInfo, var safeMediaFileGuid) = args; + (string fullMediaFilePath, var mediaFile, int targetLibraryId, var file, _, bool migrateOnlyMediaFileInfo, var safeMediaFileGuid) = source; target.FileName = mediaFile.FileName; target.FileTitle = mediaFile.FileTitle; @@ -100,6 +100,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, SearchedPath = fullMediaFilePath }) + .WithSuggestion($"If you have a backup, copy it to the filesystem on path {source.FullMediaFilePath}. Otherwise, delete the media file from the source instance using admin web interface.") .AsFailure() ); } diff --git a/KVA/Migration.Tool.Source/Services/AttachmentMigratorToContentItem.cs b/KVA/Migration.Tool.Source/Services/AttachmentMigratorToContentItem.cs index be94568e..ae841add 100644 --- a/KVA/Migration.Tool.Source/Services/AttachmentMigratorToContentItem.cs +++ b/KVA/Migration.Tool.Source/Services/AttachmentMigratorToContentItem.cs @@ -131,7 +131,12 @@ public async Task MigrateAttachment(ICmsAttachment ksA if (ksAttachment.AttachmentBinary is null) { - logger.LogError("Binary data is null, cannot migrate attachment: {Attachment}", ksAttachment); + logger.LogError("Attachment binary data is null {Attachment} " + + "Option 1: Via admin web interface of your source instance navigate to the attachment and update the data. " + + "Option 2: Update the database directly - table CMS_Attachment, column AttachmentBinary. " + + "Option 3: Via admin web interface of your source instance remove all attachment references, then remove the attachment", + new { ksAttachment.AttachmentName, ksAttachment.AttachmentSiteID, ksAttachment.AttachmentID }); + throw new InvalidOperationException("Attachment data is null!"); } diff --git a/KVA/Migration.Tool.Source/Services/AttachmentMigratorToMediaLibrary.cs b/KVA/Migration.Tool.Source/Services/AttachmentMigratorToMediaLibrary.cs index cdbe85c8..d03c645c 100644 --- a/KVA/Migration.Tool.Source/Services/AttachmentMigratorToMediaLibrary.cs +++ b/KVA/Migration.Tool.Source/Services/AttachmentMigratorToMediaLibrary.cs @@ -214,7 +214,12 @@ public async Task MigrateAttachment(ICmsAttachment ksA return DummyUploadedFile.FromStream(ms, attachment.AttachmentMimeType, attachment.AttachmentSize, attachment.AttachmentName); } - logger.LogWarning("Attachment binary is null! {Attachment}", new { attachment.AttachmentName, attachment.AttachmentSiteID, attachment.AttachmentID }); + logger.LogError("Attachment binary data is null {Attachment} " + + "Option 1: Via admin web interface of your source instance navigate to the attachment and update the data. " + + "Option 2: Update the database directly - table CMS_Attachment, column AttachmentBinary. " + + "Option 3: Via admin web interface of your source instance remove all attachment references, then remove the attachment", + new { attachment.AttachmentName, attachment.AttachmentSiteID, attachment.AttachmentID }); + return null; } diff --git a/Migration.Tool.Common/MigrationProtocol/HandbookReference.cs b/Migration.Tool.Common/MigrationProtocol/HandbookReference.cs index ae30b7d9..0d2888ce 100644 --- a/Migration.Tool.Common/MigrationProtocol/HandbookReference.cs +++ b/Migration.Tool.Common/MigrationProtocol/HandbookReference.cs @@ -26,6 +26,7 @@ public HandbookReference(string referenceName, string? additionalInfo = null) public string ReferenceName { get; } public string? AdditionalInfo { get; } public Dictionary? Data { get; private set; } + public string Suggestion { get; private set; } public override string ToString() { @@ -47,10 +48,19 @@ public override string ToString() sb.Append(", "); } } - + sb.AppendLine(); + if (!string.IsNullOrEmpty(Suggestion)) + { + sb.AppendLine($"Suggestion: {Suggestion}"); + } return sb.ToString(); } + public HandbookReference WithSuggestion(string suggestion) + { + Suggestion = suggestion; + return this; + } /// /// Related ID of data, specify if possible /// diff --git a/Migration.Tool.Core.K11/Handlers/MigrateUsersCommandHandler.cs b/Migration.Tool.Core.K11/Handlers/MigrateUsersCommandHandler.cs index 378a4501..5eb1f71d 100644 --- a/Migration.Tool.Core.K11/Handlers/MigrateUsersCommandHandler.cs +++ b/Migration.Tool.Core.K11/Handlers/MigrateUsersCommandHandler.cs @@ -89,6 +89,10 @@ private bool SaveUserUsingKenticoApi(IModelMappingResult mapped, CmsUs try { + if (string.IsNullOrEmpty(userInfo.Email)) + { + logger.LogError($"User {userInfo.UserName} does not have an email set. Email is required. You can set it via admin web interface of your source instance or directly in CMS_User database table."); + } UserInfoProvider.ProviderObject.Set(userInfo); protocol.Success(k11User, userInfo, mapped); diff --git a/Migration.Tool.Core.KX12/Handlers/MigrateUsersCommandHandler.cs b/Migration.Tool.Core.KX12/Handlers/MigrateUsersCommandHandler.cs index 42c482be..95989d6b 100644 --- a/Migration.Tool.Core.KX12/Handlers/MigrateUsersCommandHandler.cs +++ b/Migration.Tool.Core.KX12/Handlers/MigrateUsersCommandHandler.cs @@ -89,6 +89,10 @@ private void SaveUserUsingKenticoApi(IModelMappingResult mapped, KX12M try { + if (string.IsNullOrEmpty(userInfo.Email)) + { + logger.LogError($"User {userInfo.UserName} does not have an email set. Email is required. You can set it via admin web interface of your source instance or directly in CMS_User database table."); + } UserInfoProvider.ProviderObject.Set(userInfo); protocol.Success(k12User, userInfo, mapped); diff --git a/Migration.Tool.Core.KX13/Handlers/MigrateUsersCommandHandler.cs b/Migration.Tool.Core.KX13/Handlers/MigrateUsersCommandHandler.cs index f13f1d09..0c90eae6 100644 --- a/Migration.Tool.Core.KX13/Handlers/MigrateUsersCommandHandler.cs +++ b/Migration.Tool.Core.KX13/Handlers/MigrateUsersCommandHandler.cs @@ -89,6 +89,10 @@ private Task SaveUserUsingKenticoApi(IModelMappingResult mapped, KX13M try { + if (string.IsNullOrEmpty(userInfo.Email)) + { + logger.LogError($"User {userInfo.UserName} does not have an email set. Email is required. You can set it via admin web interface of your source instance or directly in CMS_User database table."); + } UserInfoProvider.ProviderObject.Set(userInfo); protocol.Success(kx13User, userInfo, mapped);