Putting 4.2.0 on top of 4.0.17
[usit-rt.git] / etc / upgrade / 3.8.2 / content
CommitLineData
af59614d
MKG
1use strict;
2use warnings;
3
4our @Initial = (
01e3b242 5 sub {
af59614d 6 RT->Logger->warning(
01e3b242
MKG
7 "Going to add [OLD] prefix to all templates in approvals queue."
8 ." If you have never used approvals, you can safely delete all the"
9 ." templates with the [OLD] prefix. Leave the new Approval templates because"
10 ." you may eventually want to start using approvals."
11 );
12
13 my $approvals_q = RT::Queue->new( RT->SystemUser );
14 $approvals_q->Load('___Approvals');
15 unless ( $approvals_q->id ) {
af59614d 16 RT->Logger->error("You have no approvals queue.");
01e3b242
MKG
17 return 1;
18 }
19
20 my $templates = RT::Templates->new( RT->SystemUser );
21 $templates->LimitToQueue( $approvals_q->id );
22 while ( my $tmpl = $templates->Next ) {
23 my ($status, $msg) = $tmpl->SetName( "[OLD] ". $tmpl->Name );
24 unless ( $status ) {
af59614d 25 RT->Logger->error("Couldn't rename template #". $tmpl->id .": $msg");
01e3b242
MKG
26 }
27 }
28 return 1;
29 },
af59614d
MKG
30
31 sub {
32 my $group = RT::Group->new( RT->SystemUser );
33 $group->DBIx::SearchBuilder::Record::LoadByCols(
34 Domain => 'SystemInternal',
35 Type => 'Privileged',
36 );
37 unless ($group->id) {
38 RT->Logger->warn("Failed to load Privilged group");
39 return;
40 }
41 my ( $return, $msg ) = $group->PrincipalObj->GrantRight(
42 Right => 'ShowApprovalsTab',
43 Object => RT->System,
44 );
45 RT->Logger->warn("Failed to grant ShowApprovalsTab right: $msg")
46 unless $return;
47 },
01e3b242
MKG
48);
49
af59614d 50our @Templates = (
01e3b242
MKG
51 { Queue => '___Approvals',
52 Name => "New Pending Approval", # loc
53 Description =>
54 "Notify Owners and AdminCcs of new items pending their approval", # loc
55 Content => 'Subject: New Pending Approval: {$Ticket->Subject}
56
57Greetings,
58
59There is a new item pending your approval: "{$Ticket->Subject()}",
60a summary of which appears below.
61
62Please visit {RT->Config->Get(\'WebURL\')}Approvals/Display.html?id={$Ticket->id}
63to approve or reject this ticket, or {RT->Config->Get(\'WebURL\')}Approvals/ to
64batch-process all your pending approvals.
65
66-------------------------------------------------------------------------
67{$Transaction->Content()}
68'
69 },
70 { Queue => '___Approvals',
71 Name => "Approval Passed", # loc
72 Description =>
73 "Notify Requestor of their ticket has been approved by some approver", # loc
74 Content => 'Subject: Ticket Approved: {$Ticket->Subject}
75
76Greetings,
77
78Your ticket has been approved by { eval { $Approval->OwnerObj->Name } }.
79Other approvals may be pending.
80
81Approver\'s notes: { $Notes }
82'
83 },
84 { Queue => '___Approvals',
85 Name => "All Approvals Passed", # loc
86 Description =>
87 "Notify Requestor of their ticket has been approved by all approvers", # loc
88 Content => 'Subject: Ticket Approved: {$Ticket->Subject}
89
90Greetings,
91
92Your ticket has been approved by { eval { $Approval->OwnerObj->Name } }.
93Its Owner may now start to act on it.
94
95Approver\'s notes: { $Notes }
96'
97 },
98 { Queue => '___Approvals',
99 Name => "Approval Rejected", # loc
100 Description =>
101 "Notify Owner of their rejected ticket", # loc
102 Content => 'Subject: Ticket Rejected: {$Ticket->Subject}
103
104Greetings,
105
106Your ticket has been rejected by { eval { $Approval->OwnerObj->Name } }.
107
108Approver\'s notes: { $Notes }
109'
110 },
111 { Queue => '___Approvals',
112 Name => "Approval Ready for Owner", # loc
113 Description =>
114 "Notify Owner of their ticket has been approved and is ready to be acted on", # loc
115 Content => 'Subject: Ticket Approved: {$Ticket->Subject}
116
117Greetings,
118
119The ticket has been approved, you may now start to act on it.
120
121'
122 },
123);
124
af59614d 125our @Final = (
01e3b242 126 sub {
af59614d 127 RT->Logger->debug("Going to adjust dashboards");
01e3b242
MKG
128 my $sys = RT::System->new(RT->SystemUser);
129
130 my $attrs = RT::Attributes->new( RT->SystemUser );
131 $attrs->UnLimit;
132 my @dashboards = $attrs->Named('Dashboard');
133
134 if (@dashboards == 0) {
af59614d 135 RT->Logger->debug("You have no dashboards. Skipped.");
01e3b242
MKG
136 return 1;
137 }
138
139 for my $attr (@dashboards) {
140 my $props = $attr->Content;
141 if (exists $props->{Searches}) {
142 $props->{Panes} = {
143 body => [
144 map {
145 my ($privacy, $id, $desc) = @$_;
146
147 {
148 portlet_type => 'search',
149 privacy => $privacy,
150 id => $id,
151 description => $desc,
152 pane => 'body',
153 }
154 } @{ delete $props->{Searches} }
155 ],
156 };
157 }
158 my ($status, $msg) = $attr->SetContent( $props );
af59614d 159 RT->Logger->error($msg) unless $status;
01e3b242
MKG
160 }
161
af59614d 162 RT->Logger->debug("Fixed.");
01e3b242
MKG
163 return 1;
164 },
165 sub {
166 my $approvals_q = RT::Queue->new( RT->SystemUser );
167 $approvals_q->Load('___Approvals');
168 unless ( $approvals_q->id ) {
af59614d 169 RT->Logger->error("You have no approvals queue.");
01e3b242
MKG
170 return 1;
171 }
172
173 require File::Temp;
174 my ($tmp_fh, $tmp_fn) = File::Temp::tempfile( 'rt-approvals-scrips-XXXX', CLEANUP => 0 );
175 unless ( $tmp_fh ) {
af59614d 176 RT->Logger->error("Couldn't create temporary file.");
01e3b242
MKG
177 return 0;
178 }
179
af59614d 180 RT->Logger->warning(
01e3b242
MKG
181 "IMPORTANT: We're going to delete all scrips in Approvals queue"
182 ." and save them in '$tmp_fn' file."
183 );
184
185 require Data::Dumper;
186
187 my $scrips = RT::Scrips->new( RT->SystemUser );
af59614d
MKG
188 $scrips->{'with_disabled_column'} = 0;
189 $scrips->Limit( FIELD => 'Queue', VALUE => $approvals_q->id );
01e3b242
MKG
190 while ( my $scrip = $scrips->Next ) {
191 my %tmp =
af59614d
MKG
192 map { $_ => $scrip->_Value( $_ ) }
193 qw/id Description ScripCondition ScripAction
194 CustomIsApplicableCode CustomPrepareCode CustomCommitCode
195 Stage Queue Template Creator Created LastUpdatedBy LastUpdated/;
01e3b242
MKG
196
197 print $tmp_fh Data::Dumper::Dumper( \%tmp );
198
af59614d 199 my ($status, $msg) = $scrip->DBIx::SearchBuilder::Record::Delete;
01e3b242 200 unless ( $status ) {
af59614d 201 RT->Logger->error( "Couldn't delete scrip: $msg");
01e3b242
MKG
202 }
203 }
204 },
205);