[freeside-commits] freeside/FS/FS Record.pm, 1.145, 1.146 cust_svc.pm, 1.68, 1.69
Ivan,,,
ivan at wavetail.420.am
Sat Oct 27 20:55:29 PDT 2007
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv6521/FS/FS
Modified Files:
Record.pm cust_svc.pm
Log Message:
mysql me harder
Index: cust_svc.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_svc.pm,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- cust_svc.pm 21 Apr 2007 04:44:57 -0000 1.68
+++ cust_svc.pm 28 Oct 2007 03:55:26 -0000 1.69
@@ -4,7 +4,7 @@
use vars qw( @ISA $DEBUG $me $ignore_quantity );
use Carp;
use FS::Conf;
-use FS::Record qw( qsearch qsearchs dbh );
+use FS::Record qw( qsearch qsearchs dbh str2time_sql );
use FS::cust_pkg;
use FS::part_pkg;
use FS::part_svc;
@@ -428,17 +428,8 @@
or die "can't connect to sqlradius database: ". $DBI::errstr;
#select a unix time conversion function based on database type
- my $str2time;
- if ( $dbh->{Driver}->{Name} =~ /^mysql(PP)?$/ ) {
- $str2time = 'UNIX_TIMESTAMP(';
- } elsif ( $dbh->{Driver}->{Name} eq 'Pg' ) {
- $str2time = 'EXTRACT( EPOCH FROM ';
- } else {
- warn "warning: unknown database type ". $dbh->{Driver}->{Name}.
- "; guessing how to convert to UNIX timestamps";
- $str2time = 'extract(epoch from ';
- }
-
+ my $str2time = str2time_sql( $dbh->{Driver}->{Name} );
+
my $username = $part_export->export_username($svc_x);
my $query;
@@ -538,16 +529,7 @@
or die "can't connect to sqlradius database: ". $DBI::errstr;
#select a unix time conversion function based on database type
- my $str2time;
- if ( $dbh->{Driver}->{Name} =~ /^mysql(PP)?$/ ) {
- $str2time = 'UNIX_TIMESTAMP(';
- } elsif ( $dbh->{Driver}->{Name} eq 'Pg' ) {
- $str2time = 'EXTRACT( EPOCH FROM ';
- } else {
- warn "warning: unknown database type ". $dbh->{Driver}->{Name}.
- "; guessing how to convert to UNIX timestamps";
- $str2time = 'extract(epoch from ';
- }
+ my $str2time = str2time_sql( $dbh->{Driver}->{Name} );
my $username = $part_export->export_username($svc_x);
@@ -637,6 +619,27 @@
} );
}
+ #astricon hack? config option?
+ push @cdrs,
+ qsearch( {
+ 'table' => 'cdr',
+ 'hashref' => { 'freesidestatus' => '',
+ 'src' => $number,
+ },
+ 'extra_sql' => 'FOR UPDATE',
+ } );
+
+ if ( length($default_prefix) ) {
+ push @cdrs,
+ qsearch( {
+ 'table' => 'cdr',
+ 'hashref' => { 'freesidestatus' => '',
+ 'src' => "$default_prefix$number",
+ },
+ 'extra_sql' => 'FOR UPDATE',
+ } );
+ }
+
@cdrs;
}
Index: Record.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Record.pm,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -d -r1.145 -r1.146
--- Record.pm 4 Oct 2007 03:37:09 -0000 1.145
+++ Record.pm 28 Oct 2007 03:55:26 -0000 1.146
@@ -24,7 +24,7 @@
@ISA = qw(Exporter);
#export dbdef for now... everything else expects to find it here
- at EXPORT_OK = qw(dbh fields hfields qsearch qsearchs dbdef jsearch);
+ at EXPORT_OK = qw(dbh fields hfields qsearch qsearchs dbdef jsearch str2time_sql);
$DEBUG = 0;
$me = '[FS::Record]';
@@ -2202,6 +2202,37 @@
=back
+=head1 SUBROUTINES
+
+=over 4
+
+=item str2time_sql [ DRIVER_NAME ]
+
+Returns a function to convert to unix time based on database type, such as
+"EXTRACT( EPOCH FROM" for Pg or "UNIX_TIMESTAMP(" for mysql. You are
+responsible for the closing parenthesis yourself. Don't let it down. It's a
+sensitive parenthesis.
+
+You can pass an optional driver name such as "Pg", "mysql" or
+$dbh->{Driver}->{Name} to return a function for that database instead of
+the current database.
+
+=cut
+
+sub str2time_sql {
+ my $driver = shift || driver_name;
+
+ return 'UNIX_TIMESTAMP(' if $driver =~ /^mysql/i;
+ return 'EXTRACT( EPOCH FROM ' if $driver =~ /^Pg/i;
+
+ warn "warning: unknown database type $driver; guessing how to convert ".
+ "dates to UNIX timestamps";
+ return 'EXTRACT(EPOCH FROM ';
+
+}
+
+=back
+
=head1 BUGS
This module should probably be renamed, since much of the functionality is
More information about the freeside-commits
mailing list