6 # Adjust various saved settings that might have the old queue name in them.
7 # $changes{'AttributeName'} = sub (attribute, old queue name, new queue name)
8 # where the sub changes any reference to the old name to the new name
9 # returning a positive value on success,
10 # or (0, error string) if it fails somehow
11 # or -1 if the old name isn't found
14 'SavedSearch' => sub {
15 my ($attr, $old, $new) = @_;
16 # Deal with queue names containing single quotes.
19 my $string = $attr->SubValue('Query');
20 # Deal with queue names containing regex metacharacters.
21 if ( $string =~ s/Queue\W+\K'\Q$old\E'/'$new'/ ) {
22 return $attr->SetSubValues(Query => $string);
26 'Pref-QuickSearch' => sub {
27 my ($attr, $old, $new) = @_;
28 my $x = $attr->SubValue($old);
29 return -1 if !defined($x);
30 my @err = $attr->DeleteSubValue($old);
31 return @err if !$err[0];
32 return $attr->SetSubValues($new => $x);
40 # We may potentially change anything at all.
41 unless ( $self->CurrentUser->HasRight(
42 Right => 'SuperUser', Object => 'RT::System' )
44 return ( 0, $self->loc("SuperUser access required to rename queues") );
47 $RT::Handle->BeginTransaction();
48 my $old = $self->Name;
49 my ($err, $msg) = $self->SUPER::SetName($new);
51 $RT::Handle->Rollback;
52 return (0, "Unable to rename queue to '$new': $msg");
54 foreach my $attrname (keys %changes) {
55 my $Attributes = RT::Attributes->new($self->CurrentUser);
57 foreach my $attr ( $Attributes->Named($attrname) ) {
58 ($err, $msg) = &{ $changes{$attrname} }($attr, $old, $new);
60 $RT::Handle->Rollback;
61 return (0, "Unable to change attribute $attrname - ".
62 $attr->Description. ": $msg");
66 RT->System->QueueCacheNeedsUpdate(1);
68 return 1, "Name changed from '$old' to '$new'";