<!---
/*========================================================================================================================================
 
Name script: Update the LVersioning to 'File Versioning'
Fogbugz:RR-7 [.5] In Item Edit, rename "Versioning" to "File Versioning"
 
Description: This script will update the default value to the LVersioning on AppbuilderLanguage table.
 
Table: [dbo].[AppbuilderLanguage]
Field: [LVersioning] (New value = File Versioning)
========================================================================================================================================*/
--->

<cfif form.Type EQ "Patch">
        <cfinclude template="patch_14.0.05.cfm">
</cfif>


<cfquery datasource="#application.config.DSN#">
BEGIN

Declare @NameOfTable varchar(255), @NameOfField varchar(255), @NameOfConstraint varchar(255)

Set @NameOfTable = 'AppbuilderSettings'
Set @NameOfField = 'ArchiveItemDays'

/* take the constraint name */

SELECT @NameOfConstraint = OBJECT_NAME(cdefault)
  FROM dbo.syscolumns
 WHERE id = OBJECT_ID('AppbuilderSettings')
   AND name = 'ArchiveItemDays'


/* delete CONSTRAINT IF EXISTS */
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'D' AND name = @NameOfConstraint)
	EXEC('ALTER TABLE [dbo].[AppbuilderSettings] DROP CONSTRAINT [' + @NameOfConstraint + ']')

/* create CONSTRAINT*/
IF NOT EXISTS (SELECT * FROM sys.objects WHERE type = 'D' AND name = 'DF_AppbuilderSettings_ArchiveItemDays')
	EXEC('ALTER TABLE [dbo].[AppbuilderSettings] ADD CONSTRAINT [' + @NameOfConstraint + ']   DEFAULT ((365)) FOR [' + @NameOfField + ']')
        
UPDATE ab
SET ab.ArchiveItemDays = 365
FROM AppbuilderSettings ab 
INNER JOIN Asset a ON a.AssetID = ab.MenuID AND a.BaseAssetID is null 
AND a.Title in ('Appbuilder', 'Blank', 'Buy and Sell','Business Links', 'Company News', 'Contacts', 'Job Center', 'Knowledgebase', 'Share Recipes', 'Suggestion Box', 'Task Manager')
INNER JOIN Application app on app.AppID = a.AssetID
        

UPDATE AppbuilderLanguage
SET LVersioning = 'File Versioning'
FROM		AppbuilderLanguage a
INNER JOIN Asset b ON b.AssetID = a.MenuID
                                 
END
</cfquery>