diff options
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Conf.pm | 7 | ||||
-rw-r--r-- | FS/FS/Mason.pm | 2 | ||||
-rw-r--r-- | FS/FS/Record.pm | 1 | ||||
-rw-r--r-- | FS/FS/UI/Web.pm | 33 |
4 files changed, 41 insertions, 2 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 2e52db7be..eec6febbb 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -6071,6 +6071,13 @@ and customer address. Include units.', { key => "vonage-password", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" }, { key => "vonage-fromnumber", section => "deprecated", description => "<b>DEPRECATED</b>", type => "text" }, + { + 'key' => 'no_random_ids', + 'section' => '', + 'description' => 'Replace random identifiers in UI code with a static string, for repeatable testing. Don\'t use in production.', + 'type' => 'checkbox', + }, + ); 1; diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index aa98ad32a..467eb6ab1 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -136,7 +136,7 @@ if ( -e $addl_handler_use_file ) { use FS::Conf; use FS::CGI qw(header menubar table itable ntable idiot eidiot myexit http_header); - use FS::UI::Web qw(svc_url); + use FS::UI::Web qw(svc_url random_id); use FS::UI::Web::small_custview qw(small_custview); use FS::UI::bytecount; use FS::Msgcat qw(gettext geterror); diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 72745fe13..ef0d88d80 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -519,6 +519,7 @@ sub qsearch { # Check for encrypted fields and decrypt them. ## only in the local copy, not the cached object + no warnings 'deprecated'; # XXX silence the warning for now if ( $conf_encryption && eval 'defined(@FS::'. $table . '::encrypted_fields)' ) { foreach my $record (@return) { diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm index b301e99b5..69de5e157 100644 --- a/FS/FS/UI/Web.pm +++ b/FS/FS/UI/Web.pm @@ -15,11 +15,13 @@ use FS::cust_main; # are sql_balance and sql_date_balance in the right module? #@ISA = qw( FS::UI ); @ISA = qw( Exporter ); -@EXPORT_OK = qw( svc_url ); +@EXPORT_OK = qw( svc_url random_id ); $DEBUG = 0; $me = '[FS::UID::Web]'; +our $NO_RANDOM_IDS; + ### # date parsing ### @@ -608,6 +610,35 @@ sub is_mobile { return 0; } +=item random_id [ DIGITS ] + +Returns a random number of length DIGITS, or if unspecified, a long random +identifier consisting of the timestamp, process ID, and a random number. +Anything in the UI that needs a random identifier should use this. + +=cut + +sub random_id { + my $digits = shift; + if (!defined $NO_RANDOM_IDS) { + my $conf = FS::Conf->new; + $NO_RANDOM_IDS = $conf->exists('no_random_ids') ? 1 : 0; + } + if ( $NO_RANDOM_IDS ) { + if ( $digits > 0 ) { + return 0; + } else { + return '0000000000-0000-000000000.000000'; + } + } else { + if ($digits > 0) { + return int(rand(10 ** $digits)); + } else { + return time . "-$$-" . rand() * 2**32; + } + } +} + =back =cut |