summaryrefslogtreecommitdiff
path: root/rt/etc/upgrade/4.1.1/content
blob: f3580bdc049328451fe6e8f8c459d6a59067ed6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strict;
use warnings;

our @Initial = (
    sub {
        require RT::ObjectScrips;
        foreach my $stage ('TransactionCreate', 'TransactionBatch') {
            my $applications = RT::ObjectScrips->new( RT->SystemUser );
            $applications->Limit( FIELD => 'Stage', VALUE => $stage );
            my $alias = $applications->Join(
                FIELD1 => 'Scrip',
                TABLE2 => 'Scrips', FIELD2 => 'id'
            );
            $applications->OrderByCols(
                { ALIAS => $alias, FIELD => 'Description', ORDER => 'ASC' },
            );
            my %h; my $top_so = $h{0} = 0;
            while ( my $record = $applications->Next ) {
                my $oid = $record->ObjectId || 0;

                my $so;
                unless ( $oid ) {
                    %h = (); $h{0} = $so = ++$top_so;
                }
                else {
                    $so = $h{ $oid } = ($h{$oid}||$h{0}) + 1;
                }
                next if $record->SortOrder == $so;

                my ($status, $msg) = $record->SetSortOrder($so);
                RT->Logger->error("Couldn't set sort order: $msg")
                    unless $status;
            }
        }
    },
);