(* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. * $Id: rebuild_links.ml,v 1.7 2006/07/27 16:46:55 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. *) open Apache open Registry open Cgi open Printf open Cocanwiki open Cocanwiki_template open Cocanwiki_links 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. *) PGSQL(dbh) "delete from links where hostid = $hostid"; (* Pull out the list of sections to process. *) let sections = PGSQL(dbh) "select c.content, c.ordering, p.url from contents c, pages p where c.pageid = p.id and p.hostid = $hostid and p.url is not null and p.redirect is null order by p.url, c.ordering" in let total_sections = List.length sections in q#header (); ignore (print_string r template_start#to_string); (* Process each section ... *) let i = ref 0 in 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); let links = get_links_from_section r dbh hostid content in List.iter (insert_link dbh hostid url) links ) sections; (* Finish off. *) PGOCaml.commit dbh; ignore (print_string r template_done#to_string) let () = register_script ~restrict:[CanManageSite] run