Skip to content

Commit

Permalink
Add Target column to the LinkFieldIndex table
Browse files Browse the repository at this point in the history
Fix #16378
  • Loading branch information
MikeAlhayek committed Jun 27, 2024
1 parent 51eb7b8 commit 0dd3422
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class LinkFieldIndex : ContentFieldIndex
// minus 1 (freeing 4 bytes) for the additional 'Published' and 'Latest' booleans.
public const int MaxUrlSize = 766;
public const int MaxTextSize = 766;
public const int MaxTargetSize = 100;

public string Url { get; set; }
public string BigUrl { get; set; }
Expand Down Expand Up @@ -53,10 +54,10 @@ public override void Describe(DescribeContext<ContentItem> context)
return null;
}

// Lazy initialization because of ISession cyclic dependency
// Lazy initialization because of ISession cyclic dependency.
_contentDefinitionManager ??= _serviceProvider.GetRequiredService<IContentDefinitionManager>();

// Search for LinkField
// Search for LinkField.
var contentTypeDefinition = await _contentDefinitionManager.GetTypeDefinitionAsync(contentItem.ContentType);

// This can occur when content items become orphaned, particularly layer widgets when a layer is removed, before its widgets have been unpublished.
Expand All @@ -70,7 +71,7 @@ public override void Describe(DescribeContext<ContentItem> context)
.Parts.SelectMany(x => x.PartDefinition.Fields.Where(f => f.FieldDefinition.Name == nameof(LinkField)))
.ToArray();

// This type doesn't have any LinkField, ignore it
// This type doesn't have any LinkField, ignore it.
if (fieldDefinitions.Length == 0)
{
_ignoredTypes.Add(contentItem.ContentType);
Expand All @@ -89,11 +90,11 @@ public override void Describe(DescribeContext<ContentItem> context)
ContentType = contentItem.ContentType,
ContentPart = pair.Definition.ContentTypePartDefinition.Name,
ContentField = pair.Definition.Name,
Url = pair.Field.Url?[..Math.Min(pair.Field.Url.Length, LinkFieldIndex.MaxUrlSize)],
Url = pair.Field.Url?.Substring(0, Math.Min(pair.Field.Target.Length, LinkFieldIndex.MaxUrlSize)),
BigUrl = pair.Field.Url,
Text = pair.Field.Text?[..Math.Min(pair.Field.Text.Length, LinkFieldIndex.MaxTextSize)],
Text = pair.Field.Text?.Substring(0, Math.Min(pair.Field.Target.Length, LinkFieldIndex.MaxTextSize)),
BigText = pair.Field.Text,
Target = pair.Field.Target,
Target = pair.Field.Target?.Substring(0, Math.Min(pair.Field.Target.Length, LinkFieldIndex.MaxTargetSize)),
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,5 +807,14 @@ await SchemaBuilder.AlterIndexTableAsync<TimeFieldIndex>(table => table

return 5;
}

public async Task<int> UpdateFrom5Async()
{
await SchemaBuilder.AlterIndexTableAsync<LinkFieldIndex>(table => table
.AddColumn<string>("Target", column => column.WithLength(LinkFieldIndex.MaxTargetSize))
);

return 6;
}
}
}

0 comments on commit 0dd3422

Please sign in to comment.