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