@Initial = (
    sub {
        use strict;
        $RT::Logger->debug('Make sure templates all have known types');

        my $templates = RT::Templates->new(RT->SystemUser);
        $templates->Limit(
            FIELD => 'Type',
            OPERATOR => '!=',
            VALUE => 'Action',
            ENTRYAGGREGATOR => 'AND'
        );
        $templates->Limit(
            FIELD => 'Type',
            OPERATOR => '!=',
            VALUE => 'Perl',
            ENTRYAGGREGATOR => 'AND'
        );

        if ($templates->Count) {
            die "You have templates with Type other than Action. This will interfere with your upgrade because RT used to ignore the template Type field, but now uses it.";
        }

        $templates = RT::Templates->new(RT->SystemUser);
        $templates->UnLimit();
        while (my $template = $templates->Next) {
            my ($status, $msg) = $template->SetType('Perl');
            $RT::Logger->warning( "Couldn't change Type of Template #" . $template->Id . ": $msg" ) unless $status;
        }
    },
    sub {
        use strict;
        $RT::Logger->debug('Adding ExecuteCode right to principals that currently have ModifyTemplate or ModifyScrips');

        my $acl = RT::ACL->new(RT->SystemUser);
        $acl->Limit(
            FIELD           => 'RightName',
            OPERATOR        => '=',
            VALUE           => 'ModifyTemplate',
            ENTRYAGGREGATOR => 'OR',
        );
        $acl->Limit(
            FIELD           => 'RightName',
            OPERATOR        => '=',
            VALUE           => 'ModifyScrips',
            ENTRYAGGREGATOR => 'OR',
        );

        while (my $ace = $acl->Next) {
            my $principal = $ace->PrincipalObj;
            next if $principal->HasRight(
                Right  => 'ExecuteCode',
                Object => $RT::System,
            );

            my ($ok, $msg) = $principal->GrantRight(
                Right  => 'ExecuteCode',
                Object => $RT::System,
            );

            if (!$ok) {
                $RT::Logger->warn("Unable to grant ExecuteCode on principal " . $principal->id . ": $msg");
            }
        }
    },
);

