X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=tools%2Fcopy_page.ml;fp=tools%2Fcopy_page.ml;h=4533e938bcdb9e0ddba8f0d03a08b54ab40045d1;hb=7e7ab40c68f1be81e064dfb177dacf45885eac5d;hp=0000000000000000000000000000000000000000;hpb=fbd2931d412b6fc0448bf1c6c1441340e77b945c;p=cocanwiki.git diff --git a/tools/copy_page.ml b/tools/copy_page.ml new file mode 100644 index 0000000..4533e93 --- /dev/null +++ b/tools/copy_page.ml @@ -0,0 +1,38 @@ +(* 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 ()