X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=FS%2FFS%2FUpgrade.pm;h=befc36f712ed7e2c8e56154e3f0bd31443dd0fcb;hb=f13afe5e228a220311557e1ca6dacbf847c26baf;hp=dec4d483d9daa6d7363742a41f03f8a3941e6c5d;hpb=12587c5314c2a2ee40ab046af1552a40db5e0eaf;p=freeside.git diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index dec4d483d..befc36f71 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -6,7 +6,7 @@ use Exporter; use Tie::IxHash; use FS::UID qw( dbh driver_name ); use FS::Conf; -use FS::Record; +use FS::Record qw(qsearchs str2time_sql); use FS::svc_domain; $FS::svc_domain::whois_hack = 1; @@ -100,6 +100,9 @@ sub upgrade_data { #populate part_pkg_taxclass for starters 'part_pkg_taxclass' => [], + #remove bad pending records + 'cust_pay_pending' => [], + ; \%hash; @@ -114,8 +117,13 @@ sub upgrade_sqlradius { my @part_export = FS::part_export::sqlradius->all_sqlradius_withaccounting(); foreach my $part_export ( @part_export ) { - my $dbh = DBI->connect( map $part_export->option($_), - qw ( datasrc username password ) ); + my $dbh = DBI->connect( + ( map $part_export->option($_), qw ( datasrc username password ) ), + { PrintError => 0, PrintWarn => 0 } + ); + + my $errmsg = 'Error adding FreesideStatus to '. + $part_export->option('datasrc'). ': '; my $str2time = str2time_sql( $dbh->{Driver}->{Name} ); my $group = "UserName"; @@ -125,11 +133,32 @@ sub upgrade_sqlradius { my $sth_alter = $dbh->prepare( "ALTER TABLE radacct ADD COLUMN FreesideStatus varchar(32) NULL" ); - if ( $sth_alter && $sth_alter->execute ) { - my $sth_update = $dbh->prepare( - "UPDATE radacct SET FreesideStatus = 'done' WHERE FreesideStatus IS NULL" - ) or die $dbh->errstr; - $sth_update->execute or die $sth_update->errstr; + if ( $sth_alter ) { + if ( $sth_alter->execute ) { + my $sth_update = $dbh->prepare( + "UPDATE radacct SET FreesideStatus = 'done' WHERE FreesideStatus IS NULL" + ) or die $errmsg.$dbh->errstr; + $sth_update->execute or die $errmsg.$sth_update->errstr; + } else { + my $error = $sth_alter->errstr; + warn $errmsg.$error unless $error =~ /Duplicate column name/i; + } + } else { + my $error = $dbh->errstr; + warn $errmsg.$error; #unless $error =~ /exists/i; + } + + my $sth_index = $dbh->prepare( + "CREATE INDEX FreesideStatus ON radacct ( FreesideStatus )" + ); + if ( $sth_index ) { + unless ( $sth_index->execute ) { + my $error = $sth_index->errstr; + warn $errmsg.$error; #unless $error =~ /exists/i; + } + } else { + my $error = $dbh->errstr; + warn $errmsg.$error; #unless $error =~ /exists/i; } my $sth = $dbh->prepare("SELECT UserName, @@ -142,8 +171,8 @@ sub upgrade_sqlradius { AND AcctStopTime != 0 GROUP BY $group ") - or die $dbh->errstr; - $sth->execute() or die $sth->errstr; + or die $errmsg.$dbh->errstr; + $sth->execute() or die $errmsg.$sth->errstr; while (my $row = $sth->fetchrow_arrayref ) { my ($username, $realm, $start, $stop) = @$row;