X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Frebuild_links.ml;h=21c2904d95ebb9b3f1e0b27a4e9ef86960113321;hb=262f6a0c34949247ba6b78399b787e693da38d86;hp=354776a8d43d1ef2f5d2693e8cf05a63aa971337;hpb=1e757a53a78e6b288f483b3b689a600d20575562;p=cocanwiki.git diff --git a/scripts/rebuild_links.ml b/scripts/rebuild_links.ml index 354776a..21c2904 100644 --- a/scripts/rebuild_links.ml +++ b/scripts/rebuild_links.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: rebuild_links.ml,v 1.3 2004/10/23 12:00:24 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 @@ -28,59 +28,47 @@ open Cocanwiki open Cocanwiki_template open Cocanwiki_links -let run r (q : cgi) (dbh : Dbi.connection) hostid _ _ = +let run r (q : cgi) dbh hostid _ _ = let template_start = _get_template "rebuild_links_start.html" in let template = _get_template "rebuild_links.html" in 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 [`Int hostid]; - - (* Estimate how many sections we will have to process. *) - let sth = - dbh#prepare_cached - "select count(c.id) 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 [`Int 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 [`Int 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 [`String content; `Int ordering; `String url] -> - let pc = 100 * !i / total_sections in incr i; - template#set "ordering" (string_of_int ordering); - template#set "url" url; - template#set "pc" (string_of_int 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. *) - dbh#commit (); + PGOCaml.commit dbh; ignore (print_string r template_done#to_string)