Skip to content

Commit 62a3cd9

Browse files
Merge pull request #537 from TechnologyEnhancedLearning/Develop/Fixes/TD-4394-Publishing-catalogues-needs-to-update-referencing-catalogues
TD-4394: Publishing catalogues needs to update referencing catalogues
2 parents b93cb47 + 4d78bfc commit 62a3cd9

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@
543543
<Build Include="Stored Procedures\Resources\GetScormContentServerDetailsForLHExternalReference.sql" />
544544
<None Include="Scripts\Post-Deploy\Scripts\Content_Referencing_DataSetup.sql" />
545545
<None Include="Scripts\Pre-Deploy\Scripts\Content Referencing Initialise.sql" />
546+
<Build Include="Stored Procedures\Hierarchy\HierarchyNewNodePathForReferedCatalogue.sql" />
546547
<Build Include="Stored Procedures\Hierarchy\CheckCatalogueHasExternalReference.sql" />
547548
<Build Include="Stored Procedures\Hierarchy\HierarchyEditDeleteNodeReferenceDetails.sql" />
548549
<Build Include="Stored Procedures\Hierarchy\HierarchyEditDeleteResourceReferenceDetails.sql" />

WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditPublish.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
-- 03-06-2024 DB Publish NodePathDisplayVersion records.
1919
-- 13-06-2024 DB Publish ResourceReferenceDisplayVersion records.
2020
-- 26-07-2024 SA Remove references to be implemented
21+
-- 21-08-2024 SS Publishing catalogues needs to update referencing catalogues
2122
-- 27-08-2024 SA Moving a folder into a referenced folder should affect all instances of the referenced folder.[added
2223
-- condition to avoid duplicate entries in to NodeLink table]
2324
-- 02-09-2024 DB Remove any deleted NodePathDisplayVersion anf ResourceReferenceDisplayVersion records.
@@ -560,7 +561,11 @@ BEGIN
560561
AND np.CatalogueNodeId != np.NodeId
561562
AND hed.NodeId IS NULL
562563

564+
----------------------------------------------------------
565+
-- NodePath: generate new NodePath/s for refered Catalogues
566+
----------------------------------------------------------
563567

568+
EXEC [hierarchy].[HierarchyNewNodePathForReferedCatalogue] @HierarchyEditId,@AmendUserId,@AmendDate
564569
----------------------------------------------------------
565570
-- NodePathNode
566571
----------------------------------------------------------
@@ -576,7 +581,7 @@ BEGIN
576581
SET @NodePathCursor = CURSOR FORWARD_ONLY FOR
577582
SELECT NodePathId, NodeId, ParentNodeId, InitialNodePath, NewNodePath, HierarchyEditDetailOperationId
578583
FROM hierarchy.HierarchyEditDetail
579-
WHERE HierarchyEditId = 80
584+
WHERE HierarchyEditId = @HierarchyEditId
580585
AND ISNULL(InitialNodePath, '') != ISNULL(NewNodePath, InitialNodePath)
581586
AND (
582587
HierarchyEditDetailTypeId = 4 -- Node Link
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
-------------------------------------------------------------------------------
2+
-- Author Sarathlal
3+
-- Created 21-08-2024
4+
-- Purpose Publishing catalogues needs to update referencing catalogues
5+
--
6+
-- Modification History
7+
-- 21-08-2024 SS Initial version
8+
-------------------------------------------------------------------------------
9+
CREATE PROCEDURE [hierarchy].[HierarchyNewNodePathForReferedCatalogue]
10+
(
11+
@HierarchyEditId INT,
12+
@AmendUserId INT,
13+
@AmendDate datetimeoffset(7)
14+
)
15+
16+
AS
17+
18+
BEGIN
19+
BEGIN TRY
20+
21+
BEGIN TRAN
22+
DECLARE @NodePathId int
23+
DECLARE @PrimaryCatalogueNodeId int
24+
DECLARE @NodeId int
25+
DECLARE @ParentNodeId int
26+
DECLARE @NewNodePath as NVARCHAR(256)
27+
DECLARE @DisplayOrder int
28+
DECLARE @NewNodePathCursor as CURSOR
29+
SET @NewNodePathCursor = CURSOR FORWARD_ONLY FOR
30+
SELECT
31+
PrimaryCatalogueNodeId,
32+
ParentNodeId,
33+
NodeId,
34+
hed.NewNodePath,
35+
DisplayOrder,
36+
NodePathId
37+
FROM
38+
hierarchy.HierarchyEditDetail hed
39+
WHERE
40+
HierarchyEditId = @HierarchyEditId
41+
AND
42+
(
43+
HierarchyEditDetailTypeId = 4 -- Node Link
44+
OR
45+
HierarchyEditDetailTypeId = 3 -- Folder Node
46+
)
47+
AND (
48+
HierarchyEditDetailOperationId = 1 -- Add
49+
OR
50+
HierarchyEditDetailOperationId = 2 -- Edit
51+
)
52+
AND NodeLinkId IS NULL
53+
AND [Deleted] = 0
54+
OPEN @NewNodePathCursor;
55+
FETCH NEXT FROM @NewNodePathCursor INTO @PrimaryCatalogueNodeId,@ParentNodeId,@NodeId,@NewNodePath,@DisplayOrder,@NodePathId;
56+
WHILE @@FETCH_STATUS = 0
57+
BEGIN
58+
IF NOT EXISTS (SELECT 1 FROM hierarchy.NodePath WHERE NodeId=@NodeId AND NodePath=NodePath+'\'+CAST(@NodeId AS VARCHAR(100)))
59+
BEGIN
60+
INSERT INTO hierarchy.NodePath (NodeId, NodePath, CatalogueNodeId, IsActive, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate)
61+
SELECT @NodeId,NP.NodePath+'\'+CAST(@NodeId AS VARCHAR(100)),NP.CatalogueNodeId,1,0,@AmendUserId,@AmendDate,@AmendUserId,@AmendDate FROM
62+
hub.[fn_Split](@NewNodePath, '\') nodeInPath
63+
INNER JOIN hierarchy.NodePath NP ON NP.NodeId=nodeInPath.value AND CatalogueNodeId!=@PrimaryCatalogueNodeId
64+
WHERE nodeInPath.value=@ParentNodeId
65+
66+
END
67+
68+
69+
FETCH NEXT FROM @NewNodePathCursor INTO @PrimaryCatalogueNodeId,@ParentNodeId,@NodeId,@NewNodePath,@DisplayOrder,@NodePathId;
70+
71+
END
72+
73+
CLOSE @NewNodePathCursor;
74+
DEALLOCATE @NewNodePathCursor;
75+
COMMIT
76+
77+
END TRY
78+
BEGIN CATCH
79+
DECLARE @ErrorMessage NVARCHAR(4000);
80+
DECLARE @ErrorSeverity INT;
81+
DECLARE @ErrorState INT;
82+
83+
SELECT
84+
@ErrorMessage = ERROR_MESSAGE(),
85+
@ErrorSeverity = ERROR_SEVERITY(),
86+
@ErrorState = ERROR_STATE();
87+
88+
IF @@TRANCOUNT > 0
89+
ROLLBACK TRAN;
90+
91+
RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState);
92+
93+
END CATCH
94+
END
95+
GO

0 commit comments

Comments
 (0)