5689e5d2bb00b4bcf283aa5ba9a2de06c7a41726
[cocanwiki.git] / tools / copy_page.ml
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.3 2006/08/04 12:45:35 rich Exp $
4  *
5  * Usage: copy_page hostid url new_hostid new_url
6  *)
7
8 module DB = Dbi_postgres
9
10 let dbh = DB.connect "cocanwiki"
11
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)
16
17 let () =
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
22
23   let sth = dbh#prepare_cached
24     "insert into pages (url, title, description, keywords,
25                         hostid, redirect, css)
26      select ? as url, title, description, keywords, ? as hostid, redirect, css
27        from pages
28       where id = ?" in
29   sth#execute [`String new_url; `Int new_hostid; `Int old_pageid];
30   let new_pageid = sth#serial "pages_id_seq" in
31
32   let sth = dbh#prepare_cached
33     "insert into contents (pageid, ordering, sectionname, content,
34                            divname, jsgo)
35      select ? as pageid, ordering, sectionname, content, divname, jsgo
36        from contents
37       where pageid = ?" in
38   sth#execute [`Int new_pageid; `Int old_pageid];
39
40   dbh#commit ()