package FS::Upgrade;
use strict;
-use vars qw( @ISA @EXPORT_OK );
+use vars qw( @ISA @EXPORT_OK $DEBUG );
use Exporter;
use Tie::IxHash;
use FS::UID qw( dbh driver_name );
@ISA = qw( Exporter );
@EXPORT_OK = qw( upgrade upgrade_sqlradius );
+$DEBUG = 1;
+
=head1 NAME
FS::Upgrade - Database upgrade routines
sub upgrade {
my %opt = @_;
- my $oldAutoCommit = $FS::UID::AutoCommit;
- local $FS::UID::AutoCommit = 0;
- $FS::UID::AutoCommit = 0;
-
my $data = upgrade_data(%opt);
foreach my $table ( keys %$data ) {
die $@ if $@;
if ( $class->can('_upgrade_data') ) {
+ warn "Upgrading $table...\n";
+
+ my $start = time;
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ $FS::UID::AutoCommit = 0;
+
$class->_upgrade_data(%opt);
+
+ if ( $oldAutoCommit ) {
+ dbh->commit or die dbh->errstr;
+ }
+
+ #warn "\e[1K\rUpgrading $table... done in ". (time-$start). " seconds\n";
+ warn " done in ". (time-$start). " seconds\n";
+
} else {
warn "WARNING: asked for upgrade of $table,".
" but FS::$table has no _upgrade_data method\n";
}
- if ( $oldAutoCommit ) {
- dbh->commit or die dbh->errstr;
- }
-
}
tie my %hash, 'Tie::IxHash',
+ #cust_main (remove paycvv from history)
+ 'cust_main' => [],
+
+ #msgcat
+ 'msgcat' => [],
+
#reason type and reasons
- 'reason_type' => [],
- 'reason' => [],
+ 'reason_type' => [],
+ 'reason' => [],
+ 'cust_pkg_reason' => [],
#need part_pkg before cust_credit...
'part_pkg' => [],
#remove bad pending records
'cust_pay_pending' => [],
+ #replace invnum and pkgnum with billpkgnum
+ 'cust_bill_pkg_detail' => [],
+
+ #usage_classes if we have none
+ 'usage_class' => [],
+
+ #fixup access rights
+ 'access_right' => [],
+
+ #change tax_rate column types
+ 'tax_rate' => [],
+
+ #change recur_flat and enable_prorate
+ 'part_pkg_option' => [],
+
;
\%hash;
my @part_export = FS::part_export::sqlradius->all_sqlradius_withaccounting();
foreach my $part_export ( @part_export ) {
+
+ my $errmsg = 'Error adding FreesideStatus to '.
+ $part_export->option('datasrc'). ': ';
+
my $dbh = DBI->connect(
( map $part_export->option($_), qw ( datasrc username password ) ),
{ PrintError => 0, PrintWarn => 0 }
- );
-
- unless $dbh {
- warn "can't connect to RADIUS database ".
- $part_export->option('datasrc'). ": $DBI::errstr\n";
+ ) or do {
+ warn $errmsg.$DBI::errstr;
next;
- }
+ };
- my $errmsg = 'Error adding FreesideStatus to '.
- $part_export->option('datasrc'). ': ';
-
my $str2time = str2time_sql( $dbh->{Driver}->{Name} );
my $group = "UserName";
$group .= ",Realm"
my ($username, $realm, $start, $stop) = @$row;
$username = lc($username) unless $conf->exists('username-uppercase');
- my $extra_sql = '';
+
+ my $exportnum = $part_export->exportnum;
+ my $extra_sql = " AND exportnum = $exportnum ".
+ " AND exportsvcnum IS NOT NULL ";
+
if ( ref($part_export) =~ /withdomain/ ) {
- $extra_sql = " And '$realm' = ( SELECT domain FROM svc_domain
+ $extra_sql = " AND '$realm' = ( SELECT domain FROM svc_domain
WHERE svc_domain.svcnum = svc_acct.domsvc ) ";
}
- my $svc_acct = qsearchs( 'svc_acct',
- { 'username' => $username },
- '',
- $extra_sql,
- );
+ my $svc_acct = qsearchs({
+ 'select' => 'svc_acct.*',
+ 'table' => 'svc_acct',
+ 'addl_from' => 'LEFT JOIN cust_svc USING ( svcnum )'.
+ 'LEFT JOIN export_svc USING ( svcpart )',
+ 'hashref' => { 'username' => $username },
+ 'extra_sql' => $extra_sql,
+ });
+
if ($svc_acct) {
$svc_acct->last_login($start)
if $start && (!$svc_acct->last_login || $start > $svc_acct->last_login);