USE [site_fuchs] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocmd_merge_navigation] @newnav [dbo].[ocms_type_navigation_base] READONLY AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- update nav table UPDATE n SET n.[parent_iid] = i.[parent_iid] FROM [dbo].[ocms_navigation] as n JOIN [ocms_items] as i ON n.[ocms_iid] = i.[ocms_iid]; -- merge nav WITH np as ( -- make sure nav are allowed by locales and path constraints SELECT n.* ,i.[parent_iid] FROM @newnav as n JOIN [dbo].[ocms_items] as i ON n.[ocms_iid] = i.[ocms_iid] AND [view] = 1 FULL OUTER JOIN [dbo].[ocms_locales]() as l on n.[locale] = l.[locale] AND l.[locale] <> '*' WHERE NOT EXISTS (SELECT * FROM [dbo].[ocms_navigation] as cn WHERE cn.[parent_iid] = i.[parent_iid] AND cn.[alias] = n.[alias] AND [cn].[ocms_iid] <> n.[ocms_iid]) AND i.[name] <> 'index' -- nav not allowed for index AND n.[alias] not in ('index') -- keyword index not allowed ) MERGE [dbo].[ocms_navigation] as TARGET USING np as SOURCE ON TARGET.[locale] = SOURCE.[locale] AND TARGET.[ocms_iid] = SOURCE.[ocms_iid] WHEN MATCHED AND SOURCE.[alias] is null THEN DELETE WHEN MATCHED THEN UPDATE SET [alias] = LOWER(SOURCE.[alias]) WHEN NOT MATCHED BY TARGET THEN INSERT ([ocms_iid], [locale], [alias]) VALUES (SOURCE.[ocms_iid], SOURCE.[locale], LOWER(SOURCE.[alias])); END GO ALTER AUTHORIZATION ON [dbo].[ocmd_merge_navigation] TO SCHEMA OWNER GO