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

Add ability to disable link based attachment migration #328

Open
alexey-nenazhenko-bm opened this issue Dec 28, 2024 · 0 comments
Open

Add ability to disable link based attachment migration #328

alexey-nenazhenko-bm opened this issue Dec 28, 2024 · 0 comments

Comments

@alexey-nenazhenko-bm
Copy link

alexey-nenazhenko-bm commented Dec 28, 2024

Motivation

When the --attachments parameter is not supplied AssetMigration.MigrateValue is trying to find and migrate attachment if it's link was found in document field value. Sometimes attachments might be missing, but referenced from RTE field for example. It will be very helpful to have a setting disabling this default behavior.

Proposed solution

  1. Add "IgnoreAttachmentLinks" app setting
  2. Add setting to ToolConfiguration
  3. Change method code this way:
if (mediaLinkKind == MediaLinkKind.Path)
{
    // path needs to be converted to GUID
    if (mediaKind == MediaKind.Attachment && path != null)
    {
        if (configuration.IgnoreAttachmentLinks)
        {
            logger.LogTrace("'{FieldName}' Skipped Match={Value}", fieldName, result);
        }
        else
        {
            switch (await attachmentMigrator.TryMigrateAttachmentByPath(path, $"__{fieldName}"))
            {
                case MigrateAttachmentResultMediaFile(true, _, var x, _):
                {
                    mfis = [new AssetRelatedItem { Identifier = x.FileGUID, Dimensions = new AssetDimensions { Height = x.FileImageHeight, Width = x.FileImageWidth }, Name = x.FileName, Size = x.FileSize }];
                    hasMigratedAsset = true;
                    logger.LogTrace("'{FieldName}' migrated Match={Value}", fieldName, result);
                    break;
                }
                case MigrateAttachmentResultContentItem { Success: true, ContentItemGuid: { } contentItemGuid }:
                {
                    mfis =
                    [
                        new ContentItemReference { Identifier = contentItemGuid }
                    ];
                    hasMigratedAsset = true;
                    logger.LogTrace("'{FieldName}' migrated Match={Value}", fieldName, result);
                    break;
                }
                default:
                {
                    logger.LogTrace("Unsuccessful attachment migration '{Field}': '{Value}' - {Match}", fieldName, path, result);
                    break;
                }
            }
        }
    }

    if (mediaKind == MediaKind.MediaFile)
    {
        logger.LogTrace("'{FieldName}' Skipped Match={Value}", fieldName, result);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant