1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
6 # <sales@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
59 RT::Config - RT's config
65 my $config = RT::Config->new;
69 my $rt_web_path = $config->Get('WebPath');
70 $config->Set(EmailOutputEncoding => 'latin1');
72 # get config object from RT package
75 my $config = RT->Config;
79 C<RT::Config> class provide access to RT's and RT extensions' config files.
81 RT uses two files for site configuring:
83 First file is F<RT_Config.pm> - core config file. This file is shipped
84 with RT distribution and contains default values for all available options.
85 B<You should never edit this file.>
87 Second file is F<RT_SiteConfig.pm> - site config file. You can use it
88 to customize your RT instance. In this file you can override any option
89 listed in core config file.
91 RT extensions could also provide thier config files. Extensions should
92 use F<< <NAME>_Config.pm >> and F<< <NAME>_SiteConfig.pm >> names for
93 config files, where <NAME> is extension name.
95 B<NOTE>: All options from RT's config and extensions' configs are saved
96 in one place and thus extension could override RT's options, but it is not
103 Hash of Config options that may be user overridable
104 or may require more logic than should live in RT_*Config.pm
106 Keyed by config name, there are several properties that
107 can be set for each config optin:
109 Section - What header this option should be grouped
110 under on the user Settings page
111 Overridable - Can users change this option
112 SortOrder - Within a Section, how should the options be sorted
113 for display to the user
114 Widget - Mason component path to widget that should be used
115 to display this config option
116 WidgetArguments - An argument hash passed to the WIdget
117 Description - Friendly description to show the user
118 Values - Arrayref of options (for select Widget)
119 ValuesLabel - Hashref, key is the Value from the Values
120 list, value is a user friendly description
122 Callback - subref that receives no arguments. It returns
123 a hashref of items that are added to the rest
124 of the WidgetArguments
125 PostLoadCheck - subref passed the RT::Config object and the current
126 setting of the config option. Can make further checks
127 (such as seeing if a library is installed) and then change
128 the setting of this or other options in the Config using
129 the RT::Config option.
130 Obfuscate - subref passed the RT::Config object, current setting of the config option
131 and a user object, can return obfuscated value. it's called in
132 RT->Config->GetObfuscated()
137 # General user overridable options
139 Section => 'General',
142 Widget => '/Widgets/Form/Select',
144 Description => 'Default queue', #loc
146 my $ret = { Values => [], ValuesLabel => {}};
147 my $q = RT::Queues->new($HTML::Mason::Commands::session{'CurrentUser'});
149 while (my $queue = $q->Next) {
150 next unless $queue->CurrentUserHasRight("CreateTicket");
151 push @{$ret->{Values}}, $queue->Id;
152 $ret->{ValuesLabel}{$queue->Id} = $queue->Name;
158 RememberDefaultQueue => {
159 Section => 'General',
162 Widget => '/Widgets/Form/Boolean',
164 Description => 'Remember default queue' # loc
168 Section => 'General',
171 Widget => '/Widgets/Form/Select',
173 Description => 'Username format', # loc
174 Values => [qw(concise verbose)],
176 concise => 'Short usernames', # loc
177 verbose => 'Name and email address', # loc
181 AutocompleteOwners => {
182 Section => 'General',
185 Widget => '/Widgets/Form/Boolean',
187 Description => 'Use autocomplete to find owners?', # loc
188 Hints => 'Replaces the owner dropdowns with textboxes' #loc
191 WebDefaultStylesheet => {
192 Section => 'General', #loc
195 Widget => '/Widgets/Form/Select',
197 Description => 'Theme', #loc
198 # XXX: we need support for 'get values callback'
199 Values => [qw(web2 aileron ballard)],
201 PostLoadCheck => sub {
203 my $value = $self->Get('WebDefaultStylesheet');
205 my @comp_roots = RT::Interface::Web->ComponentRoots;
206 for my $comp_root (@comp_roots) {
207 return if -d $comp_root.'/NoAuth/css/'.$value;
210 $RT::Logger->warning(
211 "The default stylesheet ($value) does not exist in this instance of RT. "
212 . "Defaulting to aileron."
215 $self->Set('WebDefaultStylesheet', 'aileron');
218 UseSideBySideLayout => {
219 Section => 'Ticket composition',
222 Widget => '/Widgets/Form/Boolean',
224 Description => 'Use a two column layout for create and update forms?' # loc
227 MessageBoxRichText => {
228 Section => 'Ticket composition',
231 Widget => '/Widgets/Form/Boolean',
233 Description => 'WYSIWYG message composer' # loc
236 MessageBoxRichTextHeight => {
237 Section => 'Ticket composition',
240 Widget => '/Widgets/Form/Integer',
242 Description => 'WYSIWYG composer height', # loc
246 Section => 'Ticket composition',
249 Widget => '/Widgets/Form/Integer',
251 Description => 'Message box width', #loc
254 MessageBoxHeight => {
255 Section => 'Ticket composition',
258 Widget => '/Widgets/Form/Integer',
260 Description => 'Message box height', #loc
264 Section => 'Ticket composition', #loc
267 Widget => '/Widgets/Form/Select',
269 Description => 'Message box wrapping', #loc
270 Values => [qw(SOFT HARD)],
271 Hints => "When the WYSIWYG editor is not enabled, this setting determines whether automatic line wraps in the ticket message box are sent to RT or not.", # loc
274 DefaultTimeUnitsToHours => {
275 Section => 'Ticket composition', #loc
278 Widget => '/Widgets/Form/Boolean',
280 Description => 'Enter time in hours by default', #loc
281 Hints => 'Only for entry, not display', #loc
284 SearchResultsRefreshInterval => {
285 Section => 'General', #loc
288 Widget => '/Widgets/Form/Select',
290 Description => 'Search results refresh interval', #loc
291 Values => [qw(0 120 300 600 1200 3600 7200)],
293 0 => "Don't refresh search results.", #loc
294 120 => "Refresh search results every 2 minutes.", #loc
295 300 => "Refresh search results every 5 minutes.", #loc
296 600 => "Refresh search results every 10 minutes.", #loc
297 1200 => "Refresh search results every 20 minutes.", #loc
298 3600 => "Refresh search results every 60 minutes.", #loc
299 7200 => "Refresh search results every 120 minutes.", #loc
304 # User overridable options for RT at a glance
305 HomePageRefreshInterval => {
306 Section => 'RT at a glance', #loc
309 Widget => '/Widgets/Form/Select',
311 Description => 'Home page refresh interval', #loc
312 Values => [qw(0 120 300 600 1200 3600 7200)],
314 0 => "Don't refresh home page.", #loc
315 120 => "Refresh home page every 2 minutes.", #loc
316 300 => "Refresh home page every 5 minutes.", #loc
317 600 => "Refresh home page every 10 minutes.", #loc
318 1200 => "Refresh home page every 20 minutes.", #loc
319 3600 => "Refresh home page every 60 minutes.", #loc
320 7200 => "Refresh home page every 120 minutes.", #loc
325 # User overridable options for Ticket displays
327 Section => 'Ticket display', #loc
330 Widget => '/Widgets/Form/Integer',
332 Description => 'Maximum inline message length', #loc
334 "Length in characters; Use '0' to show all messages inline, regardless of length" #loc
337 OldestTransactionsFirst => {
338 Section => 'Ticket display',
341 Widget => '/Widgets/Form/Boolean',
343 Description => 'Show oldest history first', #loc
346 DeferTransactionLoading => {
347 Section => 'Ticket display',
350 Widget => '/Widgets/Form/Boolean',
352 Description => 'Hide ticket history by default', #loc
355 ShowUnreadMessageNotifications => {
356 Section => 'Ticket display',
359 Widget => '/Widgets/Form/Boolean',
361 Description => 'Notify me of unread messages', #loc
366 Section => 'Ticket display',
369 Widget => '/Widgets/Form/Boolean',
371 Description => 'add <pre> tag around plain text attachments', #loc
372 Hints => "Use this to protect the format of plain text" #loc
376 Section => 'Ticket display',
379 Widget => '/Widgets/Form/Boolean',
381 Description => 'display wrapped and formatted plain text attachments', #loc
382 Hints => 'Use css rules to display text monospaced and with formatting preserved, but wrap as needed. This does not work well with IE6 and you should use the previous option', #loc
385 MoreAboutRequestorTicketList => {
386 Section => 'Ticket display', #loc
389 Widget => '/Widgets/Form/Select',
391 Description => q|What tickets to display in the 'More about requestor' box|, #loc
392 Values => [qw(Active Inactive All None)],
394 Active => "Show the Requestor's 10 highest priority active tickets", #loc
395 Inactive => "Show the Requestor's 10 highest priority inactive tickets", #loc
396 All => "Show the Requestor's 10 highest priority tickets", #loc
397 None => "Show no tickets for the Requestor", #loc
401 SimplifiedRecipients => {
402 Section => 'Ticket display', #loc
405 Widget => '/Widgets/Form/Boolean',
407 Description => q|Show simplified recipient list on ticket update|, #loc
410 DisplayTicketAfterQuickCreate => {
411 Section => 'Ticket display',
414 Widget => '/Widgets/Form/Boolean',
416 Description => q{Display ticket after "Quick Create"}, #loc
420 # User overridable locale options
422 Section => 'Locale', #loc
424 Widget => '/Widgets/Form/Select',
426 Description => 'Date format', #loc
427 Callback => sub { my $ret = { Values => [], ValuesLabel => {}};
428 my $date = RT::Date->new($HTML::Mason::Commands::session{'CurrentUser'});
430 foreach my $value ($date->Formatters) {
431 push @{$ret->{Values}}, $value;
432 $ret->{ValuesLabel}{$value} = $date->Get(
444 PostLoadCheck => sub {
446 my $value = $self->Get('RTAddressRegexp');
449 'The RTAddressRegexp option is not set in the config.'
450 .' Not setting this option results in additional SQL queries to'
451 .' check whether each address belongs to RT or not.'
452 .' It is especially important to set this option if RT recieves'
453 .' emails on addresses that are not in the database or config.'
455 } elsif (ref $value and ref $value eq "Regexp") {
456 # Ensure that the regex is case-insensitive; while the
457 # local part of email addresses is _technically_
458 # case-sensitive, most MTAs don't treat it as such.
459 $RT::Logger->warning(
460 'RTAddressRegexp is set to a case-sensitive regular expression.'
461 .' This may lead to mail loops with MTAs which treat the'
462 .' local part as case-insensitive -- which is most of them.'
463 ) if "$value" =~ /^\(\?[a-z]*-([a-z]*):/ and "$1" =~ /i/;
467 # User overridable mail options
469 Section => 'Mail', #loc
471 Default => 'Individual messages',
472 Widget => '/Widgets/Form/Select',
474 Description => 'Email delivery', #loc
476 'Individual messages', #loc
478 'Weekly digest', #loc
484 Section => 'Mail', #loc
487 Widget => '/Widgets/Form/Boolean',
489 Description => 'Outgoing mail', #loc
490 Hints => 'Should RT send you mail for ticket updates you make?', #loc
494 # this tends to break extensions that stash links in ticket update pages
497 PostLoadCheck => sub {
498 my ($self,$value) = @_;
499 $RT::Logger->error("your \$Organization setting ($value) appears to contain whitespace. Please fix this.")
504 # Internal config options
507 PostLoadCheck => sub {
509 my $v = $self->Get('FullTextSearch');
510 return unless $v->{Enable} and $v->{Indexed};
511 my $dbtype = $self->Get('DatabaseType');
512 if ($dbtype eq 'Oracle') {
513 if (not $v->{IndexName}) {
514 $RT::Logger->error("No IndexName set for full-text index; disabling");
515 $v->{Enable} = $v->{Indexed} = 0;
517 } elsif ($dbtype eq 'Pg') {
519 if (not $v->{'Column'}) {
520 $RT::Logger->error("No Column set for full-text index; disabling");
521 $v->{Enable} = $v->{Indexed} = 0;
522 } elsif ($v->{'Column'} eq "Content"
523 and (not $v->{'Table'} or $v->{'Table'} eq "Attachments")) {
524 $RT::Logger->error("Column for full-text index is set to Content, not tsvector column; disabling");
525 $v->{Enable} = $v->{Indexed} = 0;
527 } elsif ($dbtype eq 'mysql') {
528 if (not $v->{'Table'}) {
529 $RT::Logger->error("No Table set for full-text index; disabling");
530 $v->{Enable} = $v->{Indexed} = 0;
531 } elsif ($v->{'Table'} eq "Attachments") {
532 $RT::Logger->error("Table for full-text index is set to Attachments, not SphinxSE table; disabling");
533 $v->{Enable} = $v->{Indexed} = 0;
534 } elsif (not $v->{'MaxMatches'}) {
535 $RT::Logger->warn("No MaxMatches set for full-text index; defaulting to 10000");
536 $v->{MaxMatches} = 10_000;
539 $RT::Logger->error("Indexed full-text-search not supported for $dbtype");
546 PostLoadCheck => sub {
550 return if $INC{'GraphViz.pm'};
552 return if eval {require GraphViz; 1};
553 $RT::Logger->debug("You've enabled GraphViz, but we couldn't load the module: $@");
554 $self->Set( DisableGraphViz => 1 );
559 PostLoadCheck => sub {
563 return if $INC{'GD.pm'};
565 return if eval {require GD; 1};
566 $RT::Logger->debug("You've enabled GD, but we couldn't load the module: $@");
567 $self->Set( DisableGD => 1 );
570 MailPlugins => { Type => 'ARRAY' },
573 PostLoadCheck => sub {
575 my $value = $self->Get('Plugins');
576 # XXX Remove in RT 4.2
577 return unless $value and grep {$_ eq "RT::FM"} @{$value};
578 warn 'RTFM has been integrated into core RT, and must be removed from your @Plugins';
581 GnuPG => { Type => 'HASH' },
582 GnuPGOptions => { Type => 'HASH',
583 PostLoadCheck => sub {
585 my $gpg = $self->Get('GnuPG');
586 return unless $gpg->{'Enable'};
587 my $gpgopts = $self->Get('GnuPGOptions');
588 unless (-d $gpgopts->{homedir} && -r _ ) { # no homedir, no gpg
590 "RT's GnuPG libraries couldn't successfully read your".
591 " configured GnuPG home directory (".$gpgopts->{homedir}
592 ."). PGP support has been disabled");
593 $gpg->{'Enable'} = 0;
598 require RT::Crypt::GnuPG;
599 unless (RT::Crypt::GnuPG->Probe()) {
601 "RT's GnuPG libraries couldn't successfully execute gpg.".
602 " PGP support has been disabled");
603 $gpg->{'Enable'} = 0;
607 ReferrerWhitelist => { Type => 'ARRAY' },
608 ResolveDefaultUpdateType => {
609 PostLoadCheck => sub {
612 return unless $value;
613 $RT::Logger->info('The ResolveDefaultUpdateType config option has been deprecated. '.
614 'You can change the site default in your %Lifecycles config.');
618 PostLoadCheck => sub {
622 # "In most cases, you should leave $WebPath set to '' (an empty value)."
623 return unless $value;
625 # try to catch someone who assumes that you shouldn't leave this empty
627 $RT::Logger->error("For the WebPath config option, use the empty string instead of /");
631 # $WebPath requires a leading / but no trailing /, or it can be blank.
632 return if $value =~ m{^/.+[^/]$};
634 if ($value =~ m{/$}) {
635 $RT::Logger->error("The WebPath config option requires no trailing slash");
638 if ($value !~ m{^/}) {
639 $RT::Logger->error("The WebPath config option requires a leading slash");
644 PostLoadCheck => sub {
649 $RT::Logger->error("You must set the WebDomain config option");
653 if ($value =~ m{^(\w+://)}) {
654 $RT::Logger->error("The WebDomain config option must not contain a scheme ($1)");
658 if ($value =~ m{(/.*)}) {
659 $RT::Logger->error("The WebDomain config option must not contain a path ($1)");
663 if ($value =~ m{:(\d*)}) {
664 $RT::Logger->error("The WebDomain config option must not contain a port ($1)");
670 PostLoadCheck => sub {
675 $RT::Logger->error("You must set the WebPort config option");
679 if ($value !~ m{^\d+$}) {
680 $RT::Logger->error("The WebPort config option must be an integer");
685 PostLoadCheck => sub {
690 $RT::Logger->error("You must set the WebBaseURL config option");
694 if ($value !~ m{^https?://}i) {
695 $RT::Logger->error("The WebBaseURL config option must contain a scheme (http or https)");
698 if ($value =~ m{/$}) {
699 $RT::Logger->error("The WebBaseURL config option requires no trailing slash");
702 if ($value =~ m{^https?://.+?(/[^/].*)}i) {
703 $RT::Logger->error("The WebBaseURL config option must not contain a path ($1)");
708 PostLoadCheck => sub {
713 $RT::Logger->error("You must set the WebURL config option");
717 if ($value !~ m{^https?://}i) {
718 $RT::Logger->error("The WebURL config option must contain a scheme (http or https)");
721 if ($value !~ m{/$}) {
722 $RT::Logger->error("The WebURL config option requires a trailing slash");
726 EmailInputEncodings => {
728 PostLoadCheck => sub {
730 my $value = $self->Get('EmailInputEncodings');
731 return unless $value && @$value;
734 foreach my $encoding ( grep defined && length, splice @$value ) {
735 next if $seen{ $encoding };
736 if ( $encoding eq '*' ) {
737 unshift @$value, '*';
741 my $canonic = Encode::resolve_alias( $encoding );
742 unless ( $canonic ) {
743 warn "Unknown encoding '$encoding' in \@EmailInputEncodings option";
745 elsif ( $seen{ $canonic }++ ) {
749 push @$value, $canonic;
757 PostLoadCheck => sub {
760 # XXX Remove in RT 4.2
762 The ActiveStatus configuration has been replaced by the new Lifecycles
763 functionality. You should set the 'active' property of the 'default'
764 lifecycle and add transition rules; see RT_Config.pm for documentation.
770 PostLoadCheck => sub {
773 # XXX Remove in RT 4.2
775 The InactiveStatus configuration has been replaced by the new Lifecycles
776 functionality. You should set the 'inactive' property of the 'default'
777 lifecycle and add transition rules; see RT_Config.pm for documentation.
788 Object constructor returns new object. Takes no arguments.
794 my $class = ref($proto) ? ref($proto) : $proto;
795 my $self = bless {}, $class;
812 my %args = ( File => '', @_ );
813 $args{'File'} =~ s/(?<=Config)(?=\.pm$)/Meta/;
819 Load all configs. First of all load RT's config then load
820 extensions' config files in alphabetical order.
828 $self->InitConfig( File => 'RT_Config.pm' );
829 $self->LoadConfig( File => 'RT_Config.pm' );
831 my @configs = $self->Configs;
832 $self->InitConfig( File => $_ ) foreach @configs;
833 $self->LoadConfig( File => $_ ) foreach @configs;
839 Takes param hash with C<File> field.
840 First, the site configuration file is loaded, in order to establish
841 overall site settings like hostname and name of RT instance.
842 Then, the core configuration file is loaded to set fallback values
843 for all settings; it bases some values on settings from the site
846 B<Note> that core config file don't change options if site config
847 has set them so to add value to some option instead of
848 overriding you have to copy original value from core config file.
854 my %args = ( File => '', @_ );
855 $args{'File'} =~ s/(?<!Site)(?=Config\.pm$)/Site/;
856 if ( $args{'File'} eq 'RT_SiteConfig.pm'
857 and my $site_config = $ENV{RT_SITE_CONFIG} )
859 $self->_LoadConfig( %args, File => $site_config );
861 $self->_LoadConfig(%args);
863 $args{'File'} =~ s/Site(?=Config\.pm$)//;
864 $self->_LoadConfig(%args);
870 my %args = ( File => '', @_ );
872 my ($is_ext, $is_site);
873 if ( $args{'File'} eq ($ENV{RT_SITE_CONFIG}||'') ) {
874 ($is_ext, $is_site) = ('', 1);
876 $is_ext = $args{'File'} =~ /^(?!RT_)(?:(.*)_)(?:Site)?Config/ ? $1 : '';
877 $is_site = $args{'File'} =~ /SiteConfig/ ? 1 : 0;
882 local *Set = sub(\[$@%]@) {
883 my ( $opt_ref, @args ) = @_;
884 my ( $pack, $file, $line ) = caller;
885 return $self->SetFromConfig(
891 SiteConfig => $is_site,
892 Extension => $is_ext,
895 my @etc_dirs = ($RT::LocalEtcPath);
896 push @etc_dirs, RT->PluginDirs('etc') if $is_ext;
897 push @etc_dirs, $RT::EtcPath, @INC;
898 local @INC = @etc_dirs;
899 require $args{'File'};
902 return 1 if $is_site && $@ =~ /^Can't locate \Q$args{File}/;
903 if ( $is_site || $@ !~ /^Can't locate \Q$args{File}/ ) {
904 die qq{Couldn't load RT config file $args{'File'}:\n\n$@};
907 my $username = getpwuid($>);
908 my $group = getgrgid($();
910 my ( $file_path, $fileuid, $filegid );
911 foreach ( $RT::LocalEtcPath, $RT::EtcPath, @INC ) {
912 my $tmp = File::Spec->catfile( $_, $args{File} );
913 ( $fileuid, $filegid ) = ( stat($tmp) )[ 4, 5 ];
914 if ( defined $fileuid ) {
919 unless ($file_path) {
921 qq{Couldn't load RT config file $args{'File'} as user $username / group $group.\n}
922 . qq{The file couldn't be found in $RT::LocalEtcPath and $RT::EtcPath.\n$@};
927 RT couldn't load RT config file %s as:
931 The file is owned by user %s and group %s.
933 This usually means that the user/group your webserver is running
934 as cannot read the file. Be careful not to make the permissions
935 on this file too liberal, because it contains database passwords.
936 You may need to put the webserver user in the appropriate group
937 (%s) or change permissions be able to run succesfully.
940 my $fileusername = getpwuid($fileuid);
941 my $filegroup = getgrgid($filegid);
942 my $errormessage = sprintf( $message,
943 $file_path, $fileusername, $filegroup, $filegroup );
944 die "$errormessage\n$@";
951 foreach my $o ( grep $META{$_}{'PostLoadCheck'}, $self->Options( Overridable => undef ) ) {
952 $META{$o}->{'PostLoadCheck'}->( $self, $self->Get($o) );
958 Returns list of config files found in local etc, plugins' etc
959 and main etc directories.
967 foreach my $path ( $RT::LocalEtcPath, RT->PluginDirs('etc'), $RT::EtcPath ) {
968 my $mask = File::Spec->catfile( $path, "*_Config.pm" );
969 my @files = glob $mask;
970 @files = grep !/^RT_Config\.pm$/,
971 grep $_ && /^\w+_Config\.pm$/,
972 map { s/^.*[\\\/]//; $_ } @files;
973 push @configs, sort @files;
977 @configs = grep !$seen{$_}++, @configs;
983 Takes name of the option as argument and returns its current value.
985 In the case of a user-overridable option, first checks the user's
986 preferences before looking for site-wide configuration.
988 Returns values from RT_SiteConfig, RT_Config and then the %META hash
989 of configuration variables's "Default" for this config variable,
992 Returns different things in scalar and array contexts. For scalar
993 options it's not that important, however for arrays and hash it's.
994 In scalar context returns references to arrays and hashes.
996 Use C<scalar> perl's op to force context, especially when you use
997 C<(..., Argument => RT->Config->Get('ArrayOpt'), ...)>
998 as perl's '=>' op doesn't change context of the right hand argument to
999 scalar. Instead use C<(..., Argument => scalar RT->Config->Get('ArrayOpt'), ...)>.
1001 It's also important for options that have no default value(no default
1002 in F<etc/RT_Config.pm>). If you don't force scalar context then you'll
1003 get empty list and all your named args will be messed up. For example
1004 C<(arg1 => 1, arg2 => RT->Config->Get('OptionDoesNotExist'), arg3 => 3)>
1005 will result in C<(arg1 => 1, arg2 => 'arg3', 3)> what is most probably
1006 unexpected, or C<(arg1 => 1, arg2 => RT->Config->Get('ArrayOption'), arg3 => 3)>
1007 will result in C<(arg1 => 1, arg2 => 'element of option', 'another_one' => ..., 'arg3', 3)>.
1012 my ( $self, $name, $user ) = @_;
1015 if ( $user && $user->id && $META{$name}->{'Overridable'} ) {
1016 $user = $user->UserObj if $user->isa('RT::CurrentUser');
1017 my $prefs = $user->Preferences($RT::System);
1018 $res = $prefs->{$name} if $prefs;
1020 $res = $OPTIONS{$name} unless defined $res;
1021 $res = $META{$name}->{'Default'} unless defined $res;
1022 return $self->_ReturnValue( $res, $META{$name}->{'Type'} || 'SCALAR' );
1025 =head2 GetObfuscated
1027 the same as Get, except it returns Obfuscated value via Obfuscate sub
1033 my ( $name, $user ) = @_;
1034 my $obfuscate = $META{$name}->{Obfuscate};
1036 # we use two Get here is to simplify the logic of the return value
1037 # configs need obfuscation are supposed to be less, so won't be too heavy
1039 return $self->Get(@_) unless $obfuscate;
1041 my $res = $self->Get(@_);
1042 $res = $obfuscate->( $self, $res, $user );
1043 return $self->_ReturnValue( $res, $META{$name}->{'Type'} || 'SCALAR' );
1048 Set option's value to new value. Takes name of the option and new value.
1051 The new value should be scalar, array or hash depending on type of the option.
1052 If the option is not defined in meta or the default RT config then it is of
1058 my ( $self, $name ) = ( shift, shift );
1060 my $old = $OPTIONS{$name};
1061 my $type = $META{$name}->{'Type'} || 'SCALAR';
1062 if ( $type eq 'ARRAY' ) {
1063 $OPTIONS{$name} = [@_];
1064 { no warnings 'once'; no strict 'refs'; @{"RT::$name"} = (@_); }
1065 } elsif ( $type eq 'HASH' ) {
1066 $OPTIONS{$name} = {@_};
1067 { no warnings 'once'; no strict 'refs'; %{"RT::$name"} = (@_); }
1069 $OPTIONS{$name} = shift;
1070 {no warnings 'once'; no strict 'refs'; ${"RT::$name"} = $OPTIONS{$name}; }
1072 $META{$name}->{'Type'} = $type;
1073 return $self->_ReturnValue( $old, $type );
1077 my ( $self, $res, $type ) = @_;
1078 return $res unless wantarray;
1080 if ( $type eq 'ARRAY' ) {
1081 return @{ $res || [] };
1082 } elsif ( $type eq 'HASH' ) {
1083 return %{ $res || {} };
1101 unless ( $args{'File'} ) {
1102 ( $args{'Package'}, $args{'File'}, $args{'Line'} ) = caller(1);
1105 my $opt = $args{'Option'};
1108 my $name = $self->__GetNameByRef($opt);
1114 $type = $META{$name}->{'Type'} || 'SCALAR';
1117 # if option is already set we have to check where
1118 # it comes from and may be ignore it
1119 if ( exists $OPTIONS{$name} ) {
1120 if ( $type eq 'HASH' ) {
1122 @{ $args{'Value'} },
1123 @{ $args{'Value'} }%2? (undef) : (),
1124 $self->Get( $name ),
1126 } elsif ( $args{'SiteConfig'} && $args{'Extension'} ) {
1127 # if it's site config of an extension then it can only
1128 # override options that came from its main config
1129 if ( $args{'Extension'} ne $META{$name}->{'Source'}{'Extension'} ) {
1130 my %source = %{ $META{$name}->{'Source'} };
1132 "Change of config option '$name' at $args{'File'} line $args{'Line'} has been ignored."
1133 ." This option earlier has been set in $source{'File'} line $source{'Line'}."
1134 ." To overide this option use ". ($source{'Extension'}||'RT')
1139 } elsif ( !$args{'SiteConfig'} && $META{$name}->{'Source'}{'SiteConfig'} ) {
1140 # if it's core config then we can override any option that came from another
1141 # core config, but not site config
1143 my %source = %{ $META{$name}->{'Source'} };
1144 if ( $source{'Extension'} ne $args{'Extension'} ) {
1145 # as a site config is loaded earlier then its base config
1146 # then we warn only on different extensions, for example
1147 # RTIR's options is set in main site config
1149 "Change of config option '$name' at $args{'File'} line $args{'Line'} has been ignored."
1150 ." It may be ok, but we want you to be aware."
1151 ." This option has been set earlier in $source{'File'} line $source{'Line'}."
1159 $META{$name}->{'Type'} = $type;
1160 foreach (qw(Package File Line SiteConfig Extension)) {
1161 $META{$name}->{'Source'}->{$_} = $args{$_};
1163 $self->Set( $name, @{ $args{'Value'} } );
1168 our %REF_SYMBOLS = (
1178 sub __GetNameByRef {
1182 if ( !$pack && $last_pack ) {
1183 my $tmp = $self->__GetNameByRef( $ref, $last_pack );
1184 return $tmp if $tmp;
1187 $pack .= '::' unless substr( $pack, -2 ) eq '::';
1192 # scan $pack's nametable(hash)
1193 foreach my $k ( keys %{$pack} ) {
1195 # The hash for main:: has a reference to itself
1196 next if $k eq 'main::';
1198 # if the entry has a trailing '::' then
1199 # it is a link to another name space
1200 if ( substr( $k, -2 ) eq '::') {
1201 $name = $self->__GetNameByRef( $ref, $pack eq 'main::'? $k : $pack.$k );
1202 return $name if $name;
1205 # entry of the table with references to
1206 # SCALAR, ARRAY... and other types with
1208 my $entry = ${$pack}{$k};
1211 # get entry for type we are looking for
1212 # XXX skip references to scalars or other references.
1213 # Otherwie 5.10 goes boom. maybe we should skip any
1215 next if ref($entry) eq 'SCALAR' || ref($entry) eq 'REF';
1217 my $ref_type = ref($ref);
1219 # regex/arrayref/hashref/coderef are stored in SCALAR glob
1220 $ref_type = 'SCALAR' if $ref_type eq 'REF';
1222 my $entry_ref = *{$entry}{ $ref_type };
1223 next unless $entry_ref;
1225 # if references are equal then we've found
1226 if ( $entry_ref == $ref ) {
1228 return ( $REF_SYMBOLS{ $ref_type } || '*' ) . $pack . $k;
1243 return $META{ $_[1] };
1251 map $_->{'Section'} || 'General',
1258 my %args = ( Section => undef, Overridable => 1, Sorted => 1, @_ );
1259 my @res = keys %META;
1261 @res = grep( ( $META{$_}->{'Section'} || 'General' ) eq $args{'Section'},
1263 ) if defined $args{'Section'};
1265 if ( defined $args{'Overridable'} ) {
1267 = grep( ( $META{$_}->{'Overridable'} || 0 ) == $args{'Overridable'},
1271 if ( $args{'Sorted'} ) {
1273 ($META{$a}->{SortOrder}||9999) <=> ($META{$b}->{SortOrder}||9999)
1277 @res = sort { $a cmp $b } @res;
1282 =head2 AddOption( Name => '', Section => '', ... )
1293 Widget => '/Widgets/Form/String',
1294 WidgetArguments => {},
1298 unless ( $args{Name} ) {
1299 $RT::Logger->error("Need Name to add a new config");
1303 unless ( $args{Section} ) {
1304 $RT::Logger->error("Need Section to add a new config option");
1308 $META{ delete $args{Name} } = \%args;
1311 =head2 DeleteOption( Name => '' )
1321 if ( $args{Name} ) {
1322 delete $META{$args{Name}};
1325 $RT::Logger->error("Need Name to remove a config option");
1330 =head2 UpdateOption( Name => '' ), Section => '', ... )
1339 Overridable => undef,
1342 WidgetArguments => undef,
1346 my $name = delete $args{Name};
1349 $RT::Logger->error("Need Name to update a new config");
1353 unless ( exists $META{$name} ) {
1354 $RT::Logger->error("Config $name doesn't exist");
1358 for my $type ( keys %args ) {
1359 next unless defined $args{$type};
1360 $META{$name}{$type} = $args{$type};
1365 RT::Base->_ImportOverlays();