diff options
author | ivan <ivan> | 2004-03-03 13:44:27 +0000 |
---|---|---|
committer | ivan <ivan> | 2004-03-03 13:44:27 +0000 |
commit | ae15d56440f45d4c97584d768194eef60a0b9136 (patch) | |
tree | 20c5b488dcf74514a7f16c9f999c255fe4ccef58 /FS/FS | |
parent | 63fe62db7bb1acf1f78683ff530a1dc122ffb496 (diff) |
fix welcome emails being sent to signup server declined accounts, closes: Bug#743
Diffstat (limited to 'FS/FS')
-rw-r--r-- | FS/FS/ClientAPI/Signup.pm | 37 | ||||
-rw-r--r-- | FS/FS/cust_main.pm | 62 | ||||
-rw-r--r-- | FS/FS/cust_pkg.pm | 3 | ||||
-rw-r--r-- | FS/FS/queue.pm | 47 | ||||
-rw-r--r-- | FS/FS/svc_Common.pm | 64 | ||||
-rw-r--r-- | FS/FS/svc_acct.pm | 36 | ||||
-rw-r--r-- | FS/FS/svc_domain.pm | 10 | ||||
-rw-r--r-- | FS/FS/svc_forward.pm | 10 | ||||
-rw-r--r-- | FS/FS/svc_www.pm | 11 |
9 files changed, 234 insertions, 46 deletions
diff --git a/FS/FS/ClientAPI/Signup.pm b/FS/FS/ClientAPI/Signup.pm index 375958b9c..4655b0984 100644 --- a/FS/FS/ClientAPI/Signup.pm +++ b/FS/FS/ClientAPI/Signup.pm @@ -4,6 +4,7 @@ use strict; use Tie::RefHash; use FS::Conf; use FS::Record qw(qsearch qsearchs dbdef); +use FS::Msgcat qw(gettext); use FS::agent; use FS::cust_main_county; use FS::part_pkg; @@ -12,7 +13,7 @@ use FS::cust_main; use FS::cust_pkg; use FS::svc_acct; use FS::acct_snarf; -use FS::Msgcat qw(gettext); +use FS::queue; use FS::ClientAPI; #hmm FS::ClientAPI->register_handlers( @@ -171,7 +172,8 @@ sub new_customer { my @acct_snarf; my $snarfnum = 1; - while ( length($packet->{"snarf_machine$snarfnum"}) ) { + while ( exists($packet->{"snarf_machine$snarfnum"}) + && length($packet->{"snarf_machine$snarfnum"}) ) { my $acct_snarf = new FS::acct_snarf ( { 'machine' => $packet->{"snarf_machine$snarfnum"}, 'protocol' => $packet->{"snarf_protocol$snarfnum"}, @@ -189,12 +191,28 @@ sub new_customer { $error = $svc_acct->check; return { 'error' => $error } if $error; + #setup a job dependancy to delay provisioning + my $placeholder = new FS::queue ( { + 'job' => 'FS::ClientAPI::Signup::__placeholder', + 'status' => 'locked', + } ); + $error = $placeholder->insert; + return { 'error' => $error } if $error; + use Tie::RefHash; tie my %hash, 'Tie::RefHash'; %hash = ( $cust_pkg => [ $svc_acct ] ); #msgcat - $error = $cust_main->insert( \%hash, \@invoicing_list, 'noexport' => 1 ); - return { 'error' => $error } if $error; + $error = $cust_main->insert( + \%hash, + \@invoicing_list, + 'depend_jobnum' => $placeholder->jobnum, + ); + if ( $error ) { + my $perror = $placeholder->delete; + $error .= " (Additionally, error removing placeholder: $perror)" if $perror; + return { 'error' => $error }; + } if ( $conf->exists('signup_server-realtime') ) { @@ -222,11 +240,20 @@ sub new_customer { local $FS::svc_Common::noexport_hack = 1; $cust_main->cancel('quiet'=>1); + my $perror = $placeholder->depended_delete; + warn "error removing provisioning jobs after decline: $perror" if $perror; + unless ( $perror ) { + $perror = $placeholder->delete; + warn "error removing placeholder after decline: $perror" if $perror; + } + return { 'error' => '_decline' }; } } - $cust_main->reexport; + + $error = $placeholder->delete; + return { 'error' => $error } if $error; return { error => '' }; diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 986fef3a5..53ed4c59b 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1,7 +1,7 @@ package FS::cust_main; use strict; -use vars qw( @ISA $conf $Debug $import ); +use vars qw( @ISA $conf $DEBUG $import ); use Safe; use Carp; BEGIN { @@ -38,8 +38,8 @@ use FS::Msgcat qw(gettext); @ISA = qw( FS::Record ); -$Debug = 0; -#$Debug = 1; +$DEBUG = 0; +#$DEBUG = 1; $import = 0; @@ -223,10 +223,16 @@ invoicing_list destination to the newly-created svc_acct. Here's an example: $cust_main->insert( {}, [ $email, 'POST' ] ); -Currently available options are: I<noexport> +Currently available options are: I<depend_jobnum> and I<noexport>. -If I<noexport> is set true, no provisioning jobs (exports) are scheduled. -(You can schedule them later with the B<reexport> method.) +If I<depend_jobnum> is set, all provisioning jobs will have a dependancy +on the supplied jobnum (they will not run until the specific job completes). +This can be used to defer provisioning until some action completes (such +as running the customer's credit card sucessfully). + +The I<noexport> option is deprecated. If I<noexport> is set true, no +provisioning jobs (exports) are scheduled. (You can schedule them later with +the B<reexport> method.) =cut @@ -235,6 +241,9 @@ sub insert { my $cust_pkgs = @_ ? shift : {}; my $invoicing_list = @_ ? shift : ''; my %options = @_; + warn "FS::cust_main::insert called with options ". + join(', ', map { "$_: $options{$_}" } keys %options ). "\n" + if $DEBUG; local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -286,7 +295,6 @@ sub insert { } # packages - #local $FS::svc_Common::noexport_hack = 1 if $options{'noexport'}; $error = $self->order_pkgs($cust_pkgs, \$seconds, %options); if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -321,7 +329,7 @@ sub insert { } -=item order_pkgs HASHREF, [ , OPTION => VALUE ... ] ] +=item order_pkgs HASHREF, [ SECONDSREF, [ , OPTION => VALUE ... ] ] Like the insert method on an existing record, this method orders a package and included services atomicaly. Pass a Tie::RefHash data structure to this @@ -334,14 +342,20 @@ be a better explanation of this, but until then, here's an example: $cust_pkg => [ $svc_acct ], ... ); - $cust_main->order_pkgs( \%hash, 'noexport'=>1 ); + $cust_main->order_pkgs( \%hash, \'0', 'noexport'=>1 ); + +Currently available options are: I<depend_jobnum> and I<noexport>. -Currently available options are: I<noexport> +If I<depend_jobnum> is set, all provisioning jobs will have a dependancy +on the supplied jobnum (they will not run until the specific job completes). +This can be used to defer provisioning until some action completes (such +as running the customer's credit card sucessfully). -If I<noexport> is set true, no provisioning jobs (exports) are scheduled. -(You can schedule them later with the B<reexport> method for each -cust_pkg object. Using the B<reexport> method on the cust_main object is not -recommended, as existing services will also be reexported.) +The I<noexport> option is deprecated. If I<noexport> is set true, no +provisioning jobs (exports) are scheduled. (You can schedule them later with +the B<reexport> method for each cust_pkg object. Using the B<reexport> method +on the cust_main object is not recommended, as existing services will also be +reexported.) =cut @@ -350,6 +364,12 @@ sub order_pkgs { my $cust_pkgs = shift; my $seconds = shift; my %options = @_; + my %svc_options = (); + $svc_options{'depend_jobnum'} = $options{'depend_jobnum'} + if exists $options{'depend_jobnum'}; + warn "FS::cust_main::order_pkgs called with options ". + join(', ', map { "$_: $options{$_}" } keys %options ). "\n" + if $DEBUG; local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -377,7 +397,7 @@ sub order_pkgs { $svc_something->seconds( $svc_something->seconds + $$seconds ); $$seconds = 0; } - $error = $svc_something->insert; + $error = $svc_something->insert(%svc_options); if ( $error ) { $dbh->rollback if $oldAutoCommit; #return "inserting svc_ (transaction rolled back): $error"; @@ -392,6 +412,9 @@ sub order_pkgs { =item reexport +This method is deprecated. See the I<depend_jobnum> option to the insert and +order_pkgs methods for a better way to defer provisioning. + Re-schedules all exports by calling the B<reexport> method of all associated packages (see L<FS::cust_pkg>). If there is an error, returns the error; otherwise returns false. @@ -401,6 +424,9 @@ otherwise returns false. sub reexport { my $self = shift; + carp "warning: FS::cust_main::reexport is deprectated; ". + "use the depend_jobnum option to insert or order_pkgs to delay export"; + local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; local $SIG{QUIT} = 'IGNORE'; @@ -1454,7 +1480,7 @@ sub collect { my $dbh = dbh; my $balance = $self->balance; - warn "collect customer". $self->custnum. ": balance $balance" if $Debug; + warn "collect customer". $self->custnum. ": balance $balance" if $DEBUG; unless ( $balance > 0 ) { #redundant????? $dbh->rollback if $oldAutoCommit; #hmm return ''; @@ -1480,7 +1506,7 @@ sub collect { last if $self->balance <= 0; warn "invnum ". $cust_bill->invnum. " (owed ". $cust_bill->owed. ")" - if $Debug; + if $DEBUG; foreach my $part_bill_event ( sort { $a->seconds <=> $b->seconds @@ -1501,7 +1527,7 @@ sub collect { || $self->balance <= 0; # or if balance<=0 warn "calling invoice event (". $part_bill_event->eventcode. ")\n" - if $Debug; + if $DEBUG; my $cust_main = $self; #for callback my $error; diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm index c147f0926..a62c44e00 100644 --- a/FS/FS/cust_pkg.pm +++ b/FS/FS/cust_pkg.pm @@ -637,6 +637,9 @@ sub attribute_since_sqlradacct { =item reexport +This method is deprecated. See the I<depend_jobnum> option to the insert and +order_pkgs methods in FS::cust_main for a better way to defer provisioning. + =cut sub reexport { diff --git a/FS/FS/queue.pm b/FS/FS/queue.pm index d35dc883f..68a48634c 100644 --- a/FS/FS/queue.pm +++ b/FS/FS/queue.pm @@ -1,7 +1,7 @@ package FS::queue; use strict; -use vars qw( @ISA @EXPORT_OK $conf $jobnums); +use vars qw( @ISA @EXPORT_OK $DEBUG $conf $jobnums); use Exporter; use FS::UID; use FS::Conf; @@ -14,6 +14,9 @@ use FS::cust_svc; @ISA = qw(FS::Record); @EXPORT_OK = qw( joblisting ); +$DEBUG = 0; +#$DEBUG = 1; + $FS::UID::callback{'FS::queue'} = sub { $conf = new FS::Conf; }; @@ -120,7 +123,10 @@ sub insert { } } - push @$jobnums, $self->jobnum if $jobnums; + if ( $jobnums ) { + warn "jobnums global is active: $jobnums\n" if $DEBUG; + push @$jobnums, $self->jobnum; + } $dbh->commit or die $dbh->errstr if $oldAutoCommit; @@ -239,6 +245,7 @@ sub cust_svc { =item queue_depend Returns the FS::queue_depend objects associated with this job, if any. +(Dependancies that must complete before this job can be run). =cut @@ -247,7 +254,6 @@ sub queue_depend { qsearch('queue_depend', { 'jobnum' => $self->jobnum } ); } - =item depend_insert OTHER_JOBNUM Inserts a dependancy for this job - it will not be run until the other job @@ -268,6 +274,39 @@ sub depend_insert { $queue_depend->insert; } +=item queue_depended + +Returns the FS::queue_depend objects that associate other jobs with this job, +if any. (The jobs that are waiting for this job to complete before they can +run). + +=cut + +sub queue_depended { + my $self = shift; + qsearch('queue_depend', { 'depend_jobnum' => $self->jobnum } ); +} + +=item depended_delete + +Deletes the other queued jobs (FS::queue objects) that are waiting for this +job, if any. If there is an error, returns the error, otherwise returns false. + +=cut + +sub depended_delete { + my $self = shift; + my $error; + foreach my $job ( + map { qsearchs('queue', { 'jobnum' => $_->jobnum } ) } $self->queue_depended + ) { + $error = $job->depended_delete; + return $error if $error; + $error = $job->delete; + return $error if $error + } +} + =back =head1 SUBROUTINES @@ -385,7 +424,7 @@ END =head1 VERSION -$Id: queue.pm,v 1.15 2002-07-02 06:48:59 ivan Exp $ +$Id: queue.pm,v 1.15.4.1 2004-03-03 13:44:27 ivan Exp $ =head1 BUGS diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index a4011f049..315b7c074 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -1,7 +1,7 @@ package FS::svc_Common; use strict; -use vars qw( @ISA $noexport_hack ); +use vars qw( @ISA $noexport_hack $DEBUG ); use FS::Record qw( qsearchs fields dbh ); use FS::cust_svc; use FS::part_svc; @@ -9,6 +9,9 @@ use FS::queue; @ISA = qw( FS::Record ); +$DEBUG = 0; +#$DEBUG = 1; + =head1 NAME FS::svc_Common - Object method for all svc_ records @@ -28,7 +31,7 @@ inherit from, i.e. FS::svc_acct. FS::svc_Common inherits from FS::Record. =over 4 -=item insert [ JOBNUM_ARRAYREF [ OBJECTS_ARRAYREF ] ] +=item insert [ , OPTION => VALUE ... ] Adds this record to the database. If there is an error, returns the error, otherwise returns false. @@ -36,19 +39,36 @@ otherwise returns false. The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be defined. An FS::cust_svc record will be created and inserted. -If an arrayref is passed as parameter, the B<jobnum>s of any export jobs will -be added to the array. +Currently available options are: I<jobnums>, I<child_objects> and +I<depend_jobnum>. + +If I<jobnum> is set to an array reference, the jobnums of any export jobs will +be added to the referenced array. + +If I<child_objects> is set to an array reference of FS::tablename objects (for +example, FS::acct_snarf objects), they will have their svcnum fieldsset and +will be inserted after this record, but before any exports are run. -If an arrayref of FS::tablename objects (for example, FS::acct_snarf objects) -is passed as the optional second parameter, they will have their svcnum fields -set and will be inserted after this record, but before any exports are run. +If I<depend_jobnum> is set (to a scalar jobnum or an array reference of +jobnums), all provisioning jobs will have a dependancy on the supplied +jobnum(s) (they will not run until the specific job(s) complete(s)). =cut sub insert { my $self = shift; - local $FS::queue::jobnums = shift if @_; - my $objects = scalar(@_) ? shift : []; + my %options = @_; + warn "FS::svc_Common::insert called with options ". + join(', ', map { "$_: $options{$_}" } keys %options ). "\n" + if $DEBUG; + + my @jobnums = (); + local $FS::queue::jobnums = \@jobnums; + warn "FS::svc_Common::insert: set \$FS::queue::jobnums to $FS::queue::jobnums" + if $DEBUG; + my $objects = $options{'child_objects'} || []; + my $depend_jobnums = $options{'depend_jobnum'} || []; + $depend_jobnums = [ $depend_jobnums ] unless ref($depend_jobnums); my $error; local $SIG{HUP} = 'IGNORE'; @@ -108,6 +128,10 @@ sub insert { #new-style exports! unless ( $noexport_hack ) { + + warn "FS::svc_Common::insert: \$FS::queue::jobnums is $FS::queue::jobnums" + if $DEBUG; + foreach my $part_export ( $self->cust_svc->part_svc->part_export ) { my $error = $part_export->export_insert($self); if ( $error ) { @@ -116,6 +140,26 @@ sub insert { " (transaction rolled back): $error"; } } + + foreach my $depend_jobnum ( @$depend_jobnums ) { + warn "inserting dependancies on supplied job $depend_jobnum\n" + if $DEBUG; + foreach my $jobnum ( @jobnums ) { + my $queue = qsearchs('queue', { 'jobnum' => $jobnum } ); + warn "inserting dependancy for job $jobnum on $depend_jobnum\n" + if $DEBUG; + my $error = $queue->depend_insert($depend_jobnum); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error queuing job dependancy: $error"; + } + } + } + + } + + if ( exists $options{'jobnums'} ) { + push @{ $options{'jobnums'} }, @jobnums; } $dbh->commit or die $dbh->errstr if $oldAutoCommit; @@ -404,7 +448,7 @@ sub clone_kludge_unsuspend { =head1 VERSION -$Id: svc_Common.pm,v 1.12.4.5 2004-02-23 08:12:54 ivan Exp $ +$Id: svc_Common.pm,v 1.12.4.6 2004-03-03 13:44:27 ivan Exp $ =head1 BUGS diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index e49c2ebe7..9ff26b8e8 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -36,6 +36,7 @@ use FS::Msgcat qw(gettext); @ISA = qw( FS::svc_Common ); $DEBUG = 0; +#$DEBUG = 1; $me = '[FS::svc_acct]'; #ask FS::UID to run this stuff for us later @@ -180,7 +181,7 @@ Creates a new account. To add the account to the database, see L<"insert">. sub table { 'svc_acct'; } -=item insert +=item insert [ , OPTION => VALUE ... ] Adds this account to the database. If there is an error, returns the error, otherwise returns false. @@ -197,15 +198,21 @@ should contain an arrayref of FS::tablename objects. They will have their svcnum fields set and will be inserted after this record, but before any exports are run. +Currently available options are: I<depend_jobnum> + +If I<depend_jobnum> is set (to a scalar jobnum or an array reference of +jobnums), all provisioning jobs will have a dependancy on the supplied +jobnum(s) (they will not run until the specific job(s) complete(s)). + (TODOC: L<FS::queue> and L<freeside-queued>) (TODOC: new exports!) - =cut sub insert { my $self = shift; + my %options = @_; my $error; local $SIG{HUP} = 'IGNORE'; @@ -329,7 +336,11 @@ sub insert { #see? i told you it was more complicated my @jobnums; - $error = $self->SUPER::insert(\@jobnums, $self->child_objects || [] ); + $error = $self->SUPER::insert( + 'jobnums' => \@jobnums, + 'child_objects' => $self->child_objects, + %options, + ); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -399,6 +410,22 @@ sub insert { return "error queuing welcome email: $error"; } + if ( $options{'depend_jobnum'} ) { + warn "$me depend_jobnum found; adding to welcome email dependancies" + if $DEBUG; + if ( ref($options{'depend_jobnum'}) ) { + warn "$me adding jobs ". join(', ', @{$options{'depend_jobnum'}} ). + "to welcome email dependancies" + if $DEBUG; + push @jobnums, @{ $options{'depend_jobnum'} }; + } else { + warn "$me adding job $options{'depend_jobnum'} ". + "to welcome email dependancies" + if $DEBUG; + push @jobnums, $options{'depend_jobnum'}; + } + } + foreach my $jobnum ( @jobnums ) { my $error = $wqueue->depend_insert($jobnum); if ( $error ) { @@ -1291,6 +1318,9 @@ counterintuitive. radius_usergroup_selector? putting web ui components in here? they should probably live somewhere else... +insertion of RADIUS group stuff in insert could be done with child_objects now +(would probably clean up export of them too) + =head1 SEE ALSO L<FS::svc_Common>, edit/part_svc.cgi from an installed web interface, diff --git a/FS/FS/svc_domain.pm b/FS/FS/svc_domain.pm index 58e4c790b..f457a7679 100644 --- a/FS/FS/svc_domain.pm +++ b/FS/FS/svc_domain.pm @@ -90,7 +90,7 @@ Creates a new domain. To add the domain to the database, see L<"insert">. sub table { 'svc_domain'; } -=item insert +=item insert [ , OPTION => VALUE ... ] Adds this domain to the database. If there is an error, returns the error, otherwise returns false. @@ -116,6 +116,12 @@ If any records are defined in the I<defaultrecords> configuration file, appropriate records are added to the domain_record table (see L<FS::domain_record>). +Currently available options are: I<depend_jobnum> + +If I<depend_jobnum> is set (to a scalar jobnum or an array reference of +jobnums), all provisioning jobs will have a dependancy on the supplied +jobnum(s) (they will not run until the specific job(s) complete(s)). + =cut sub insert { @@ -149,7 +155,7 @@ sub insert { return "Domain not found (see whois)"; } - $error = $self->SUPER::insert; + $error = $self->SUPER::insert(@_); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; diff --git a/FS/FS/svc_forward.pm b/FS/FS/svc_forward.pm index 2b1fb9225..5ec396143 100644 --- a/FS/FS/svc_forward.pm +++ b/FS/FS/svc_forward.pm @@ -66,7 +66,7 @@ database, see L<"insert">. sub table { 'svc_forward'; } -=item insert +=item insert [ , OPTION => VALUE ... ] Adds this mail forwarding alias to the database. If there is an error, returns the error, otherwise returns false. @@ -74,6 +74,12 @@ the error, otherwise returns false. The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be defined. An FS::cust_svc record will be created and inserted. +Currently available options are: I<depend_jobnum> + +If I<depend_jobnum> is set (to a scalar jobnum or an array reference of +jobnums), all provisioning jobs will have a dependancy on the supplied +jobnum(s) (they will not run until the specific job(s) complete(s)). + =cut sub insert { @@ -94,7 +100,7 @@ sub insert { $error = $self->check; return $error if $error; - $error = $self->SUPER::insert; + $error = $self->SUPER::insert(@_); if ($error) { $dbh->rollback if $oldAutoCommit; return $error; diff --git a/FS/FS/svc_www.pm b/FS/FS/svc_www.pm index d7a42c8ae..2e9ab8522 100644 --- a/FS/FS/svc_www.pm +++ b/FS/FS/svc_www.pm @@ -74,7 +74,7 @@ points to. You can ask the object for a copy with the I<hash> method. sub table { 'svc_www'; } -=item insert +=item insert [ , OPTION => VALUE ... ] Adds this record to the database. If there is an error, returns the error, otherwise returns false. @@ -82,6 +82,13 @@ otherwise returns false. The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be defined. An FS::cust_svc record will be created and inserted. +Currently available options are: I<depend_jobnum> + +If I<depend_jobnum> is set (to a scalar jobnum or an array reference of +jobnums), all provisioning jobs will have a dependancy on the supplied +jobnum(s) (they will not run until the specific job(s) complete(s)). + + =cut sub insert { @@ -124,7 +131,7 @@ sub insert { $self->recnum($domain_record->recnum); } - $error = $self->SUPER::insert; + $error = $self->SUPER::insert(@_); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; |