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

fix: RichText retrieval bug #507

Merged
merged 1 commit into from
Feb 9, 2024
Merged
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
@@ -0,0 +1,39 @@
ALTER FUNCTION [Contentful].[SelectAllRichTextContentForPageSlug] (
@PageSlug NVARCHAR(MAX)
)
RETURNS @ReturnTable table(Id BIGINT, [Value] NVARCHAR(MAX), NodeType NVARCHAR(MAX), DataId BIGINT, ParentId BIGINT)
BEGIN
DECLARE @ContentComponentIds TABLE (Id NVARCHAR(MAX))
DECLARE @RichTextIds TABLE (Id bigint)

--Get content components for the page
INSERT INTO @ContentComponentIds
SELECT ISNULL(PC.BeforeContentComponentId, PC.ContentComponentId) AS ContentComponentId
FROM [Contentful].[PageContents] PC
LEFT JOIN [Contentful].[Pages] P ON PC.PageId = P.Id
WHERE P.Slug = @PageSlug

--Get rich text ids for text bodies and warnings
INSERT INTO @RichTextIds
SELECT DISTINCT TB.RichTextId
FROM [Contentful].[TextBodies] AS TB
JOIN @ContentComponentIds AS CC ON TB.Id = CC.Id
UNION
SELECT DISTINCT TB.RichTextId
FROM [Contentful].[Warnings] AS W
LEFT JOIN [Contentful].[TextBodies] AS TB ON W.TextId = TB.ID
JOIN @ContentComponentIds AS CC ON W.Id = CC.Id

--For each rich text id, execute the SelectAllRichTextContentForParentId function and add to the return table
DECLARE @idColumn BIGINT

SELECT @idColumn = min(Id) FROM @RichTextIds

WHILE @idColumn IS NOT NULL
BEGIN
INSERT INTO @ReturnTable SELECT [Id], [Value], [NodeType], [DataId], [ParentId] FROM [Contentful].[SelectAllRichTextContentForParentId](@idColumn)
SELECT @idColumn = min(Id) FROM @RichTextIds WHERE Id > @idColumn
END

RETURN
END
Loading