%@ Language="VBScript" %> <% ' /////////////////////////////////////////////////////// ' // Dimac CMS ' // Copyright 2004-2008 Dimac Development AB, Sweden ' // www.Dimac.net ' // ' // NOTE: ' // You are not allowed to remove this ' // Copyright information without written ' // permission from Dimac Development. ' /////////////////////////////////////////////////////// ' // GetConStr = "Provider=SQLOLEDB;Data Source=localhost;database=dev_DimacCMS-L;uid=www_dimaccms;pwd=www_dimaccms;" ' // GetConStr = "DSN=MyDSN; User Id=MyUserID; Password=MyPassword;" vDebug = False vExamples = (Request.Form("examples").Item="yes") vDatabase = Request.Form("database").Item vDBName = Request.Form("dbname").Item vDSNName = Request.Form("dsnname").Item vDBIP = Request.Form("dbserver").Item vDBPass = Request.Form("password").Item vDBUser = Request.Form("username").Item vDBUser2 = Request.Form("dbusername2").Item vDBPass2 = Request.Form("dbpassword2").Item vPosted = (vDatabase<>"") ' Selected Database Type If vDatabase = "MS-SQL" Then strConn = "Provider=SQLOLEDB;Data Source="& vDBIP & ";database=" & vDBName & ";uid=" & vDBUser & ";pwd=" & vDBPass & ";" ElseIf vDatabase = "mySQL" Then strConn = "DSN=" & vDSNName & "; User Id=" & vDBUser2 & "; Password=" & vDBPass2 & ";" Else vPosted = False 'strConn = "Provider=SQLOLEDB;Data Source="& vDBIP & ";database=" & vDBName & ";uid=" & vDBUser & ";pwd=" & vDBPass & ";" 'strConn = GetConStr("..\SiteResources\Data\") End If If vPosted Then vPath = Server.MapPath("sql/" & LCase(vDatabase) & "_create.sql") Set fso = Server.CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(vPath, 1, False) allSQL = f.ReadAll f.Close Set cunn = Server.CreateObject("ADODB.Connection") Set conn = Server.CreateObject("ADODB.Connection") Set ris = Server.CreateObject("ADODB.Recordset") Set ros = Server.CreateObject("ADODB.Recordset") conn.Open GetConStr("..\SiteResources\Data\") cunn.Open strConn dim arrOldID(), arrNewID(), max dim oldRevs(), newRevs() max=0 rmax=0 ' Create tables using the SQL files If LCase(vDatabase) = "ms-sql" Then For Each sql In Split(allSQL, "GO") sql = Replace(sql, vbTab, " ") sql = Replace(sql, vbNewLine, " ") sql = Trim(sql) If Len(sql) > 5 Then exeSQL cunn, sql End If Next ElseIf LCase(vDatabase) = "mysql" Then For Each sql In Split(allSQL, "CREATE TABLE") sql = Replace(sql, vbTab, " ") sql = Replace(sql, vbNewLine, " ") sql = Trim(sql) If Len(sql) > 5 Then sql = "CREATE TABLE " & sql exeSQL cunn, sql End If Next End If ' Tables that does not relate to other tables: arrSQL = array( "ContentScripts", "FunctionScripts", "Languages", "Modules", "SystemData", "Users", "UserGroups", "Members") For i = LBound(arrSQL) To UBound(arrSQL) ros.Open "SELECT * FROM " & arrSQL(i), conn, 1, 3 If Not ros.EOF And Not ros.BOF Then sep="" sql="INSERT INTO " & arrSQL(i) & " (" sql=sql & addFields(ros, 1) sql=sql&") VALUES (" While Not ros.EOF sep="" sql2 = sql & addValues(ros, 1, "", "") & ")" exeSQL cunn, sql2 ros.MoveNext Wend End If ros.Close Next 'Copy the documents: sql="SELECT * FROM Documents ORDER BY ParentID, SortOrder DESC" ros.Open sql, conn, 1, 3 While Not ros.EOF id=ros("DocumentID").Value parent=ros("ParentID").Value temp=ros("TemplateURL").Value TopLevel=(Left(temp, 1)="0") ' If it is a TopLevel document (or user has selected ' to add examples to the DB) current copy document: If vExamples Or TopLevel Then sql="INSERT INTO Documents (" & addFields(ros, 1) & ") VALUES (" & addValues(ros, 1, "", "") & ")" exeSQL cunn, sql sql="SELECT DocumentID FROM Documents ORDER BY DocumentID DESC" ris.Open sql, cunn, 1, 3 If Not ris.EOF And Not ris.BOF Then idNew=ris("DocumentID").Value End If ris.Close ' Copy information about the current document ' into these tables: FillWithDocInfo ris, conn, cunn, "DocumentLanguages", "DocId", idNew, id FillWithDocInfo ris, conn, cunn, "DocumentFields", "DocID", idNew, id End If If vExamples Then ' Copy "unnecessary" exmple data: FillWithDocInfo ris, conn, cunn, "WorkFlowInfo", "DocID", idNew, id FillWithDocInfo ris, conn, cunn, "Tasks", "DocumentID", idNew, id 'TemplatePermissions End If if temp = "0TrashBin.asp" then trash=idNew if temp = "0SiteRoot.asp" then root=idNew ' Store the new and old DocumentID's to be used to ' update the ParentID's: ReDim Preserve arrOldID(max) ReDim Preserve arrNewID(max) arrOldID(max) = id arrNewID(max) = idNew max=max+1 ros.MoveNext Wend ros.Close ' Update with previously inserted DocumentID's and RevisionID's UpdateIDs "Documents", "ParentID", arrOldID, arrNewID, cunn ' Insert information into cmsSettigns and change the DatabaseType: sql="SELECT * FROM cmsSettings" ros.Open sql, conn, 1, 3 If Not ros.EOF And Not ros.BOF Then sep="" sql="INSERT INTO cmsSettings (" sql=sql & addFields(ros, 1) sql=sql&") VALUES (" While Not ros.EOF sep="" sql2 = sql & addValues(ros, 1, "", "") & ")" exeSQL cunn, sql2 ros.MoveNext Wend End If ros.Close sql2="UPDATE cmsSettings SET SettingValue = '" & vDatabase & "' WHERE SettingKey = 'DatabaseType'" exeSQL cunn, sql2 sql2="UPDATE cmsSettings SET SettingValue = '" & root & "' WHERE SettingKey = 'SiteRootID'" exeSQL cunn, sql2 sql2="UPDATE cmsSettings SET SettingValue = '" & trash & "' WHERE SettingKey = 'TrashBinID'" exeSQL cunn, sql2 conn.Close cunn.Close Set ris = Nothing Set ros = Nothing Set conn = Nothing Set cunn = Nothing End If '------------------------------------------------------- '-- UpdateIDs '-- Updates fields[flds] in a [table] with values '-- from an array. '------------------------------------------------------- Function UpdateIDs( table, flds, oldids, newids, conn ) Dim fld, sql, i For Each fld In Split(flds, ",") For i = LBound(oldids) To UBound(oldids) sql="UPDATE " & table & " SET " & fld & "=" & newids(i) & " WHERE " & fld & "=" & oldids(i) exeSQL conn, sql Next Next End Function '------------------------------------------------------- '-- addFields '-- Returns filed names from a RecordSet (for '-- constructing SQL INSERT statements) '------------------------------------------------------- Function addFields(rs, start) Dim result, sep, f result="" sep="" For f = start To rs.Fields.Count-1 result = result & sep & rs.Fields.Item(f).Name sep=", " Next addFields=result End Function '------------------------------------------------------- '-- addValues '-- Returns filed values from a RecordSet (for '-- constructing SQL INSERT statements) '------------------------------------------------------- Function addValues(rs, start, replaceName, replaceValue) Dim result, sep, f, t, v, n result="" sep="" For f = start To rs.Fields.Count-1 v=rs.Fields.Item(f).Value&"" t=rs.Fields.Item(f).Type n=rs.Fields.Item(f).Name If n=replaceName then v=replaceValue If (t>3 And t<15) or t>21 Then v = "'"&ff(v)&"'" ElseIf v="" Then v=0 End If result = result & sep & v sep=", " Next addValues = result End Function '------------------------------------------------------- '-- FillWithDocInfo '-- Copies the data from one table in one database '-- to another. Replaces the DocumentID with the '-- DocumentID from the new database. '------------------------------------------------------- Sub FillWithDocInfo (rs, conn, destConn, tblName, colDocID, newID, oldID) Dim sql, start start=1 if tblName = "TemplatePermissions" Then start=0 sql = "SELECT * FROM " & tblName & " WHERE " & colDocID & " = " & oldID rs.Open sql, conn, 1, 3 If Not rs.EOF And Not rs.BOF Then sql="INSERT INTO " & tblName & " (" & addFields(rs, start) & ") VALUES (" End If While Not rs.EOF sql2 = sql & addValues(rs, start, colDocID, newID) & ")" exeSQL destConn, sql2 rs.MoveNext Wend rs.Close End Sub '------------------------------------------------------- '-- FillWithRevInfo '-- Copies the data from revisions in one database '-- to another. Replaces the DocumentID with the '-- DocumentID from the new database. '-- Adds the two tables' RevID's to two arrays '------------------------------------------------------- Sub FillWithRevInfo (rs, conn, destConn, tblName, colDocID, newID, oldID) Dim sql, start, res, oldRevId, newRevId Set res = Server.CreateObject("ADODB.Recordset") sql = "SELECT * FROM Revisions WHERE " & colDocID & " = " & oldID rs.Open sql, conn, 1, 3 If Not rs.EOF And Not rs.BOF Then sql="INSERT INTO Revisions (" & addFields(rs, 1) & ") VALUES (" End If While Not rs.EOF oldRevId = rs("ID").Value sql2 = sql & addValues(rs, 1, colDocID, newID) & ")" exeSQL destConn, sql2 sql3="SELECT * FROM Revisions ORDER BY ID DESC " res.Open sql3, destConn, 1, 3 If Not res.EOF And Not res.BOF Then newRevId = res("ID").Value End If res.Close ReDim Preserve oldRevs(rmax) ReDim Preserve newRevs(rmax) oldRevs(rmax) = oldRevId newRevs(rmax) = newRevId rmax=rmax+1 rs.MoveNext Wend rs.Close End Sub '------------------------------------------------------- '-- FillWithDependentInfo '-- Copies the data from two tables in one database '-- to another. '-- Uses id's from first table into the next one. '------------------------------------------------------- Sub FillWithDependentInfo (rs, conn, destConn, tblFirst, tblSecond, matchFirst, matchSecond) Dim sql, rus, newId Set rus = Server.CreateObject("ADODB.Recordset") sql = "SELECT * FROM " & tblFirst rs.Open sql, conn, 1, 3 While Not rs.EOF sql="INSERT INTO " & tblFirst & " (" & addFields(rs, 1) & ") VALUES (" & addValues(rs, 1, "", "") & ")" exeSQL destConn, sql sql="SELECT * FROM " & tblFirst & " ORDER BY " & matchFirst & " DESC" rus.Open sql, destConn, 1, 3 If Not rus.EOF And Not rus.BOF Then newId=rus(matchFirst).Value End If rus.Close FillWithDocInfo rus, conn, destConn, tblSecond, matchSecond, newId, rs(matchFirst).Value rs.MoveNext Wend rs.Close End Sub '------------------------------------------------------- '-- exeSQL '-- Execute the inSQL '------------------------------------------------------- Sub exeSQL(inConn, inSQL) If vDebug = False Then 'Response.Write inSQL & vbNewLine On Error Resume Next inConn.Execute(inSQL) If err.number <> 0 Then Response.Write "
" & inSQL & "" End If Else Response.Write inSQL & vbNewLine & vbNewLine End If End Sub '------------------------------------------------------- '-- ff '-- fix the fnutts '------------------------------------------------------- Function ff(inStr) ff = Replace(inStr&"", "'", "''") End Function %>
" & err.Description & "
