1 (* Copy a page from one host to another. Note that this only copies
2 * the text, not any images which may be present.
3 * $Id: copy_page.ml,v 1.1 2005/07/25 12:49:22 rich Exp $
5 * Usage: copy_page hostid url new_hostid new_url
8 module DB = Dbi_postgres
10 let dbh = DB.connect "cocanwiki"
12 let old_hostid = int_of_string Sys.argv.(1)
13 let old_url = Sys.argv.(2)
14 let new_hostid = int_of_string Sys.argv.(3)
15 let new_url = Sys.argv.(4)
18 let sth = dbh#prepare_cached
19 "select id from pages where hostid = ? and url = ?" in
20 sth#execute [`Int old_hostid; `String old_url];
21 let old_pageid = sth#fetch1int () in
23 let sth = dbh#prepare_cached
24 "insert into pages (url, title, description, hostid, redirect, css)
25 select ? as url, title, description, ? as hostid, redirect, css
28 sth#execute [`String new_url; `Int new_hostid; `Int old_pageid];
29 let new_pageid = sth#serial "pages_id_seq" in
31 let sth = dbh#prepare_cached
32 "insert into contents (pageid, ordering, sectionname, content, divname)
33 select ? as pageid, ordering, sectionname, content, divname
36 sth#execute [`Int new_pageid; `Int old_pageid];