X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FUpgrade.pm;h=57c94ac6f7ec31acfa27a396c5e34561e5871a13;hb=4b5d4c82766ef1869d03df63fa1e2f0dd050cb6a;hp=8f3a6e5711defea611d80d50e2212a7a779b8e57;hpb=2212d77b5379ab6bc3907058b8e672106da7cf21;p=freeside.git diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm index 8f3a6e571..57c94ac6f 100644 --- a/FS/FS/Upgrade.pm +++ b/FS/FS/Upgrade.pm @@ -1,7 +1,7 @@ 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 ); @@ -14,6 +14,8 @@ $FS::svc_domain::whois_hack = 1; @ISA = qw( Exporter ); @EXPORT_OK = qw( upgrade upgrade_sqlradius ); +$DEBUG = 1; + =head1 NAME FS::Upgrade - Database upgrade routines @@ -51,6 +53,7 @@ sub upgrade { die $@ if $@; if ( $class->can('_upgrade_data') ) { + warn "Upgrading $table...\n"; $class->_upgrade_data(%opt); } else { warn "WARNING: asked for upgrade of $table,". @@ -82,8 +85,9 @@ sub upgrade_data { tie my %hash, 'Tie::IxHash', #reason type and reasons - 'reason_type' => [], - 'reason' => [], + 'reason_type' => [], + 'reason' => [], + 'cust_pkg_reason' => [], #need part_pkg before cust_credit... 'part_pkg' => [], @@ -103,6 +107,15 @@ sub upgrade_data { #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' => [], + ; \%hash; @@ -117,9 +130,18 @@ 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 $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 } + ) or do { + warn $errmsg.$DBI::errstr; + next; + }; + my $str2time = str2time_sql( $dbh->{Driver}->{Name} ); my $group = "UserName"; $group .= ",Realm" @@ -128,18 +150,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 ) { - $sth_index->execute; + unless ( $sth_index->execute ) { + my $error = $sth_index->errstr; + warn $errmsg.$error unless $error =~ /Duplicate key name/i; + } + } else { + my $error = $dbh->errstr; + warn $errmsg.$error; #unless $error =~ /exists/i; } my $sth = $dbh->prepare("SELECT UserName, @@ -152,8 +188,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;