line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Workflow::History; |
2
|
|
|
|
|
|
|
|
3
|
22
|
|
|
22
|
|
766
|
use warnings; |
|
22
|
|
|
|
|
46
|
|
|
22
|
|
|
|
|
922
|
|
4
|
22
|
|
|
22
|
|
119
|
use strict; |
|
22
|
|
|
|
|
68
|
|
|
22
|
|
|
|
|
703
|
|
5
|
22
|
|
|
22
|
|
121
|
use base qw( Class::Accessor ); |
|
22
|
|
|
|
|
72
|
|
|
22
|
|
|
|
|
3088
|
|
6
|
22
|
|
|
22
|
|
2095
|
use DateTime; |
|
22
|
|
|
|
|
45
|
|
|
22
|
|
|
|
|
7698
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Workflow::History::VERSION = '1.62'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my @FIELDS |
11
|
|
|
|
|
|
|
= qw( id workflow_id action description date user state time_zone ); |
12
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(@FIELDS); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
35
|
|
|
35
|
1
|
15886
|
my ( $class, $params ) = @_; |
16
|
35
|
|
|
|
|
130
|
my $self = bless { _saved => 0 }, $class; |
17
|
35
|
|
|
|
|
97
|
for (@FIELDS) { |
18
|
280
|
100
|
|
|
|
3087
|
$self->$_( $params->{$_} ) if ( $params->{$_} ); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $time_zone |
22
|
35
|
100
|
|
|
|
360
|
= exists $params->{time_zone} ? $params->{time_zone} : 'floating'; |
23
|
35
|
|
|
|
|
117
|
$self->time_zone($time_zone); |
24
|
|
|
|
|
|
|
|
25
|
35
|
100
|
|
|
|
380
|
unless ( $self->date ) { |
26
|
11
|
|
|
|
|
168
|
$self->date( DateTime->now( time_zone => $self->time_zone() ) ); |
27
|
|
|
|
|
|
|
} |
28
|
35
|
|
|
|
|
6790
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub set_new_state { |
32
|
10
|
|
|
10
|
1
|
164
|
my ( $self, $new_state ) = @_; |
33
|
10
|
50
|
|
|
|
46
|
unless ( $self->state ) { |
34
|
10
|
|
|
|
|
155
|
$self->state($new_state); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub is_saved { |
39
|
43
|
|
|
43
|
1
|
4977
|
my ($self) = @_; |
40
|
43
|
|
|
|
|
182
|
return $self->{_saved}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub set_saved { |
44
|
36
|
|
|
36
|
1
|
528
|
my ($self) = @_; |
45
|
36
|
|
|
|
|
63
|
$self->{_saved} = 1; |
46
|
|
|
|
|
|
|
|
47
|
36
|
|
|
|
|
67
|
return 1; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub clear_saved { |
51
|
1
|
|
|
1
|
1
|
3
|
my ($self) = @_; |
52
|
1
|
|
|
|
|
1
|
$self->{_saved} = 0; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
5
|
return 0; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=pod |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 NAME |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Workflow::History - Recorded work on a workflow action or workflow itself |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 VERSION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This documentation describes version 1.62 of this package |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SYNOPSIS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# in your action |
74
|
|
|
|
|
|
|
sub execute { |
75
|
|
|
|
|
|
|
my ( $self, $wf ) = @_; |
76
|
|
|
|
|
|
|
my $current_user = $wf->context->param( 'current_user' ); |
77
|
|
|
|
|
|
|
# ... do your work with $ticket |
78
|
|
|
|
|
|
|
$wf->add_history( action => 'create ticket', |
79
|
|
|
|
|
|
|
user => $current_user->full_name, |
80
|
|
|
|
|
|
|
description => "Ticket $ticket->{subject} successfully created" ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# in your view (using TT2) |
84
|
|
|
|
|
|
|
[% FOREACH history = workflow.get_history %] |
85
|
|
|
|
|
|
|
On: [% OI.format_date( history.date, '%Y-%m-%d %H:%M' ) %]<br> |
86
|
|
|
|
|
|
|
Action: [% history.action %] (ID: [% history.id %])<br> |
87
|
|
|
|
|
|
|
by: [% history.user %]<br> |
88
|
|
|
|
|
|
|
[% history.description %] |
89
|
|
|
|
|
|
|
[% END %] |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 DESCRIPTION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Every workflow can record its history. More appropriately, every |
94
|
|
|
|
|
|
|
action the workflow executes can deposit history entries in the |
95
|
|
|
|
|
|
|
workflow to be saved later. Neither the action nor the workflow knows |
96
|
|
|
|
|
|
|
about how the history is saved, just that the history is available. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 METHODS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 Public Methods |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head3 new( \%params ) |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Create a new history object, filling it with properties from |
105
|
|
|
|
|
|
|
C<\%params>. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head3 set_new_state( $new_state ) |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Assigns the new state C<$new_state> to the history if the state is not |
110
|
|
|
|
|
|
|
already assigned. This is used when you generate a history request in |
111
|
|
|
|
|
|
|
a L<Workflow::Action> since the workflow state will change once the |
112
|
|
|
|
|
|
|
action has successfully completed. So in the action you create a |
113
|
|
|
|
|
|
|
history object without the state: |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$wf->add_history( |
116
|
|
|
|
|
|
|
Workflow::History->new({ |
117
|
|
|
|
|
|
|
action => "Cocoa Puffs", |
118
|
|
|
|
|
|
|
description => "They're magically delicious", |
119
|
|
|
|
|
|
|
user => "Count Chocula", |
120
|
|
|
|
|
|
|
}) |
121
|
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
And then after the new state has been set but before the history |
124
|
|
|
|
|
|
|
objects are stored the workflow sets the new state in all unsaved |
125
|
|
|
|
|
|
|
history objects. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head3 is_saved() |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Returns true (1) if this history object has been saved, false (0) if not. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 Properties |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=over 4 |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item * |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
B<id> - ID of history entry |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
B<workflow_id> - ID of workflow to which history is attached |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
B<action> - Brief description of action taken |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item * |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
B<description> - Lengthy description of action taken |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
B<date> - Date history noted, set to a L<DateTime> object. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
B<time_zone> - Time zone to pass to the L<DateTime> object. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item * |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
B<user> - User name (ID, login, or full name, up to you) taking action |
162
|
|
|
|
|
|
|
(may be blank) |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
B<state> - State of workflow as history was recorded. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=back |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head3 clear_saved |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Sets saved state to false and returns 0 |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head3 set_saved |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Sets saved state to true and returns 1 |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SEE ALSO |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=over |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * L<Workflow> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 COPYRIGHT |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Copyright (c) 2003-2023 Chris Winters. All rights reserved. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
191
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Please see the F<LICENSE> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 AUTHORS |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Please see L<Workflow> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |