Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / etc / upgrade / 4.2.11 / 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         # Remove globally-granted role rights which couldn't also apply
17         # to some other object.  That is, globally granting that
18         # AdminCcs have SuperUser makes no sense.
19
20         # Find rights which apply globally
21         no warnings 'once';
22         my @rights = sort map {$_->{Name}} values %{$RT::ACE::RIGHTS{'RT::System'}};
23
24         # Those are not allowed to be granted on global role groups
25         my $invalid = RT::ACL->new( RT->SystemUser );
26         $invalid->LimitToObject( 'RT::System' );
27         $invalid->LimitToPrincipal( Id => RT::System->RoleGroup($_)->PrincipalId )
28             for RT::System->Roles;
29         $invalid->Limit( FIELD => 'RightName', OPERATOR => 'IN', VALUE => \@rights );
30
31         return unless $invalid->Count;
32
33         # Remove them, warning in the process
34         $RT::Logger->warning("There are invalid global role rights; removing:");
35         while (my $right = $invalid->Next) {
36             $RT::Logger->warning("  ".$right->RightName." granted globally to ".$right->PrincipalObj->Object->Name);
37             my ($ok, $msg) = $right->Delete;
38             $RT::Logger->error("Failed to remove right ".$right->id.": $msg") unless $ok;
39         }
40     },
41     sub {
42         my $txns = RT::Transactions->new(RT->SystemUser);
43         $txns->Limit( FIELD => 'Type', VALUE => 'Forward Transaction' );
44         $txns->Limit( FIELD => 'Type', VALUE => 'Forward Ticket' );
45         while ( my $txn = $txns->Next ) {
46             my $att = $txn->Attachments->First;
47             next unless $att;
48
49             # we only need to process ascii-only strings
50             unless ( $att->Subject =~ /[^\x00-\x7F]/ ) {
51                 $att->__Set( Field => 'Subject', Value => Encode::decode("UTF-8", RT::I18N::DecodeMIMEWordsToUTF8($att->Subject, 'Subject')) );
52             }
53             for my $field ( qw/Subject From To Cc Bcc/ ) {
54                 next if !$att->GetHeader($field) || $att->GetHeader($field) =~ /[^\x00-\x7F]/;
55                 # Subject here is not a typo, because we don't really want to parse email addresses here
56                 $att->SetHeader( $field, Encode::decode("UTF-8", RT::I18N::DecodeMIMEWordsToUTF8($att->GetHeader($field), 'Subject')) );
57             }
58         }
59     },
60 );