Fixed CopyItemAndChildren to support Grids, Images and DROUsages
Removed completed items from the ToDo List at the top of the file
This commit is contained in:
@@ -1972,7 +1972,14 @@ Join @Children NN on NN.NewContentID = CC.ContentID
|
||||
Join Contents CC2 on NN.ContentID = CC2.ContentID
|
||||
-- Contents are done
|
||||
-- SELECT * From Contents where DTS = @DTS and UserID = @UserID
|
||||
-- <<< Copy Items >>>
|
||||
-- <<< Copy Grids >>>
|
||||
INSERT INTO [Grids]([ContentID],[Data],[Config],[DTS],[UserID])
|
||||
SELECT NN.[NewContentID],[Data],[Config],@DTS,@UserID
|
||||
FROM [Grids] GG Join @Children NN on GG.ContentID = NN.ContentID
|
||||
-- <<< Copy Images >>>
|
||||
INSERT INTO [Images]([ContentID],[ImageType],[FileName],[Data],[Config],[DTS],[UserID])
|
||||
SELECT NN.[NewContentID],[ImageType],[FileName],[Data],[Config],@DTS,@UserID
|
||||
FROM [Images] II Join @Children NN on II.ContentID = NN.ContentID
|
||||
-- Create new item rows based upon the current item rows and the @Children table, with the NewContentIDs
|
||||
INSERT INTO [Items] ([PreviousID],[ContentID],[DTS],[UserID])
|
||||
SELECT II.[PreviousID], -- Leave the PreviousID as is for now
|
||||
@@ -2040,6 +2047,12 @@ INSERT INTO [Entries] ([ContentID],[DocID],[DTS],[UserID])
|
||||
SELECT NN.[NewContentID],ND.[NewDocID],@DTS,@UserID
|
||||
FROM [Entries] EE JOIN @Children NN on NN.ContentID = EE.ContentID
|
||||
JOIN @NewDocuments ND on EE.[DocID] = ND.[DocID]
|
||||
-- Logic to Create DROUsages for these newly created documents
|
||||
INSERT INTO [VEPROMS].[dbo].[DROUsages] ([DocID],[ROID],[Config],[DTS],[UserID],[RODbID])
|
||||
SELECT ND.[NewDocID],[ROID],[Config],@DTS,@UserID,[RODbID]
|
||||
FROM [DROUsages] RR
|
||||
JOIN @NewDocuments ND on RR.[DocID] = ND.[DocID]
|
||||
|
||||
-- Entries are done
|
||||
-- SELECT * From Entries EE JOIN Documents DD on ee.DocID = DD.DocID where EE.DTS = @DTS and EE.UserID = @UserID
|
||||
-- <<< Copy RoUsages >>>
|
||||
@@ -2051,7 +2064,7 @@ DECLARE @RowsAffected int
|
||||
SET @RowsAffected=1
|
||||
WHILE @RowsAffected > 0
|
||||
BEGIN
|
||||
UPDATE CC SET [TEXT] = C2.NewText
|
||||
UPDATE CC SET [TEXT] = C2.NewText
|
||||
FROM CONTENTS CC
|
||||
JOIN (SELECT C1.ContentID, .dbo.vefn_FixROText(C1.Text, CAST([ROID] as int), [ROUsageID]) NewText
|
||||
FROM CONTENTS C1
|
||||
@@ -2060,6 +2073,19 @@ UPDATE CC SET [TEXT] = C2.NewText
|
||||
WHERE [TEXT] <> C2.NewText
|
||||
SET @RowsAffected = @@RowCount
|
||||
END
|
||||
-- Update grid records for newly copied records to use correct RO usage ids in the RO tags
|
||||
SET @RowsAffected=1
|
||||
WHILE @RowsAffected > 0
|
||||
BEGIN
|
||||
UPDATE GG SET [Data] = G2.NewData
|
||||
FROM GRIDS GG
|
||||
JOIN (SELECT G1.ContentID, .dbo.vefn_FixROData(G1.Data, CAST([ROID] as int), [ROUsageID]) NewData
|
||||
FROM GRIDS G1
|
||||
JOIN @Children NN on G1.ContentID = NN.NewContentID
|
||||
JOIN RoUsages RO on NN.NewContentID = RO.ContentID) G2 ON GG.ContentID = G2.ContentID
|
||||
WHERE Cast([Data] as varchar(max)) <> cast(G2.NewData as varchar(max))
|
||||
SET @RowsAffected = @@RowCount
|
||||
END
|
||||
UPDATE RON SET [ROID] = ROO.[ROID]
|
||||
FROM RoUsages RON
|
||||
JOIN @Children NN on RON.ContentID = NN.NewContentID
|
||||
@@ -2103,6 +2129,20 @@ UPDATE CC SET [TEXT] = C2.NewText
|
||||
WHERE [TEXT] <> C2.NewText
|
||||
SET @RowsAffected = @@RowCount
|
||||
END
|
||||
-- -- Update grid records for newly copied records to use correct TransitionIDs in the Transition tags
|
||||
SET @RowsAffected=1
|
||||
WHILE @RowsAffected > 0
|
||||
BEGIN
|
||||
UPDATE GG SET [DATA] = G2.NewData
|
||||
FROM GRIDS GG
|
||||
JOIN (SELECT G1.ContentID, .dbo.vefn_FixTransitionDataForCopy(G1.Data, TRO.TransitionID, TRO.TranType, TRO.[ToID], TRO.[RangeID],TR.[TransitionID], TR.[ToID], TR.[RangeID], .dbo.vefn_GetNewTranType(NN.FormatID, NN.NewFormatID, TRO.TranType)) NewData
|
||||
FROM GRIDS G1
|
||||
JOIN @Children NN on G1.ContentID = NN.NewContentID
|
||||
JOIN Transitions TR on NN.NewContentID = TR.FromID
|
||||
JOIN Transitions TRO on TR.TranType = TRO.TransitionID) G2 ON GG.ContentID = G2.ContentID
|
||||
WHERE Cast([DATA] as varchar(max)) <> CAST(G2.NewData as varchar(max))
|
||||
SET @RowsAffected = @@RowCount
|
||||
END
|
||||
-- Add 'Verification Required' AnnotationType
|
||||
DECLARE @typeID int
|
||||
SELECT @typeID = TypeID from AnnotationTypes where Name = 'Verification Required'
|
||||
@@ -12729,6 +12769,30 @@ IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_FirstLink Succeeded'
|
||||
ELSE PRINT 'ScalarFunction Creation: vefn_FirstLink Error on Creation'
|
||||
GO
|
||||
|
||||
/****** Object: StoredProcedure [vefn_FixROData] ******/
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FixROData]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
|
||||
DROP FUNCTION [vefn_FixROData];
|
||||
GO
|
||||
|
||||
Create FUNCTION [dbo].[vefn_FixROData]
|
||||
(@data XML,@ROUsageID int,@NewROUsageID int)
|
||||
RETURNS XML
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN
|
||||
-- Build Search String and Replace String
|
||||
DECLARE @lookFor varchar(MAX)
|
||||
DECLARE @replaceWith varchar(MAX)
|
||||
SET @lookFor = '#Link:ReferencedObject:' + ltrim(str(@ROUsageID)) + ' '
|
||||
SET @replaceWith = '#Link:ReferencedObject:' + ltrim(str(@NewROUsageID)) + ' '
|
||||
return CAST(replace(CAST(@data AS VarChar(max)),@lookFor,@replaceWith) AS XML)
|
||||
END
|
||||
GO
|
||||
-- Display the status of Proc creation
|
||||
IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_FixROData Succeeded'
|
||||
ELSE PRINT 'ScalarFunction Creation: vefn_FixROData Error on Creation'
|
||||
GO
|
||||
|
||||
/****** Object: StoredProcedure [vefn_FixROText] ******/
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FixROText]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
|
||||
DROP FUNCTION [vefn_FixROText];
|
||||
@@ -12804,6 +12868,49 @@ IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_FixSearchString Succeeded'
|
||||
ELSE PRINT 'ScalarFunction Creation: vefn_FixSearchString Error on Creation'
|
||||
GO
|
||||
|
||||
/****** Object: StoredProcedure [vefn_FixTransitionDataForCopy] ******/
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FixTransitionDataForCopy]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
|
||||
DROP FUNCTION [vefn_FixTransitionDataForCopy];
|
||||
GO
|
||||
|
||||
CREATE FUNCTION [dbo].[vefn_FixTransitionDataForCopy]
|
||||
(@data XML,@TransitionID int,@TranType int,@OldToID int,@OldRangeID int, @NewID int, @NewToID int, @NewRangeID int, @NewTranType int)
|
||||
RETURNS XML
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN
|
||||
|
||||
-- Build Search String and Replace String
|
||||
DECLARE @offset int
|
||||
DECLARE @lookFor varchar(MAX)
|
||||
DECLARE @replaceWith varchar(MAX)
|
||||
DECLARE @text varchar(MAX)
|
||||
SET @text = Cast(@data as varchar(max))
|
||||
SET @lookFor = '#Link:Transition:' + ltrim(str(@TranType)) + ' ' + ltrim(str(@TransitionID))
|
||||
SET @offset = CHARINDEX(@lookFor,@text)
|
||||
if(@offset = 0)
|
||||
BEGIN
|
||||
|
||||
SET @lookFor = '#Link:TransitionRange:' + ltrim(str(@TranType)) + ' ' + ltrim(str(@TransitionID))
|
||||
SET @offset = CHARINDEX(@lookFor,@text)
|
||||
SET @replaceWith = '#Link:TransitionRange:' + ltrim(str(@NewTranType)) + ' ' + ltrim(str(@NewID))
|
||||
+ ' ' + ltrim(str(@NewToID)) + ' ' + ltrim(str(@NewRangeID))
|
||||
SET @lookFor = @lookFor + ' ' + ltrim(str(@OldToID)) + ' ' + ltrim(str(@OldRangeID))
|
||||
END
|
||||
ELSE
|
||||
BEGIN
|
||||
SET @replaceWith = '#Link:Transition:' + ltrim(str(@NewTranType)) + ' ' + ltrim(str(@NewID))
|
||||
+ ' ' + ltrim(str(@NewToID))
|
||||
SET @lookFor = @lookFor + ' ' + ltrim(str(@OldToID))
|
||||
END
|
||||
return Cast(replace(@text,@lookFor,@replaceWith) as XML)
|
||||
END
|
||||
GO
|
||||
-- Display the status of Proc creation
|
||||
IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_FixTransitionDataForCopy Succeeded'
|
||||
ELSE PRINT 'ScalarFunction Creation: vefn_FixTransitionDataForCopy Error on Creation'
|
||||
GO
|
||||
|
||||
/****** Object: StoredProcedure [vefn_FixTransitionText] ******/
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FixTransitionText]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
|
||||
DROP FUNCTION [vefn_FixTransitionText];
|
||||
|
Reference in New Issue
Block a user