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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
use strict;
use warnings;
my $move_attributes = sub {
my ($table, $type, $column) = @_;
my $query = "UPDATE $table SET $column = (SELECT Content FROM Attributes WHERE"
." Name = ? AND ObjectType = ? AND $table.id = Attributes.ObjectId)";
my $res = RT->DatabaseHandle->SimpleQuery( $query, $column, $type );
unless ( $res ) {
RT->Logger->error("Failed to move $column on $type from Attributes into $table table");
return;
}
$query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?';
$res = RT->DatabaseHandle->SimpleQuery( $query, $column, $type );
unless ( $res ) {
RT->Logger->error("Failed to delete $column on $type from Attributes");
return;
}
return 1;
};
our @Initial = (
sub {
return $move_attributes->( 'Users', 'RT::User', 'AuthToken');
},
sub {
return $move_attributes->( 'CustomFields', 'RT::CustomField', 'RenderType');
},
sub {
my $cfs = RT::CustomFields->new( RT->SystemUser );
$cfs->UnLimit;
$cfs->FindAllRows;
while ( my $cf = $cfs->Next ) {
# Explicitly remove 'ORDER BY id asc' to emulate the
# previous functionality, where Pg might return the the
# rows in arbitrary order
$cf->Attributes->OrderByCols();
my $attr = $cf->FirstAttribute('BasedOn');
next unless $attr;
$cf->SetBasedOn($attr->Content);
}
my $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?';
my $res = RT->DatabaseHandle->SimpleQuery( $query, 'BasedOn', 'RT::CustomField' );
unless ( $res ) {
RT->Logger->error("Failed to delete BasedOn CustomFields from Attributes");
return;
}
return 1;
},
sub {
$move_attributes->( 'CustomFields', 'RT::CustomField', 'ValuesClass')
or return;
my $query = "UPDATE CustomFields SET ValuesClass = NULL WHERE ValuesClass = ?";
my $res = RT->DatabaseHandle->SimpleQuery( $query, 'RT::CustomFieldValues' );
unless ( $res ) {
RT->Logger->error("Failed to replace default with NULLs");
return;
}
return 1;
},
sub {
my $attr = RT->System->FirstAttribute('BrandedSubjectTag');
return 1 unless $attr;
my $map = $attr->Content || {};
while ( my ($qid, $tag) = each %$map ) {
my $queue = RT::Queue->new( RT->SystemUser );
$queue->Load( $qid );
unless ( $queue->id ) {
RT->Logger->warning("Couldn't load queue #$qid. Skipping...");
next;
}
my ($status, $msg) = $queue->SetSubjectTag($tag);
unless ( $status ) {
RT->Logger->error("Couldn't set subject tag for queue #$qid: $msg");
next;
}
}
},
);
|