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

Fixed ContainedPartIndex behavior for DisplayText over 255 chars long #16738

Merged
merged 4 commits into from
Sep 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace OrchardCore.Lists.Indexes;

public class ContainedPartIndex : MapIndex
{
public const int MaxDisplayTextSize = 255;

public string ListContentItemId { get; set; }

public int Order { get; set; }
Expand Down Expand Up @@ -40,16 +42,26 @@ public override void Describe(DescribeContext<ContentItem> context)
return null;
}

return new ContainedPartIndex
var containedPartIndex = new ContainedPartIndex
{
ContentItemId = contentItem.ContentItemId,
ListContentType = containedPart.ListContentType,
ListContentItemId = containedPart.ListContentItemId,
Order = containedPart.Order,
Published = contentItem.Published,
Latest = contentItem.Latest,
DisplayText = contentItem.DisplayText,
};

if (containedPartIndex.DisplayText?.Length > ContainedPartIndex.MaxDisplayTextSize)
{
containedPartIndex.DisplayText = contentItem.DisplayText[..ContainedPartIndex.MaxDisplayTextSize];
}
else
{
containedPartIndex.DisplayText = contentItem.DisplayText;
}

return containedPartIndex;
});
}
}
4 changes: 2 additions & 2 deletions src/OrchardCore.Modules/OrchardCore.Lists/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ await _contentDefinitionManager.AlterPartDefinitionAsync("ListPart", builder =>
await SchemaBuilder.CreateMapIndexTableAsync<ContainedPartIndex>(table => table
.Column<string>("ContentItemId", column => column.WithLength(26))
.Column<string>("ListContentItemId", column => column.WithLength(26))
.Column<string>("DisplayText")
.Column<string>("DisplayText", column => column.WithLength(ContainedPartIndex.MaxDisplayTextSize))
.Column<int>("Order")
.Column<string>("ListContentType")
.Column<bool>("Published")
Expand Down Expand Up @@ -84,7 +84,7 @@ await SchemaBuilder.AlterIndexTableAsync<ContainedPartIndex>(table => table
);

await SchemaBuilder.AlterIndexTableAsync<ContainedPartIndex>(table => table
.AddColumn<string>("DisplayText")
.AddColumn<string>("DisplayText", column => column.WithLength(ContainedPartIndex.MaxDisplayTextSize))
);

await SchemaBuilder.AlterIndexTableAsync<ContainedPartIndex>(table => table
Expand Down