summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2005-01-27 10:21:18 +0000
committerivan <ivan>2005-01-27 10:21:18 +0000
commit6cf964d0dc008621fb30fd2da28e2c44f29c6364 (patch)
tree74fd5536bb89960db22d03cc95b6374711de60ef /FS
parente4ae5122522f2d45c68a38eaef337a82029f2fc1 (diff)
DHTML progress bar for glacial rate adding and editing, closes: Bug#1100
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/UID.pm2
-rw-r--r--FS/FS/queue.pm35
-rw-r--r--FS/FS/rate.pm213
-rw-r--r--FS/bin/freeside-queued11
4 files changed, 239 insertions, 22 deletions
diff --git a/FS/FS/UID.pm b/FS/FS/UID.pm
index 3d893ee..c0c9f7a 100644
--- a/FS/FS/UID.pm
+++ b/FS/FS/UID.pm
@@ -98,7 +98,7 @@ sub forksuidsetup {
}
sub myconnect {
- $dbh = DBI->connect( getsecrets, {'AutoCommit' => 0, 'ChopBlanks' => 1, } )
+ DBI->connect( getsecrets, {'AutoCommit' => 0, 'ChopBlanks' => 1, } )
or die "DBI->connect error: $DBI::errstr\n";
}
diff --git a/FS/FS/queue.pm b/FS/FS/queue.pm
index dcac3c6..f42d998 100644
--- a/FS/FS/queue.pm
+++ b/FS/FS/queue.pm
@@ -3,7 +3,7 @@ package FS::queue;
use strict;
use vars qw( @ISA @EXPORT_OK $DEBUG $conf $jobnums);
use Exporter;
-use FS::UID;
+use FS::UID qw(myconnect);
use FS::Conf;
use FS::Record qw( qsearch qsearchs dbh );
#use FS::queue;
@@ -15,7 +15,6 @@ use FS::cust_svc;
@EXPORT_OK = qw( joblisting );
$DEBUG = 0;
-#$DEBUG = 1;
$FS::UID::callback{'FS::queue'} = sub {
$conf = new FS::Conf;
@@ -307,6 +306,38 @@ sub depended_delete {
}
}
+=item update_statustext VALUE
+
+Updates the statustext value of this job to supplied value, in the database.
+If there is an error, returns the error, otherwise returns false.
+
+=cut
+
+use vars qw($_update_statustext_dbh);
+sub update_statustext {
+ my( $self, $statustext ) = @_;
+ return '' if $statustext eq $self->statustext;
+ warn "updating statustext for $self to $statustext" if $DEBUG;
+
+ $_update_statustext_dbh ||= myconnect;
+
+ my $sth = $_update_statustext_dbh->prepare(
+ 'UPDATE queue set statustext = ? WHERE jobnum = ?'
+ ) or return $_update_statustext_dbh->errstr;
+
+ $sth->execute($statustext, $self->jobnum) or return $sth->errstr;
+ $_update_statustext_dbh->commit or die $_update_statustext_dbh->errstr;
+ $self->statustext($statustext);
+ '';
+
+ #my $new = new FS::queue { $self->hash };
+ #$new->statustext($statustext);
+ #my $error = $new->replace($self);
+ #return $error if $error;
+ #$self->statustext($statustext);
+ #'';
+}
+
=back
=head1 SUBROUTINES
diff --git a/FS/FS/rate.pm b/FS/FS/rate.pm
index b8a6940..7f625a6 100644
--- a/FS/FS/rate.pm
+++ b/FS/FS/rate.pm
@@ -1,12 +1,14 @@
package FS::rate;
use strict;
-use vars qw( @ISA );
-use FS::Record qw( qsearch qsearchs dbh );
+use vars qw( @ISA $DEBUG );
+use FS::Record qw( qsearch qsearchs dbh fields );
use FS::rate_detail;
@ISA = qw(FS::Record);
+$DEBUG = 1;
+
=head1 NAME
FS::rate - Object methods for rate records
@@ -94,13 +96,32 @@ sub insert {
}
if ( $options{'rate_detail'} ) {
+
+ my( $num, $last, $min_sec ) = (0, time, 5); #progressbar foo
+
foreach my $rate_detail ( @{$options{'rate_detail'}} ) {
+
$rate_detail->ratenum($self->ratenum);
$error = $rate_detail->insert;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return $error;
}
+
+ if ( $options{'job'} ) {
+ $num++;
+ if ( time - $min_sec > $last ) {
+ my $error = $options{'job'}->update_statustext(
+ int( 100 * $num / scalar( @{$options{'rate_detail'}} ) )
+ );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ $last = time;
+ }
+ }
+
}
}
@@ -148,8 +169,8 @@ sub replace {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
- my @old_rate_detail = ();
- @old_rate_detail = $old->rate_detail if $options{'rate_detail'};
+# my @old_rate_detail = ();
+# @old_rate_detail = $old->rate_detail if $options{'rate_detail'};
my $error = $new->SUPER::replace($old);
if ($error) {
@@ -157,21 +178,67 @@ sub replace {
return $error;
}
- foreach my $old_rate_detail ( @old_rate_detail ) {
- my $error = $old_rate_detail->delete;
- if ($error) {
+# foreach my $old_rate_detail ( @old_rate_detail ) {
+#
+# my $error = $old_rate_detail->delete;
+# if ($error) {
+# $dbh->rollback if $oldAutoCommit;
+# return $error;
+# }
+#
+# if ( $options{'job'} ) {
+# $num++;
+# if ( time - $min_sec > $last ) {
+# my $error = $options{'job'}->update_statustext(
+# int( 50 * $num / scalar( @old_rate_detail ) )
+# );
+# if ( $error ) {
+# $dbh->rollback if $oldAutoCommit;
+# return $error;
+# }
+# $last = time;
+# }
+# }
+#
+# }
+ if ( $options{'rate_detail'} ) {
+ my $sth = $dbh->prepare('DELETE FROM rate_detail WHERE ratenum = ?') or do {
$dbh->rollback if $oldAutoCommit;
- return $error;
- }
- }
-
- foreach my $rate_detail ( @{$options{'rate_detail'}} ) {
- $rate_detail->ratenum($new->ratenum);
- $error = $rate_detail->insert;
- if ( $error ) {
+ return $dbh->errstr;
+ };
+
+ $sth->execute($old->ratenum) or do {
$dbh->rollback if $oldAutoCommit;
- return $error;
+ return $sth->errstr;
+ };
+
+ my( $num, $last, $min_sec ) = (0, time, 5); #progresbar foo
+# $num = 0;
+ foreach my $rate_detail ( @{$options{'rate_detail'}} ) {
+
+ $rate_detail->ratenum($new->ratenum);
+ $error = $rate_detail->insert;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ if ( $options{'job'} ) {
+ $num++;
+ if ( time - $min_sec > $last ) {
+ my $error = $options{'job'}->update_statustext(
+ int( 100 * $num / scalar( @{$options{'rate_detail'}} ) )
+ );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ $last = time;
+ }
+ }
+
}
+
}
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
@@ -230,6 +297,120 @@ sub rate_detail {
=back
+=head1 SUBROUTINES
+
+=over 4
+
+=item process
+
+Experimental job-queue processor for web interface adds/edits
+
+=cut
+
+sub process {
+ my $job = shift;
+
+ #my %param = @_;
+
+ my $param = shift;
+ my %param = split(/[;=]/, $param);
+
+ my $old = qsearchs('rate', { 'ratenum' => $param{'ratenum'} } )
+ if $param{'ratenum'};
+
+ my @rate_detail = map {
+
+ my $regionnum = $_->regionnum;
+ if ( $param{"sec_granularity$regionnum"} ) {
+
+ new FS::rate_detail {
+ 'dest_regionnum' => $regionnum,
+ map { $_ => $param{"$_$regionnum"} }
+ qw( min_included min_charge sec_granularity )
+ };
+
+ } else {
+
+ new FS::rate_detail {
+ 'dest_regionnum' => $regionnum,
+ 'min_included' => 0,
+ 'min_charge' => 0,
+ 'sec_granularity' => '60'
+ };
+
+ }
+
+ } qsearch('rate_region', {} );
+
+ my $rate = new FS::rate {
+ map { $_ => $param{$_} }
+ fields('rate')
+ };
+
+ my $error = '';
+ if ( $param{'ratenum'} ) {
+ warn "$rate replacing $old ($param{'ratenum'})\n" if $DEBUG;
+ $error = $rate->replace( $old,
+ 'rate_detail' => \@rate_detail,
+ 'job' => $job,
+ );
+ } else {
+ warn "inserting $rate\n" if $DEBUG;
+ $error = $rate->insert( 'rate_detail' => \@rate_detail,
+ 'job' => $job,
+ );
+ #$ratenum = $rate->getfield('ratenum');
+ }
+
+ die $error if $error;
+
+}
+
+# begin JSRPC code...
+
+package FS::rate::JSRPC;
+use vars qw(@ISA $DEBUG);
+use JavaScript::RPC::Server::CGI;
+use FS::UID;
+@ISA = qw( JavaScript::RPC::Server::CGI );
+$DEBUG = 1;
+
+sub process_rate {
+ my $self = shift;
+
+ my %param = @_;
+ warn "FS::rate::JSRPC::process_rate\n".
+ join('', map " $_ => $param{$_}\n", keys %param )
+ if $DEBUG;
+
+ #progressbar prototype code... should be generalized
+
+ #first get the CGI params shipped off to a job ASAP so an id can be returned
+ #to the caller
+
+ my $job = new FS::queue { 'job' => 'FS::rate::process' };
+
+ #too slow to insert all the cgi params as individual args..,?
+ #my $error = $queue->insert('_JOB', $cgi->Vars);
+
+ #my $bigstring = join(';', map { "$_=". scalar($cgi->param($_)) } $cgi->param );
+ my $bigstring = join(';', map { "$_=". $param{$_} } keys %param );
+ my $error = $job->insert('_JOB', $bigstring);
+
+ if ( $error ) {
+ $error;
+ } else {
+ $job->jobnum;
+ }
+
+}
+
+sub get_new_query {
+ FS::UID::cgi();
+}
+
+# end JSRPC code...
+
=head1 BUGS
=head1 SEE ALSO
diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued
index e14ddad..a3fb7e5 100644
--- a/FS/bin/freeside-queued
+++ b/FS/bin/freeside-queued
@@ -87,7 +87,7 @@ while (1) {
unless ( dbh && dbh->ping ) {
warn "WARNING: connection to database lost, reconnecting...\n";
- eval { myconnect; };
+ eval { $FS::UID::dbh = myconnect; };
unless ( !$@ && dbh && dbh->ping ) {
warn "WARNING: still no connection to database, sleeping for retry...\n";
@@ -162,6 +162,7 @@ while (1) {
#}
my @args = $ljob->args;
+ splice @args, 0, 1, $ljob if $args[0] eq '_JOB';
defined( my $pid = fork ) or do {
warn "WARNING: can't fork: $!\n";
@@ -184,8 +185,12 @@ while (1) {
forksuidsetup($user);
- #auto-use export classes...
- if ( $ljob->job =~ /(FS::part_export::\w+)::/ ) {
+ #auto-use classes...
+ #if ( $ljob->job =~ /(FS::part_export::\w+)::/ ) {
+ if ( $ljob->job =~ /(FS::part_export::\w+)::/
+ || $ljob->job =~ /(FS::\w+)::/
+ )
+ {
my $class = $1;
eval "use $class;";
if ( $@ ) {