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