Control of the can_edit_macros user permission.
[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.2 2006/07/26 13:41:46 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, hostid, redirect, css)
25      select ? as url, title, description, ? as hostid, redirect, css
26        from pages
27       where id = ?" in
28   sth#execute [`String new_url; `Int new_hostid; `Int old_pageid];
29   let new_pageid = sth#serial "pages_id_seq" in
30
31   let sth = dbh#prepare_cached
32     "insert into contents (pageid, ordering, sectionname, content,
33                            divname, jsgo)
34      select ? as pageid, ordering, sectionname, content, divname, jsgo
35        from contents
36       where pageid = ?" in
37   sth#execute [`Int new_pageid; `Int old_pageid];
38
39   dbh#commit ()