Change subject line so it shows the name of the site.
[cocanwiki.git] / scripts / rebuild_links.ml
index f7afa1b..21c2904 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: rebuild_links.ml,v 1.5 2006/03/27 18:09:46 rich Exp $
+ * $Id: rebuild_links.ml,v 1.6 2006/03/28 16:24:08 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -34,50 +34,38 @@ let run r (q : cgi) dbh hostid _ _ =
   let template_done = _get_template "rebuild_links_done.html" in
 
   (* Delete entries in the old links table. *)
-  let sth = dbh#prepare_cached "delete from links where hostid = ?" in
-  sth#execute [Some hostid];
-
-  (* Estimate how many sections we will have to process. *)
-  let sth =
-    dbh#prepare_cached
-      "select count(c.id)::int4 from contents c, pages p
-        where c.pageid = p.id
-          and p.hostid = ?
-          and p.url is not null
-          and p.redirect is null" in
-  sth#execute [Some hostid];
-
-  let total_sections = sth#fetch1int () in
+  PGSQL(dbh) "delete from links where hostid = $hostid";
 
   (* Pull out the list of sections to process. *)
-  let sth =
-    dbh#prepare_cached
+  let sections =
+    PGSQL(dbh)
       "select c.content, c.ordering, p.url from contents c, pages p
         where c.pageid = p.id
-          and p.hostid = ?
+          and p.hostid = $hostid
           and p.url is not null
           and p.redirect is null
         order by p.url, c.ordering" in
-  sth#execute [Some hostid];
+
+  let total_sections = List.length sections in
 
   q#header ();
-  print_string r template_start#to_string;
+  ignore (print_string r template_start#to_string);
 
   (* Process each section ... *)
   let i = ref 0 in
 
-  sth#iter
-    (function [Some content; Some ordering; Some url] ->
-       let pc = 100 * !i / total_sections in incr i;
-       template#set "ordering" (Int32.to_string ordering);
-       template#set "url" url;
-       template#set "pc" (Int32.to_string pc);
-       print_string r template#to_string;
-
-       let links = get_links_from_section dbh hostid content in
-       List.iter (insert_link dbh hostid url) links
+  List.iter (
+    fun (content, ordering, url) ->
+      let url = Option.get url in
+      let pc = 100 * !i / total_sections in incr i;
+      template#set "ordering" (Int32.to_string ordering);
+      template#set "url" url;
+      template#set "pc" (string_of_int pc);
+      ignore (print_string r template#to_string);
 
-       | _ -> assert false);
+      let links = get_links_from_section dbh hostid content in
+      List.iter (insert_link dbh hostid url) links
+  ) sections;
 
   (* Finish off. *)
   PGOCaml.commit dbh;