1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
6 %# <sales@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/licenses/old-licenses/gpl-2.0.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 = RT::Ticket->new($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();
75 my @arglist = split('/', $args );
77 if (defined $arglist[0] && $arglist[0] eq 'type') {
79 } elsif ( defined $arglist[0] && $arglist[0] eq 'id') {
86 # Create, Set, Status, Correspond, Comment, Give, Steal, Take, Told
87 # CustomField, AddLink, DeleteLink, AddWatcher, DelWatcher
88 if ($args =~ /^links?$/) {
89 $trans->Limit(FIELD => 'Type', OPERATOR => 'LIKE', VALUE => '%Link');
91 elsif ($args =~ /^watchers?$/) {
92 $trans->Limit(FIELD => 'Type', OPERATOR => 'LIKE', VALUE => '%Watcher');
95 $trans->Limit(FIELD => 'Type', OPERATOR => '=', VALUE => $type);
98 $trans->Limit(FIELD => 'Id', OPERATOR => '=', VALUE => $tid);
103 my $t = RT::Transaction->new($session{CurrentUser});
105 # this paragraph limits the transaction ID query to transactions on this ticket.
106 # Otherwise you can query any transaction from any ticket, which makes no sense.
107 my $Transactions = $ticket->Transactions;
109 while (my $T = $Transactions->Next()) {
110 $tok=1 if ($T->Id == $tid)
115 return [ "# Transaction $tid is not related to Ticket $id", [], {}, 1 ];
118 push @data, [ id => $t->Id ];
119 push @data, [ Ticket => $t->Ticket ]
120 if (!%$fields || exists $fields->{lc 'Ticket'});
121 push @data, [ TimeTaken => $t->TimeTaken ]
122 if (!%$fields || exists $fields->{lc 'TimeTaken'});
123 push @data, [ Type => $t->Type ]
124 if (!%$fields || exists $fields->{lc 'Type'});
125 push @data, [ Field => $t->Field ]
126 if (!%$fields || exists $fields->{lc 'Field'});
127 push @data, [ OldValue => $t->OldValue ]
128 if (!%$fields || exists $fields->{lc 'OldValue'});
129 push @data, [ NewValue => $t->NewValue ]
130 if (!%$fields || exists $fields->{lc 'NewValue'});
131 push @data, [ Data => $t->Data ]
132 if (!%$fields || exists $fields->{lc 'Data'});
133 push @data, [ Description => $t->Description ]
134 if (!%$fields || exists $fields->{lc 'Description'});
135 push @data, [ Content => $t->Content ]
136 if (!%$fields || exists $fields->{lc 'Content'});
139 if (!%$fields || exists $fields->{lc 'Content'}) {
140 my $creator = RT::User->new($session{CurrentUser});
141 $creator->Load($t->Creator);
142 push @data, [ Creator => $creator->Name ];
144 push @data, [ Created => $t->Created ]
145 if (!%$fields || exists $fields->{lc 'Created'});
147 if (!%$fields || exists $fields->{lc 'Attachments'}) {
149 my $attachments = $t->Attachments;
150 while (my $a = $attachments->Next) {
151 my $size = length($a->Content||'');
152 if ($size > 1024) { $size = int($size/102.4)/10 . "k" }
153 else { $size .= "b" }
154 my $name = (defined $a->Filename and length $a->Filename) ? $a->Filename : "untitled";
155 $attachlist .= "\n" . $a->Id.": $name ($size)";
158 push @data, [Attachments => $attachlist];
161 my %k = map {@$_} @data;
162 $o = [ map {$_->[0]} @data ];
168 $format = "l" if (%$fields);
170 while (my $t = $trans->Next) {
173 if ($format eq "l") {
174 $tids .= "," if $tids;
178 $k->{$tid} = $t->Description;
182 if ($format eq "l") {
184 push @tid, "ticket/$id/history/id/$tids";
186 foreach my $key (keys %$fields) {
187 $fieldstring .= "," if $fieldstring;
188 $fieldstring .= $key;
190 my ($content, $forms);
191 $m->subexec("/REST/1.0/show",
194 fields => $fieldstring);
195 return [ $c, $o, $k, $e ];
200 my $sub = $trans->Count();
201 $c = "# $sub/$total ($args/total)";
204 return [ $c, $o, $k, $e ];