rename WebExternalAutoInfo to WebRemoteUserAutocreateInfo, #37318
[freeside.git] / rt / lib / RT / Queue_Local.pm
1 package RT::Queue;
2
3 use strict;
4 use warnings;
5
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
12
13 my %changes = (
14     'SavedSearch' => sub {
15         my ($attr, $old, $new) = @_;
16         # Deal with queue names containing single quotes.
17         $old =~ s/'/\\'/g;
18         $new =~ s/'/\\'/g;
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);
23         }
24         -1;
25     },
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);
33     },
34 );
35
36 sub SetName {
37     my $self = shift;
38     my $new = shift;
39
40     # We may potentially change anything at all.
41     unless ( $self->CurrentUser->HasRight(
42         Right => 'SuperUser', Object => 'RT::System' )
43     ) {
44         return ( 0, $self->loc("SuperUser access required to rename queues") );
45     }
46
47     $RT::Handle->BeginTransaction();
48     my $old = $self->Name;
49     my ($err, $msg) = $self->SUPER::SetName($new);
50     unless ($err) {
51         $RT::Handle->Rollback;
52         return (0, "Unable to rename queue to '$new': $msg");
53     }
54     foreach my $attrname (keys %changes) {
55         my $Attributes = RT::Attributes->new($self->CurrentUser);
56         $Attributes->UnLimit;
57         foreach my $attr ( $Attributes->Named($attrname) ) {
58             ($err, $msg) = &{ $changes{$attrname} }($attr, $old, $new);
59             unless ($err) {
60                 $RT::Handle->Rollback;
61                 return (0, "Unable to change attribute $attrname - ".
62                     $attr->Description.  ": $msg");
63             }
64         }
65     }
66     RT->System->QueueCacheNeedsUpdate(1);
67     $RT::Handle->Commit;
68     return 1, "Name changed from '$old' to '$new'";
69 }
70
71
72 1;