Deletion using same record rather then recordIdOpaque
[irspy-moved-to-github.git] / web / htdocs / details / delete.mc
1 %# $Id: delete.mc,v 1.6 2007-04-25 13:28:42 mike Exp $
2 <%args>
3 $id
4 $really => 0
5 </%args>
6 % if (!$really) {
7      <h2>Warning</h2>
8      <p class="error">
9       Are you sure you want to delete the target
10       <% xml_encode($id) %>?
11      </p>
12      <p>
13       <a href="?really=1&amp;id=<% xml_encode(uri_escape($id)) %>">Yes</a><br/>
14       <a href="/full.html?id=<% xml_encode(uri_escape($id)) %>">No</a><br/>
15      </p>
16 % } else {
17 <%perl>
18     # We can't delete records using recordIdOpaque, since character
19     # sets are handled differently here in extended services from how
20     # they are used in the Alvis filter's record-parsing, and so
21     # non-ASCII characters come out differently in the two contexts.
22     # Instead, we must send a record whose contents indicate the ID of
23     # that which we wish to delete.  There are two ways, both
24     # unsatisfactory: we could either fetch the actual record them
25     # resubmit it in the deletion request (which wastes a search and a
26     # fetch) or we could build a record by hand from the parsed-out
27     # components (which is error-prone and which I am not 100% certain
28     # will work since the other contents of the record will be
29     # different).  The former evil seems to be the lesser.
30     my $conn = new ZOOM::Connection("localhost:8018/IR-Explain---1", 0,
31                                     user => "admin", password => "fruitbat",
32                                     elementSetName => "zeerex");
33     my $rs = $conn->search(new ZOOM::Query::CQL(cql_target($id)));
34     if ($rs->size() == 0) {
35         $m->comp("/details/error.mc",
36                  title => "Error", message => "No such ID '$id'");
37         return 0;
38     }
39     my $rec = $rs->record(0);
40     my $xml = $rec->render();
41
42     my $p = $conn->package();
43     $p->option(action => "recordDelete");
44     $p->option(record => $xml);
45     $p->send("update");
46     $p->destroy();
47
48     $p = $conn->package();
49     $p->send("commit");
50     $p->destroy();
51 </%perl>
52      <p>
53       Deleted record
54       <% xml_encode($id) %>
55      </p>
56 % }