2 * Written by Richard W.M. Jones <rich@merjis.com>.
3 * Copyright (C) 2004 Merjis Ltd.
4 * $Id: undelete_file.ml,v 1.2 2004/09/07 13:40:10 rich Exp $
15 open Cocanwiki_template
18 let run r (q : cgi) (dbh : Dbi.connection) (hostid, hostname, _) _ =
19 let id = int_of_string (q#param "id") in
21 if q#param_true "yes" then (
22 (* Get the name of the file. *)
23 let sth = dbh#prepare_cached "select name_deleted from files
24 where hostid = ? and id = ?" in
25 sth#execute [`Int hostid; `Int id];
27 let name = sth#fetch1string () in
29 (* First delete any more recent versions of this file. *)
30 let sth = dbh#prepare_cached "update files
31 set name_deleted = name, name = null
32 where hostid = ? and name = ?" in
33 sth#execute [`Int hostid; `String name];
35 (* Now copy the old row, changing name_deleted back to name so the file
38 let sth = dbh#prepare_cached "insert into files
39 (hostid, name, content, title, mime_type,
41 select hostid, name_deleted, content,
42 title, mime_type, upload_date
44 where hostid = ? and id = ?" in
45 sth#execute [`Int hostid; `Int id];
50 let buttons = [ ok_button "/_files" ] in
51 ok ~title:"File restored" ~buttons
52 q "File was restored successfully."
54 q#redirect ("http://" ^ hostname ^ "/_files")