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 Target column to the LinkFieldIndex table #16380

Closed
wants to merge 7 commits into from
Closed
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 @@ -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.Url.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.Text.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 @@ -308,6 +308,7 @@ await SchemaBuilder.CreateMapIndexTableAsync<LinkFieldIndex>(table => table
.Column<string>("ContentType", column => column.WithLength(ContentItemIndex.MaxContentTypeSize))
.Column<string>("ContentPart", column => column.WithLength(ContentItemIndex.MaxContentPartSize))
.Column<string>("ContentField", column => column.WithLength(ContentItemIndex.MaxContentFieldSize))
.Column<string>("Target", column => column.WithLength(LinkFieldIndex.MaxTargetSize))
.Column<bool>("Published", column => column.Nullable())
.Column<bool>("Latest", column => column.Nullable())
.Column<string>("Url", column => column.Nullable().WithLength(LinkFieldIndex.MaxUrlSize))
Expand Down Expand Up @@ -434,7 +435,7 @@ await SchemaBuilder.AlterIndexTableAsync<MultiTextFieldIndex>(table => table
);

// Shortcut other migration steps on new content definition schemas.
return 5;
return 6;
}

// This code can be removed in a later version.
Expand Down Expand Up @@ -807,5 +808,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;
}
}
}