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

Enhance logs #292

Merged
merged 1 commit into from
Nov 12, 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
5 changes: 3 additions & 2 deletions KVA/Migration.Tool.Source/Mappers/MediaFileInfoMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MediaFileInfo>()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ public async Task<IMigrateAttachmentResult> 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!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ public async Task<IMigrateAttachmentResult> 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;
}

Expand Down
12 changes: 11 additions & 1 deletion Migration.Tool.Common/MigrationProtocol/HandbookReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public HandbookReference(string referenceName, string? additionalInfo = null)
public string ReferenceName { get; }
public string? AdditionalInfo { get; }
public Dictionary<string, object?>? Data { get; private set; }
public string Suggestion { get; private set; }

public override string ToString()
{
Expand All @@ -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;
}
/// <summary>
/// Related ID of data, specify if possible
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ private bool SaveUserUsingKenticoApi(IModelMappingResult<UserInfo> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ private void SaveUserUsingKenticoApi(IModelMappingResult<UserInfo> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ private Task SaveUserUsingKenticoApi(IModelMappingResult<UserInfo> 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);
Expand Down
Loading