Skip to content
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 @@ -534,7 +534,7 @@
<Build Include="Tables\Resource\ScormResourceReferenceEvent.sql" />
<Build Include="Tables\Resource\ScormResourceReferenceEventType.sql" />
<None Include="Scripts\Post-Deploy\Scripts\UpdateFileTypes.sql" />
<Build Include="Triggers\external\AddDigitalLearningSolutionsExternalSystem.sql" />
<None Include="Scripts\Post-Deploy\Scripts\AddDigitalLearningSolutionsExternalSystem.sql" />
</ItemGroup>
<ItemGroup>
<None Include="Scripts\Pre-Deploy\Scripts\Card5766_AuthorTableChanges.PreDeployment.sql" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ END

UPDATE [resources].[ResourceVersion] SET CertificateEnabled = 0 WHERE VersionStatusId <> 1 AND CertificateEnabled IS NULL

-- do not delete the script AddDigitalLearningSolutionsExternalSystem
:r .\Scripts\AddDigitalLearningSolutionsExternalSystem.sql
:r .\Scripts\Bookmark.sql
:r .\Scripts\PopulateEventTypes.sql
:r .\Scripts\InternalSystem.sql
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

-------------------------------------------------------------------------------
-- Author Colin Beeby
-- Created 21-03-2024
-- Purpose Ensure that when a user is associated with external system DigitalLearningSolutionsSso, they are also associated with DigitalLearningSolutions
--
-- Modification History
--
-- 21-03-2024 ColB Initial Version
-- 15-11-2024 SA Modified the script to execute check if the trigger exists in the table schema
-------------------------------------------------------------------------------

-- Check if the trigger exists in the [external] schema and the [ExternalSystemUser] table
IF NOT EXISTS (SELECT * FROM sys.triggers WHERE name = 'InsertTrigger_AddDigitalLearningSolutionsExternalSystem' AND parent_id = OBJECT_ID('[external].[ExternalSystemUser]'))
BEGIN
-- Create the trigger if it doesn't exist
EXEC('
CREATE TRIGGER [external].InsertTrigger_AddDigitalLearningSolutionsExternalSystem
ON [external].[ExternalSystemUser]
FOR INSERT
AS
BEGIN
DECLARE @DigitalLearningSolutionsId INT;
DECLARE @DigitalLearningSolutionsSsoId INT;

-- Get the DigitalLearningSolutions ExternalSystemId
SELECT @DigitalLearningSolutionsId = id
FROM [external].[ExternalSystem]
WHERE code = ''DigitalLearningSolutions'';

-- Get the DigitalLearningSolutionsSso ExternalSystemId
SELECT @DigitalLearningSolutionsSsoId = id
FROM [external].[ExternalSystem]
WHERE code = ''DigitalLearningSolutionsSso'';

-- Check if the inserted row has ExternalSystemId matching DigitalLearningSolutionsSsoId
IF EXISTS (SELECT 1 FROM inserted WHERE ExternalSystemId = @DigitalLearningSolutionsSsoId)
BEGIN
-- Insert into ExternalSystemUser table
INSERT INTO [external].[ExternalSystemUser]
(UserId, ExternalSystemId, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate)
SELECT UserId, @DigitalLearningSolutionsId, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate
FROM inserted;
END
END;
');
END;
Loading