summaryrefslogtreecommitdiff
path: root/FS/FS/UI
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2015-08-04 11:16:41 -0700
committerMark Wells <mark@freeside.biz>2015-08-04 11:52:57 -0700
commitce1a26f5033acf26ccf0c922b2fc43cc2baa2bb9 (patch)
treee146ac70e272749658fe146e522931ad83a79269 /FS/FS/UI
parent908d425750365b7a2bf59334ccfc41adc9d61a17 (diff)
de-randomization fixes for testing, #37340
Conflicts: FS/FS/Conf.pm
Diffstat (limited to 'FS/FS/UI')
-rw-r--r--FS/FS/UI/Web.pm33
1 files changed, 32 insertions, 1 deletions
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