home *** CD-ROM | disk | FTP | other *** search
/ gimli.bioss.sari.ac.uk / gimli.bioss.sari.ac.uk.zip / gimli.bioss.sari.ac.uk / pub / misc / McAfee8.7.Zip / ePOPolicyMigration.exe / CABFILE / 1 / 71To87_Task_Upgrade_Script.sql < prev    next >
Text File  |  2007-12-17  |  11KB  |  359 lines

  1. -------------------------------------------------------------------------------
  2.  
  3. -------------  V S E  7 . 1  T O  8 . 7  T A S K  U P G R A D E  --------------
  4.  
  5. -------------------------------------------------------------------------------
  6.  
  7. if exists (select * from tempdb..sysobjects where name like '#VseTmpUpgradeTask%')
  8. drop table #VseTmpUpgradeTask
  9. go
  10.  
  11. CREATE TABLE [dbo].[#VseTmpUpgradeTask] (
  12.     [AutoID] [int] IDENTITY (1, 1) NOT NULL ,
  13.     [ParentType] [tinyint] NOT NULL ,
  14.     [ParentID] [int] NOT NULL ,
  15.     [GlobalTaskID] [int] NOT NULL ,
  16.     [TaskStatus] [tinyint] NULL ,
  17.     [TheTimestamp] [binary] (8) NULL ,
  18.     [ProductCode] [nvarchar] (50) NULL ,
  19.     [DeleteTimestamp] [binary] (8) NULL ,
  20.     [TaskType] [nvarchar] (50) NULL ,
  21.     [TaskName] [nvarchar] (150) NULL ,
  22.     [PlatformsSupported] [nvarchar] (250) NULL ,
  23.     [JustPlaceHolder] [bit] NULL ,
  24.     [Priority] [int] NULL,
  25.     [VSE87AutoID] [int],        -- must link VSE 8.7 autoid
  26.     [VSE71AutoID] [int]            -- with VSE 7.1 autoid
  27. )
  28. go
  29.  
  30. declare @Continue int
  31. declare @DoNotForce71 nvarchar(30)
  32. declare @DoNotForce nvarchar(30)
  33.     
  34. select @Continue = 1
  35. select @DoNotForce71 = 'DO_NOT_FORCE_71'
  36. select @DoNotForce = 'DO_NOT_FORCE_%'
  37.  
  38. -- Don't copy any tasks if 8.0, 8.5 or 8.7 tasks already exist
  39. if exists (select * from Task where ProductCode = 'VIRUSCAN8700' and ParentType = 7 and GlobalTaskID > 0)
  40. begin
  41.     select @Continue = 0
  42. end
  43.  
  44. if @DoNotForce71 like @DoNotForce
  45. begin
  46.     if exists (select * from Task where ProductCode = 'VIRUSCAN8600' and ParentType = 7 and GlobalTaskID > 0)
  47.     begin
  48.         select @Continue = 0
  49.     end
  50.     if exists (select * from Task where ProductCode = 'VIRUSCAN8000' and ParentType = 7 and GlobalTaskID > 0)
  51.     begin
  52.         select @Continue = 0
  53.     end
  54. end
  55.  
  56. if @Continue = 1
  57. begin
  58.  
  59. -- Convert VSE7.1 tasks
  60. -- Copy over all task data and relink globaltaskid field
  61. -- Must copy over task and policies not just move them
  62. -- Copy all non global Task table 7.1 policies to 8.7 policies
  63. -- Copy over global root tasks, but only those with GlobalTaskID > 0
  64.  
  65. -- copy all VSE 7.1 tasks
  66. insert #VseTmpUpgradeTask
  67. (ParentType, ParentID, GlobalTaskID, TaskStatus, TheTimestamp, ProductCode, DeleteTimestamp,
  68.     TaskType, TaskName, PlatformsSupported, JustPlaceHolder, Priority, VSE87AutoID, VSE71AutoID)
  69. select 
  70. ParentType, ParentID, GlobalTaskID, TaskStatus, TheTimestamp, 'VIRUSCAN8700' as ProductCode, DeleteTimestamp,
  71.     TaskType, TaskName, PlatformsSupported, JustPlaceHolder, Priority, 0 as VSE87AutoID, autoid as VSE71AutoID
  72. from Task
  73. where
  74. Task.ProductCode = 'VIRUSCAN7100'
  75. and 
  76. (
  77. ParentType in (6,5,4,3,1)
  78. or
  79. (ParentType = 7 and GlobalTaskID > 0 )
  80. )
  81. and Task.TaskType = 'VSC700_Scan_Task'
  82. order by autoid
  83.  
  84. -- Find next task autoid value
  85. Declare @NextTaskid int
  86. Select @NextTaskid = IDENT_CURRENT('Task')
  87.  
  88. -- populate VSE87AutoID field in #VseTmpUpgradeTask
  89. Update #VseTmpUpgradeTask
  90. set VSE87AutoID = @NextTaskid + autoid
  91.  
  92. -- create VSE 8.7 tasks
  93. insert Task
  94. (ParentType, ParentID, GlobalTaskID, TaskStatus, TheTimestamp, ProductCode, DeleteTimestamp,
  95.     TaskType, TaskName, PlatformsSupported, JustPlaceHolder, Priority)
  96. select 
  97. ParentType, ParentID, GlobalTaskID, TaskStatus, TheTimestamp, 'VIRUSCAN8700' as ProductCode, DeleteTimestamp,
  98.     TaskType, TaskName + ' (VSE 8.7i)', PlatformsSupported, JustPlaceHolder, Priority
  99. from #VseTmpUpgradeTask
  100. order by autoid
  101.  
  102. -- Update GlobalTaskID field, link it to VSE 8.7 task instead of VSE 7.1 task
  103. update Task
  104. Set GlobalTaskID = VSE87AutoID
  105. From #VseTmpUpgradeTask
  106. where
  107. Task.GlobalTaskID = #VseTmpUpgradeTask.VSE71AutoID
  108. and Task.ProductCode = 'VIRUSCAN8700'
  109. and 
  110. (
  111. Task.ParentType in (6,5,4,3,1)
  112. or
  113. (Task.ParentType = 7 and Task.GlobalTaskID > 0 )
  114. )
  115. and Task.TaskType = 'VSC700_Scan_Task'
  116.  
  117. -- Update the GlobalTaskID for global root tasks, 
  118. -- (but only for those with with GlobalTaskID > 0)
  119. Declare @Root71Taskid int
  120. Select @Root71Taskid = AutoId
  121. From Task
  122. where ParentType = 7
  123. and GlobalTaskID = 0
  124. and ProductCode = 'VIRUSCAN7100'
  125. and TaskType = 'VSC700_Scan_Task'
  126.  
  127. Declare @Root87Taskid int
  128. Select @Root87Taskid = AutoId
  129. From Task
  130. where ParentType = 7
  131. and GlobalTaskID = 0
  132. and ProductCode = 'VIRUSCAN8700'
  133. and TaskType = 'VSC700_Scan_Task'
  134.  
  135. update Task
  136. Set GlobalTaskID = @Root87Taskid
  137. where
  138. Task.ProductCode = 'VIRUSCAN8700'
  139. and GlobalTaskID = @Root71Taskid
  140. and 
  141. (
  142. ParentType in (6,5,4,3,1)
  143. or
  144. (ParentType = 7 and GlobalTaskID > 0 )
  145. )
  146. and TaskType = 'VSC700_Scan_Task'
  147.  
  148. -- copy VSE 7.1 tasksettings to VSE 8.7 task settings
  149. -- Copy all non global TaskSetting from 7.1 Task settings to 8.7 Task settings
  150. -- copy only settings where GlobalTaskID > 0
  151. -- Change parentid to point to the VSE 8.7 task
  152. insert TaskSettings
  153. (ParentID, SectionName, SettingName, Value, TheTimestamp)
  154. select VSE87AutoID, SectionName, SettingName, Value, TaskSettings.TheTimestamp
  155. from TaskSettings, #VseTmpUpgradeTask
  156. where
  157. TaskSettings.ParentID = #VseTmpUpgradeTask.VSE71AutoID
  158.  
  159. /* ----------------------------------------------------------------------------
  160.  Change the SectionName and/or the SettingName of the policies that have moved.
  161.  A "-" sign indicates that the value is no longer used and is to be deleted only.
  162.  
  163. OLD VALUE:                                                        NEW VALUE:
  164. [Actions]                                                        [Actions]
  165. uAction                                        = 3    (Move)        =>  = 4 (Delete)
  166. uSecAction                                                    =>  = 1 (Continue)
  167.  
  168. [Actions]                                                        [Actions]
  169. uAction                                        = 5    (Clean)
  170. uSecAction                                    = 3    (Move)        =>  = 4 (Delete)
  171.  
  172. [Actions]                                                        [Actions]
  173. uAction                                        = 4    (Delete)
  174. uSecAction                                    = 3    (Move)        =>  = 1 (Continue)
  175.  
  176. [Actions]                                                        
  177. -szMoveToFolder
  178. -szSecMoveToFolder
  179.  
  180. [Reports]                                                
  181. -bLogUsername
  182. ----------------------------------------------------------------------------- */
  183.  
  184. /* ----------------------------------------------------------------------------
  185. [Actions]                                                        [Actions]
  186. uAction                                        = 3    (Move)        =>  = 4 (Delete)
  187. uSecAction                                                    =>  = 1 (Continue)
  188. ---------------------------------------------------------------------------- */
  189. update TaskSettings
  190. set Value = '1'
  191. where
  192. SectionName = 'Actions'
  193. and SettingName = 'uSecAction'
  194. and TaskSettings.parentid in 
  195.     (select b.parentid
  196.     from #VseTmpUpgradeTask, TaskSettings b
  197.     where
  198.     b.ParentID = #VseTmpUpgradeTask.VSE87AutoID
  199.     and b.SectionName = 'Actions'
  200.     and b.SettingName = 'uAction'
  201.     and b.Value = '3'
  202.     )
  203.  
  204. update TaskSettings
  205. set Value = '4'
  206. where
  207. SectionName = 'Actions'
  208. and SettingName = 'uAction'
  209. and TaskSettings.parentid in 
  210.     (select b.parentid
  211.     from #VseTmpUpgradeTask, TaskSettings b
  212.     where
  213.     b.ParentID = #VseTmpUpgradeTask.VSE87AutoID
  214.     and b.SectionName = 'Actions'
  215.     and b.SettingName = 'uAction'
  216.     and b.Value = '3'
  217.     )
  218.  
  219. /* ----------------------------------------------------------------------------
  220. [Actions]                                                        [Actions]
  221. uAction                                        = 5 (Clean)
  222. uSecAction                                    = 3    (Move)        =>  = 4 (Delete)
  223. ---------------------------------------------------------------------------- */
  224. update TaskSettings
  225. set Value = '4'
  226. where
  227. SectionName = 'Actions'
  228. and SettingName = 'uSecAction'
  229. and TaskSettings.parentid in 
  230.     (select b.parentid
  231.     from #VseTmpUpgradeTask, TaskSettings b, TaskSettings c
  232.     where
  233.     b.ParentID = #VseTmpUpgradeTask.VSE87AutoID
  234.     and b.SectionName = 'Actions'
  235.     and b.SettingName = 'uAction'
  236.     and b.Value = '5'
  237.     and b.ParentID = c.ParentID
  238.     and c.SectionName = 'Actions'
  239.     and c.SettingName = 'uSecAction'
  240.     and c.Value = '3'
  241.     )
  242.  
  243. /* ----------------------------------------------------------------------------
  244. [Actions]                                                        [Actions]
  245. uAction                                        = 4    (Delete)
  246. uSecAction                                    = 3    (Move)        =>  = 1 (Continue)
  247. ---------------------------------------------------------------------------- */
  248. update TaskSettings
  249. set Value = '1'
  250. where
  251. SectionName = 'Actions'
  252. and SettingName = 'uSecAction'
  253. and TaskSettings.parentid in 
  254.     (select b.parentid
  255.     from #VseTmpUpgradeTask, TaskSettings b, TaskSettings c
  256.     where
  257.     b.ParentID = #VseTmpUpgradeTask.VSE87AutoID
  258.     and b.SectionName = 'Actions'
  259.     and b.SettingName = 'uAction'
  260.     and b.Value = '4'
  261.     and b.ParentID = c.ParentID
  262.     and c.SectionName = 'Actions'
  263.     and c.SettingName = 'uSecAction'
  264.     and c.Value = '3'
  265.     )
  266.  
  267. /* ----------------------------------------------------------------------------
  268. [Actions]                                                        
  269. -szMoveToFolder
  270. -szSecMoveToFolder
  271. ---------------------------------------------------------------------------- */
  272. delete TaskSettings 
  273. where 
  274. TaskSettings.SectionName = 'Actions'
  275. and TaskSettings.SettingName = 'szMoveToFolder'
  276. and TaskSettings.parentid in 
  277.     (select b.parentid
  278.     from #VseTmpUpgradeTask, TaskSettings b
  279.     where
  280.     b.ParentID = #VseTmpUpgradeTask.VSE87AutoID
  281.     )
  282.  
  283. delete TaskSettings 
  284. where 
  285. TaskSettings.SectionName = 'Actions'
  286. and TaskSettings.SettingName = 'szSecMoveToFolder'
  287. and TaskSettings.parentid in 
  288.     (select b.parentid
  289.     from #VseTmpUpgradeTask, TaskSettings b
  290.     where
  291.     b.ParentID = #VseTmpUpgradeTask.VSE87AutoID
  292.     )
  293.  
  294. /* ----------------------------------------------------------------------------
  295. [Reports]                                                
  296. -bLogUsername
  297. ---------------------------------------------------------------------------- */
  298. delete TaskSettings 
  299. where 
  300. TaskSettings.SectionName = 'Reports'
  301. and TaskSettings.SettingName = 'bLogUsername'
  302. and TaskSettings.parentid in 
  303.     (select b.parentid
  304.     from #VseTmpUpgradeTask, TaskSettings b
  305.     where
  306.     b.ParentID = #VseTmpUpgradeTask.VSE87AutoID
  307.     )
  308. end
  309. go
  310.  
  311. if exists (select * from tempdb..sysobjects where name like '#VseTmpUpgradeTask%')
  312. drop table #VseTmpUpgradeTask
  313. go
  314.  
  315. /* ----------------------------------------------------------------------------
  316. Update the task timestamps
  317. ---------------------------------------------------------------------------- */
  318. if exists (select * from tempdb..sysobjects where name like '#vsetasktime%')
  319. drop table #vsetasktime
  320. go
  321.  
  322. begin
  323. -- Update the timestamps so that the agents know there are new tasks
  324. declare @Currenttime int
  325. select @Currenttime = @@dbts
  326.  
  327. update task set TheTimestamp = @Currenttime
  328. where ProductCode = 'VIRUSCAN8700'
  329.  
  330. select parentid as autoid, parenttype, max(thetimestamp)as maxtime
  331. into #vsetasktime
  332. from task
  333. where ProductCode = 'VIRUSCAN8700'
  334. group by parentid, parenttype
  335.  
  336. update leafnode
  337. set tasktimestamp = #vsetasktime.maxtime + 1
  338. from #vsetasktime
  339. where leafnode.autoid = #vsetasktime.autoid
  340. and #vsetasktime.parenttype = leafnode.type
  341.  
  342. update branchnode
  343. set tasktimestamp = #vsetasktime.maxtime + 1
  344. from #vsetasktime
  345. where branchnode.autoid = #vsetasktime.autoid
  346. and #vsetasktime.parenttype = branchnode.type
  347.  
  348. update tasksettings set TheTimestamp = @Currenttime
  349. from task
  350. where tasksettings.parentid = task.autoid
  351. and task.ProductCode = 'VIRUSCAN8700'
  352.  
  353. end
  354. go
  355.  
  356. if exists (select * from tempdb..sysobjects where name like '#vsetasktime%')
  357. drop table #vsetasktime
  358. go
  359.