From ce1a26f5033acf26ccf0c922b2fc43cc2baa2bb9 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Tue, 4 Aug 2015 11:16:41 -0700 Subject: de-randomization fixes for testing, #37340 Conflicts: FS/FS/Conf.pm --- FS/FS/UI/Web.pm | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'FS/FS/UI') diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm index 6655f27..13b2e2d 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 -- cgit v1.1