X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fqueue.pm;h=4b880a23c2dfa8cdf40dc349fb3b170c074ead4d;hb=fca110eff969104793774ed717985e91c53f5318;hp=13e6f92c1f1c25d0be46408fd355d44f72a3d229;hpb=4c61cd25bdb4dfaeb083b3605ce3ef4d3157fe1b;p=freeside.git diff --git a/FS/FS/queue.pm b/FS/FS/queue.pm index 13e6f92c1..4b880a23c 100644 --- a/FS/FS/queue.pm +++ b/FS/FS/queue.pm @@ -1,11 +1,21 @@ package FS::queue; use strict; -use vars qw( @ISA ); +use vars qw( @ISA @EXPORT_OK $conf ); +use Exporter; +use FS::UID; +use FS::Conf; use FS::Record qw( qsearch qsearchs dbh ); +#use FS::queue; use FS::queue_arg; +use FS::cust_svc; @ISA = qw(FS::Record); +@EXPORT_OK = qw( joblisting ); + +$FS::UID::callback{'FS::queue'} = sub { + $conf = new FS::Conf; +}; =head1 NAME @@ -39,6 +49,12 @@ FS::Record. The following fields are currently supported: =item status - job status +=item statustext - freeform text status message + +=item _date - UNIX timestamp + +=item svcnum - optional link to service (see L) + =back =head1 METHODS @@ -68,6 +84,7 @@ created (see L). =cut +#false laziness w/part_export.pm sub insert { my $self = shift; @@ -127,7 +144,7 @@ sub delete { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my @args = $self->args; + my @args = qsearch( 'queue_arg', { 'jobnum' => $self->jobnum } ); my $error = $self->SUPER::delete; if ( $error ) { @@ -173,9 +190,14 @@ sub check { || $self->ut_anything('job') || $self->ut_numbern('_date') || $self->ut_enum('status',['', qw( new locked failed )]) + || $self->ut_textn('statustext') + || $self->ut_numbern('svcnum') ; return $error if $error; + $error = $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum'); + $self->svcnum('') if $error; + $self->status('new') unless $self->status; $self->_date(time) unless $self->_date; @@ -195,11 +217,104 @@ sub args { ); } +=item cust_svc + +Returns the FS::cust_svc object associated with this job, if any. + +=cut + +sub cust_svc { + my $self = shift; + qsearchs('cust_svc', { 'svcnum' => $self->svcnum } ); +} + +=item joblisting HASHREF NOACTIONS + +=cut + +sub joblisting { + my($hashref, $noactions) = @_; + + use Date::Format; + use FS::CGI; + + my @queue = qsearch( 'queue', $hashref ); + return '' unless scalar(@queue); + + my $html = FS::CGI::table(). < + Job + Args + Date + Status +END + $html .= 'Account' unless $hashref->{svcnum}; + $html .= ''; + + my $dangerous = $conf->exists('queue_dangerous_controls'); + + my $p = FS::CGI::popurl(2); + foreach my $queue ( sort { + $a->getfield('jobnum') <=> $b->getfield('jobnum') + } @queue ) { + my $queue_hashref = $queue->hashref; + my $jobnum = $queue->jobnum; + + my $args; + if ( $dangerous || $queue->job !~ /^FS::part_export::/ || !$noactions ) { + $args = join(' ', $queue->args); + } else { + $args = ''; + } + + my $date = time2str( "%a %b %e %T %Y", $queue->_date ); + my $status = $queue->status; + $status .= ': '. $queue->statustext if $queue->statustext; + if ( $dangerous + || ( ! $noactions && $status =~ /^failed/ || $status =~ /^locked/ ) ) { + $status .= + qq! ( retry |!. + qq! remove )!; + } + my $cust_svc = $queue->cust_svc; + + $html .= < + $jobnum + $queue_hashref->{job} + $args + $date + $status +END + + unless ( $hashref->{svcnum} ) { + my $account; + if ( $cust_svc ) { + my $table = $cust_svc->part_svc->svcdb; + my $label = ( $cust_svc->label )[1]; + $account = qq!$label!; + } else { + $account = ''; + } + $html .= "$account"; + } + + $html .= ''; + +} + + $html .= ''; + + $html; + +} + =back =head1 VERSION -$Id: queue.pm,v 1.2 2001-09-11 12:24:13 ivan Exp $ +$Id: queue.pm,v 1.10 2002-03-27 07:08:08 ivan Exp $ =head1 BUGS