fix unnecessary warnings on upgrade of remote Pg RADIUS db, RT#9178
[freeside.git] / FS / FS / Upgrade.pm
index 7aecf45..34fc324 100644 (file)
@@ -42,6 +42,10 @@ sub upgrade {
 
   my $data = upgrade_data(%opt);
 
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  local $FS::UID::AutoCommit = 0;
+
   foreach my $table ( keys %$data ) {
 
     my $class = "FS::$table";
@@ -53,13 +57,10 @@ sub upgrade {
 
       my $start = time;
 
-      my $oldAutoCommit = $FS::UID::AutoCommit;
-      local $FS::UID::AutoCommit = 0;
-      $FS::UID::AutoCommit = 0;
-
       $class->_upgrade_data(%opt);
 
       if ( $oldAutoCommit ) {
+        warn "  committing\n";
         dbh->commit or die dbh->errstr;
       }
       
@@ -99,7 +100,6 @@ sub upgrade_data {
 
     #reason type and reasons
     'reason_type'     => [],
-    'reason'          => [],
     'cust_pkg_reason' => [],
 
     #need part_pkg before cust_credit...
@@ -126,15 +126,37 @@ sub upgrade_data {
     #usage_classes if we have none
     'usage_class' => [],
 
+    #phone_type if we have none
+    'phone_type' => [],
+
     #fixup access rights
     'access_right' => [],
 
-    #change tax_rate column types
-    'tax_rate' => [],
-
     #change recur_flat and enable_prorate
     'part_pkg_option' => [],
 
+    #add weights to pkg_category
+    'pkg_category' => [],
+
+    #cdrbatch fixes
+    'cdr' => [],
+
+    #otaker->usernum
+    'cust_attachment' => [],
+    #'cust_credit' => [],
+    #'cust_main' => [],
+    'cust_main_note' => [],
+    #'cust_pay' => [],
+    'cust_pay_void' => [],
+    'cust_pkg' => [],
+    #'cust_pkg_reason' => [],
+    'cust_pkg_discount' => [],
+    'cust_refund' => [],
+    'banned_pay' => [],
+
+    #default namespace
+    'payment_gateway' => [],
+
   ;
 
   \%hash;
@@ -164,7 +186,8 @@ sub upgrade_sqlradius {
     my $str2time = str2time_sql( $dbh->{Driver}->{Name} );
     my $group = "UserName";
     $group .= ",Realm"
-      if ( ref($part_export) =~ /withdomain/ );
+      if ref($part_export) =~ /withdomain/
+      || $dbh->{Driver}->{Name} =~ /^Pg/; #hmm
 
     my $sth_alter = $dbh->prepare(
       "ALTER TABLE radacct ADD COLUMN FreesideStatus varchar(32) NULL"
@@ -190,21 +213,26 @@ sub upgrade_sqlradius {
     if ( $sth_index ) {
       unless ( $sth_index->execute ) {
         my $error = $sth_index->errstr;
-        warn $errmsg.$error unless $error =~ /Duplicate key name/i;
+        warn $errmsg.$error
+          unless $error =~ /Duplicate key name/i                        #mysql
+              || $error =~ /relation "freesidestatus" already exists/i; #Pg
       }
     } else {
       my $error = $dbh->errstr;
-      warn $errmsg.$error#unless $error =~ /exists/i;
+      warn $errmsg.$error. ' (preparing statement)';#unless $error =~ /exists/i;
     }
 
+    my $times = ($dbh->{Driver}->{Name} =~ /^mysql/)
+      ? ' AcctStartTime != 0 AND AcctStopTime != 0 '
+      : ' AcctStartTime IS NOT NULL AND AcctStopTime IS NOT NULL ';
+
     my $sth = $dbh->prepare("SELECT UserName,
                                     Realm,
                                     $str2time max(AcctStartTime)),
                                     $str2time max(AcctStopTime))
                               FROM radacct
                               WHERE FreesideStatus = 'done'
-                                AND AcctStartTime != 0
-                                AND AcctStopTime  != 0
+                                AND $times
                               GROUP BY $group
                             ")
       or die $errmsg.$dbh->errstr;