Old files left over from experiments few weeks ago.
authorrich <rich>
Mon, 25 Jul 2005 12:49:22 +0000 (12:49 +0000)
committerrich <rich>
Mon, 25 Jul 2005 12:49:22 +0000 (12:49 +0000)
tools/.cvsignore [new file with mode: 0644]
tools/copy_page.ml [new file with mode: 0644]

diff --git a/tools/.cvsignore b/tools/.cvsignore
new file mode 100644 (file)
index 0000000..4fe4f92
--- /dev/null
@@ -0,0 +1,3 @@
+*.cmi
+*.cmo
+copy_page
diff --git a/tools/copy_page.ml b/tools/copy_page.ml
new file mode 100644 (file)
index 0000000..4533e93
--- /dev/null
@@ -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 ()