1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
6 %# <jesse@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/copyleft/gpl.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
48 %# REST/1.0/Forms/ticket/history
57 my $ticket = new RT::Ticket $session{CurrentUser};
58 my ($c, $o, $k, $e) = ("", [], {}, "");
61 unless ($ticket->Id) {
62 return [ "# Ticket $id does not exist.", [], {}, 1 ];
65 my $trans = $ticket->Transactions();
66 my $total = $trans->Count();
69 my @arglist = split('/', $args);
72 if ($arglist[0] eq 'type') {
74 } elsif ($arglist[0] eq 'id') {
81 # Create, Set, Status, Correspond, Comment, Give, Steal, Take, Told
82 # CustomField, AddLink, DeleteLink, AddWatcher, DelWatcher
83 if ($args =~ /^links?$/) {
84 $trans->Limit(FIELD => 'Type', OPERATOR => 'LIKE', VALUE => '%Link');
86 elsif ($args =~ /^watchers?$/) {
87 $trans->Limit(FIELD => 'Type', OPERATOR => 'LIKE', VALUE => '%Watcher');
90 $trans->Limit(FIELD => 'Type', OPERATOR => '=', VALUE => $type);
93 $trans->Limit(FIELD => 'Id', OPERATOR => '=', VALUE => $tid);
98 my $t = new RT::Transaction $session{CurrentUser};
100 # this paragraph limits the transaction ID query to transactions on this ticket.
101 # Otherwise you can query any transaction from any ticket, which makes no sense.
102 my $Transactions = $ticket->Transactions;
104 while (my $T = $Transactions->Next()) {
105 $tok=1 if ($T->Id == $tid)
110 return [ "# Transaction $tid is not related to Ticket $id", [], {}, 1 ];
113 push @data, [ id => $t->Id ];
114 push @data, [ Ticket => $t->Ticket ]
115 if (!%$fields || exists $fields->{lc 'Ticket'});
116 push @data, [ TimeTaken => $t->TimeTaken ]
117 if (!%$fields || exists $fields->{lc 'TimeTaken'});
118 push @data, [ Type => $t->Type ]
119 if (!%$fields || exists $fields->{lc 'Type'});
120 push @data, [ Field => $t->Field ]
121 if (!%$fields || exists $fields->{lc 'Field'});
122 push @data, [ OldValue => $t->OldValue ]
123 if (!%$fields || exists $fields->{lc 'OldValue'});
124 push @data, [ NewValue => $t->NewValue ]
125 if (!%$fields || exists $fields->{lc 'NewValue'});
126 push @data, [ Data => $t->Data ]
127 if (!%$fields || exists $fields->{lc 'Data'});
128 push @data, [ Description => $t->Description ]
129 if (!%$fields || exists $fields->{lc 'Description'});
130 push @data, [ Content => $t->Content ]
131 if (!%$fields || exists $fields->{lc 'Content'});
134 if (!%$fields || exists $fields->{lc 'Content'}) {
135 my $creator = new RT::User $session{CurrentUser};
136 $creator->Load($t->Creator);
137 push @data, [ Creator => $creator->Name ];
139 push @data, [ Created => $t->Created ]
140 if (!%$fields || exists $fields->{lc 'Created'});
142 if (!%$fields || exists $fields->{lc 'Attachments'}) {
144 my $attachments = $t->Attachments;
145 while (my $a = $attachments->Next) {
146 my $size = length($a->Content);
147 if ($size > 1024) { $size = int($size/102.4)/10 . "k" }
148 else { $size .= "b" }
149 $attachlist .= "\n" . $a->Id.": ".($a->Filename || "untitled")." (".$size.")";
152 push @data, [Attachments => $attachlist];
155 my %k = map {@$_} @data;
156 $o = [ map {$_->[0]} @data ];
162 $format = "l" if (%$fields);
164 while (my $t = $trans->Next) {
167 if ($format eq "l") {
168 $tids .= "," if $tids;
172 $k->{$tid} = $t->Description;
176 if ($format eq "l") {
178 push @tid, "ticket/$id/history/id/$tids";
180 foreach my $key (keys %$fields) {
181 $fieldstring .= "," if $fieldstring;
182 $fieldstring .= $key;
184 my ($content, $forms);
185 $m->subexec("/REST/1.0/show",
188 fields => $fieldstring);
189 return [ $c, $o, $k, $e ];
194 my $sub = $trans->Count();
195 $c = "# $sub/$total ($args/total)";
198 return [ $c, $o, $k, $e ];