diff --git a/PROMS/DataLoader/PROMSFixes.Sql b/PROMS/DataLoader/PROMSFixes.Sql index 952ebf10..c5386327 100644 --- a/PROMS/DataLoader/PROMSFixes.Sql +++ b/PROMS/DataLoader/PROMSFixes.Sql @@ -9512,3 +9512,252 @@ GO IF (@@Error = 0) PRINT 'Procedure Creation: vesp_GetTransitionReportData Succeeded' ELSE PRINT 'Procedure Creation: vesp_GetTransitionReportData Error on Creation' GO + + +/****** Object: StoredProcedure [PasteItemChild] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[PasteItemChild]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [PasteItemChild]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2015 - Volian Enterprises, Inc. All rights reserved. + +Copies & Pastes into a level above the copied item, for example copied item is step pasted into a section. + +Example test: + +declare @NewItemID int +declare @dts datetime +set @newitemid = 0 +set @dts = getdate() +exec PasteItemChild 1493,484,20041,2,@dts,'KATHY',@NewItemID output + +*****************************************************************************/ + +CREATE PROCEDURE [dbo].[PasteItemChild] +( + @ItemID int=null, @StartItemID int=null, -- ItemID is destination, StartItemID is top of copy + @Type int=null, @FromType int=null, @DTS datetime, @UserID nvarchar(100), -- Type is step/section type for content record, fromtype is for parts + @NewItemID int output +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + if exists (select * from tblitems where itemid = @ItemID and DeleteStatus !=0) + BEGIN + RAISERROR ('###Cannot Paste Step###This current step has been deleted in another session',16,1) + RETURN + END + -- First make a copy of the input StartItemID + -- DestFormatID is the formatid for the destination parent's format + DECLARE @DestFormatID int + SET @DestFormatID = .dbo.vefn_GetInheritedFormat(@ItemID, 0) + EXECUTE CopyItemAndChildren @StartItemID, @DestFormatID, @UserID, @NewItemID OUTPUT + -- print 'testing PasteItemChild 1 ' + cast(dbo.ve_GetTransitionErrorCount() as varchar(20)) + DECLARE @ChildID int, @ContentID int, @ParentContentID int, @LastChanged timestamp + , @newLastChanged timestamp, @Error int, @Rowcount int, @ChildDeleted int + SELECT @ChildID = pp.[ItemID],@ParentContentID = ii.ContentID, @LastChanged = pp.LastChanged + FROM [ITEMS] ii + LEFT JOIN [PARTS] pp on pp.ContentID=ii.ContentID and pp.FromType=@FromType + WHERE ii.[ItemID]=@ItemID + IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[tblParts]') AND OBJECTPROPERTY(id,N'IsTable') = 1) + BEGIN + SELECT @ChildDeleted = pp.[ItemID],@ParentContentID = ii.ContentID, @LastChanged = pp.LastChanged + FROM [ITEMS] ii + LEFT JOIN [tblPARTS] pp on pp.ContentID=ii.ContentID and pp.FromType=@FromType + WHERE ii.[ItemID]=@ItemID and pp.DeleteStatus > 0 + END + -- No existing child - Add Parts record. Note that don't need to update any transition records if no existing children + IF @ChildID is null + BEGIN + IF @ChildDeleted is not null + DELETE FROM [tblParts] WHERE ItemID = @ChildDeleted + EXECUTE AddPart @ParentContentID, @FromType, @newItemID, @DTS, @UserID, @newLastChanged output + END + ELSE -- Children exist: Update existing Parts record and adjust transition records that may have pointed to 1st child. + BEGIN + EXECUTE UpdatePart @ParentContentID, @FromType, @newItemID, @DTS, @UserID, @LastChanged, @newLastChanged output + UPDATE [Items] SET [PreviousID]=@newItemID WHERE [ItemID]=@ChildID + + -- Update content records for the transitions, this only fixes the link portion. Code fixes the text. + Update CC + Set Text = DBO.vefn_FixTransitionText(Text,TT.TransitionID,TT.TranType,TT.ToID,TT.RangeID,@ChildID,@newItemID) + From CONTENTS CC + JOIN Transitions TT ON TT.FromID = CC.ContentID + WHERE TT.ToID = @ChildID OR TT.RangeID = @ChildID + -- Update transitions that pointed to @ItemID to point to @newItemID + Update TRANSITIONS + Set ToID = CASE ToID WHEN @ChildID THEN @newItemID ELSE ToID END, + RangeID = CASE RangeID WHEN @ChildID THEN @newItemID ELSE RangeID END + WHERE ToID = @ChildID OR RangeID = @ChildID + END + -- Add 'Verification Required' AnnotationType + DECLARE @typeID int + SELECT @typeID = TypeID from AnnotationTypes where Name = 'Verification Required' + IF(@typeID IS NULL) + BEGIN + INSERT INTO [AnnotationTypes] ([Name],[UserID]) VALUES ('Verification Required','Volian') + SELECT @typeID = SCOPE_IDENTITY() + END + -- Add "Verification Required" Annotation for each Transition that points to @newItemID or @NextID + -- I don't expect to see any transitions that point to @ChildID. They should have changed in + -- the update above to point to @newItemID. This is here for consistency with the other insert + -- stored procedures + INSERT INTO [Annotations] ([ItemID],[TypeID],[SearchText],[UserID]) + SELECT ItemID, @typeID,'Verify Transition Destination',@UserID + FROM Items where CONTENTID in (SELECT FromID FROM TRANSITIONS + where ToID IN(@ChildID,@newItemID) OR RangeID IN(@ChildID,@newItemID)) + -- Transition Text gets updated in ItemInsertExt.cs + IF( @@TRANCOUNT > 0 ) COMMIT + PRINT 'Child Added ' + ltrim(str(@newItemID)) + EXECUTE GetItem @newItemID + delete from itemaudits where itemid in (select itemid from vefn_ChildItems(@newitemid)) + delete from contentaudits where contentid in (select contentid from vefn_ChildItems(@newitemid)) +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: PasteItemChild Succeeded' +ELSE PRINT 'Procedure Creation: PasteItemChild Error on Creation' +GO + + +/****** Object: StoredProcedure [PasteDocVersionChild] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[PasteDocVersionChild]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [PasteDocVersionChild]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2014 - Volian Enterprises, Inc. All rights reserved. + +Copies & Pastes into a docversion that does NOT have any existing procedures. + +Example test: + +declare @NewItemID int +declare @dts datetime +set @newitemid = 0 +set @dts = getdate() +exec PasteDocVersionChild 5,30,@dts,'KATHY',@NewItemID output + +*****************************************************************************/ +CREATE PROCEDURE [dbo].[PasteDocVersionChild] +( + @VersionID int=null, @StartItemID int=null, -- VersionID is destination (docversion), StartItemID is top of copy (i.e. procedure) + @DTS datetime, @UserID nvarchar(100), + @ThisVersionID int output +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + if not exists (select * from DocVersions where versionid = @VersionID) + BEGIN + RAISERROR ('###Cannot Paste Procedure###This document version has been deleted in another session',16,1) + RETURN + END + -- First make a copy of the input StartItemID (Procedure) + -- DestFormatID is the formatid for the destination parent's format + DECLARE @NewItemID int + DECLARE @DestFormatID int + SET @ThisVersionID = @VersionID + SET @DestFormatID = .dbo.vefn_GetDocVersionInheritedFormat(@VersionID) + EXECUTE CopyItemAndChildren @StartItemID, @DestFormatID, @UserID, @NewItemID OUTPUT + UPDATE [DOCVERSIONS] SET [ItemID] = @NewItemID where [VersionID]=@VersionID + IF( @@TRANCOUNT > 0 ) COMMIT + PRINT 'Child Added ' + ltrim(str(@newItemID)) + EXECUTE GetDocVersion @ThisVersionID + delete from itemaudits where itemid in (select itemid from vefn_ChildItems(@newitemid)) + delete from contentaudits where contentid in (select contentid from vefn_ChildItems(@newitemid)) +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: PasteDocVersionChild Succeeded' +ELSE PRINT 'Procedure Creation: PasteDocVersionChild Error on Creation' +GO + + +/****** Object: StoredProcedure [vefn_GetDocVersionInheritedFormat] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_GetDocVersionInheritedFormat]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) + DROP FUNCTION [vefn_GetDocVersionInheritedFormat]; +GO + +CREATE FUNCTION [dbo].[vefn_GetDocVersionInheritedFormat] (@VersionID int) RETURNS int +WITH EXECUTE AS OWNER +AS +BEGIN +DECLARE @FormatID as int + -- First get format for the input doc version + begin + with Itemz([Level], [VersionID], [FolderID], [ParentID], [FormatID]) as ( + -- DocVersion From Item + select 0 [Level], DV.VersionID, DV.FolderID, null, DV.FormatID + from DocVersions DV + where [VersionID] = @VersionID + Union All + -- Folders + select [Level] + 1, null, FF.ParentID, FF.FolderID, FF.FormatID + from Itemz Z + join Folders FF on FF.FolderID = Z.ParentID and FF.ParentID <> FF.FolderID + where Z.FormatID is null + ) + Select @FormatID = FormatID from Itemz ZZ Where FormatID is not null + OPTION (MAXRECURSION 10000) + RETURN @FormatID + END +END +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_GetDocVersionInheritedFormat Succeeded' +ELSE PRINT 'ScalarFunction Creation: vefn_GetDocVersionInheritedFormat Error on Creation' +GO + +/*********the following funcion is for debugging copy/paste where transition text in content records does not get updated */ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[ve_GetTransitionErrorCount]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1) + DROP FUNCTION [ve_GetTransitionErrorCount]; +/****** Object: UserDefinedFunction [dbo].[vefn_ChronologyReport] Script Date: 03/20/2012 17:50:44 ******/ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +/* +select dbo.ve_GetTransitionErrorCount () +print 'testing ' + cast(dbo.ve_GetTransitionErrorCount() as varchar(20)) +*/ + +CREATE FUNCTION [dbo].[ve_GetTransitionErrorCount] () RETURNS int +WITH EXECUTE AS OWNER +AS +BEGIN +DECLARE @Count int +select @Count = count(*) from ( +select dbo.ve_GetShortPathFromContentId(contentid) location, * from ( +select contentid, text, tt.*, +case when text like '%'+ case when tt.toid = tt.rangeid and tt.IsRange = 0 +then +'#Link:Transition:' + cast(TranType as nvarchar(2)) + +' ' + cast(TransitionID as nvarchar(10)) + ' ' + cast(ToID as nvarchar(10)) + '%' +else +'#Link:TransitionRange:' + cast(TranType as nvarchar(2)) + +' ' + cast(TransitionID as nvarchar(10)) + ' ' + cast(ToID as nvarchar(10)) + ' ' + cast(RangeID as nvarchar(10))+ '%' +end then 'matches' else 'different' end ContentMatchesTrans, +case when text like '%'+ +'#Link:TransitionRange:' + cast(TranType as nvarchar(2)) + +' ' + cast(TransitionID as nvarchar(10)) + ' ' + cast(ToID as nvarchar(10)) + ' ' + cast(RangeID as nvarchar(10))+ '%' +then 'matches' else 'different' end ContentMatchesRangeTrans +from Contents cc +join transitions tt on tt.fromid = cc.contentid) mm +where ContentMatchesTrans = 'different') mm +return @Count END \ No newline at end of file