first pass RT4 merge, RT#13852
[freeside.git] / rt / etc / upgrade / 3.9.1 / content
1 @Initial = (
2     sub {
3         use strict;
4         $RT::Logger->debug('Make sure templates all have known types');
5
6         # We update all NULL rows, below.  We want to find non-NULL
7         # rows, which weren't created by the current codebase running
8         # through earlier initialdatas.  Type != 'Perl' enforces the
9         # non-NULL part, as well
10         my $templates = RT::Templates->new(RT->SystemUser);
11         $templates->Limit(
12             FIELD => 'Type',
13             OPERATOR => '!=',
14             VALUE => 'Perl',
15         );
16
17         if ($templates->Count) {
18             die "You have templates with Type already set. This will interfere with your upgrade because RT used to ignore the template Type field, but now uses it.";
19         }
20
21         $templates = RT::Templates->new(RT->SystemUser);
22         $templates->Limit(
23             FIELD => 'Type',
24             OPERATOR => 'IS',
25             VALUE => 'NULL',
26         );
27         while (my $template = $templates->Next) {
28             my ($status, $msg) = $template->SetType('Perl');
29             $RT::Logger->warning( "Couldn't change Type of Template #" . $template->Id . ": $msg" ) unless $status;
30         }
31     },
32     sub {
33         use strict;
34         $RT::Logger->debug('Adding ExecuteCode right to principals that currently have ModifyTemplate or ModifyScrips');
35
36         my $acl = RT::ACL->new(RT->SystemUser);
37         $acl->Limit(
38             FIELD           => 'RightName',
39             OPERATOR        => '=',
40             VALUE           => 'ModifyTemplate',
41             ENTRYAGGREGATOR => 'OR',
42         );
43         $acl->Limit(
44             FIELD           => 'RightName',
45             OPERATOR        => '=',
46             VALUE           => 'ModifyScrips',
47             ENTRYAGGREGATOR => 'OR',
48         );
49
50         while (my $ace = $acl->Next) {
51             my $principal = $ace->PrincipalObj;
52             next if $principal->HasRight(
53                 Right  => 'ExecuteCode',
54                 Object => $RT::System,
55             );
56
57             my ($ok, $msg) = $principal->GrantRight(
58                 Right  => 'ExecuteCode',
59                 Object => $RT::System,
60             );
61
62             if (!$ok) {
63                 $RT::Logger->warn("Unable to grant ExecuteCode on principal " . $principal->id . ": $msg");
64             }
65         }
66     },
67 );
68