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