From 7e7ab40c68f1be81e064dfb177dacf45885eac5d Mon Sep 17 00:00:00 2001 From: rich Date: Mon, 25 Jul 2005 12:49:22 +0000 Subject: [PATCH] Old files left over from experiments few weeks ago. --- tools/.cvsignore | 3 +++ tools/copy_page.ml | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tools/.cvsignore create mode 100644 tools/copy_page.ml diff --git a/tools/.cvsignore b/tools/.cvsignore new file mode 100644 index 0000000..4fe4f92 --- /dev/null +++ b/tools/.cvsignore @@ -0,0 +1,3 @@ +*.cmi +*.cmo +copy_page 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 () -- 1.8.3.1