Changeset 13167

Show
Ignore:
Timestamp:
01/06/12 14:07:59 (1 year ago)
Author:
p_lindheimer
Message:

make sure we successfully connected to the CDR DB before trying to add the fields

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.10/upgrades/2.10.0beta3/migration.php

    r13154 r13167  
    4545    . $db_creds['dbname']; 
    4646  $db_cdr = DB::connect($datasource); // attempt connection 
     47  if (DB::IsError($db_cdr)) {  
     48    out(_("ERROR connectng to CDR DB to migrate, not done!")); 
     49    freepbx_log(FPBX_LOG_ERROR,"failed to open CDR DB to add recordingfile and did fields"); 
     50  } else { 
     51    $sql = "SELECT recordingfile FROM cdr"; 
     52    $confs = $db_cdr->getRow($sql, DB_FETCHMODE_ASSOC); 
     53    outn(_("checking if recordingfile file field needed in cdr..")); 
     54    if (DB::IsError($confs)) { // no error... Already done 
     55      $sql = "ALTER TABLE cdr ADD recordingfile VARCHAR ( 255 ) NOT NULL default ''"; 
     56      $results = $db_cdr->query($sql); 
     57      if(DB::IsError($results)) { 
     58        out(_("failed")); 
     59        freepbx_log(FPBX_LOG_ERROR,"failed to add recordingfile fieled to cdr table during migration"); 
     60      } 
     61      out(_("added")); 
     62    } else { 
     63      out(_("already there")); 
     64    } 
    4765 
    48   $sql = "SELECT recordingfile FROM cdr"; 
    49   $confs = $db_cdr->getRow($sql, DB_FETCHMODE_ASSOC); 
    50   outn(_("checking if recordingfile file field needed in cdr..")); 
    51   if (DB::IsError($confs)) { // no error... Already done 
    52     $sql = "ALTER TABLE cdr ADD recordingfile VARCHAR ( 255 ) NOT NULL default ''"; 
    53     $results = $db_cdr->query($sql); 
    54     if(DB::IsError($results)) { 
    55       out(_("failed")); 
    56       freepbx_log(FPBX_LOG_ERROR,"failed to add recordingfile fieled to cdr table during migration"); 
     66  $sql = "SELECT did FROM cdr"; 
     67  $confs = $db_cdr->getRow($sql, DB_FETCHMODE_ASSOC); 
     68  outn(_("checking if did file field needed in cdr..")); 
     69  if (DB::IsError($confs)) { // no error... Already done 
     70    $sql = "ALTER TABLE cdr ADD did VARCHAR ( 50 ) NOT NULL default ''"; 
     71    $results = $db_cdr->query($sql); 
     72    if(DB::IsError($results)) { 
     73      out(_("failed")); 
     74      freepbx_log(FPBX_LOG_ERROR,"failed to add did fieled to cdr table during migration"); 
    5775    } 
    58     out(_("added")); 
    59   } else { 
    60     out(_("already there")); 
    61   } 
    62  
    63   $sql = "SELECT did FROM cdr"; 
    64   $confs = $db_cdr->getRow($sql, DB_FETCHMODE_ASSOC); 
    65   outn(_("checking if did file field needed in cdr..")); 
    66   if (DB::IsError($confs)) { // no error... Already done 
    67     $sql = "ALTER TABLE cdr ADD did VARCHAR ( 50 ) NOT NULL default ''"; 
    68     $results = $db_cdr->query($sql); 
    69     if(DB::IsError($results)) { 
    70       out(_("failed")); 
    71       freepbx_log(FPBX_LOG_ERROR,"failed to add did fieled to cdr table during migration"); 
     76      out(_("added")); 
     77    } else { 
     78      out(_("already there")); 
    7279    } 
    73     out(_("added")); 
    74   } else { 
    75     out(_("already there")); 
    7680  } 
    7781}