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