Changeset 35 for trunk/cleanup_gfac.php


Ignore:
Timestamp:
Apr 8, 2018, 4:41:57 PM (7 years ago)
Author:
gegorbet
Message:

mods mostly for use of mysqli

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cleanup_gfac.php

    r25 r35  
    4141   write_log( "$me: debug db=$db; requestID=$requestID" );
    4242
    43    $us3_link = mysql_connect( $dbhost, $user, $passwd );
     43   $us3_link = mysqli_connect( $dbhost, $user, $passwd, $db );
    4444
    4545   if ( ! $us3_link )
    4646   {
    47       write_log( "$me: could not connect: $dbhost, $user, $passwd" );
    48       mail_to_user( "fail", "Internal Error $requestID\nCould not connect to DB" );
    49       return( -1 );
    50    }
    51 
    52    $result = mysql_select_db( $db, $us3_link );
    53 
    54    if ( ! $result )
    55    {
    56       write_log( "$me: could not select DB $db" );
    57       mail_to_user( "fail", "Internal Error $requestID\n$could not select DB $db" );
     47      write_log( "$me: could not connect: $dbhost, $user, $passwd, $db" );
     48      mail_to_user( "fail", "Internal Error $requestID\nCould not connect to DB $db" );
    5849      return( -1 );
    5950   }
     
    6253   $query  = "SELECT email, investigatorGUID, editXMLFilename FROM HPCAnalysisRequest " .
    6354             "WHERE HPCAnalysisRequestID=$requestID";
    64    $result = mysql_query( $query, $us3_link );
     55   $result = mysqli_query( $us3_link, $query );
    6556
    6657   if ( ! $result )
    6758   {
    6859      write_log( "$me: Bad query: $query" );
    69       mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysql_error( $us3_link ) );
    70       return( -1 );
    71    }
    72 
    73    list( $email_address, $investigatorGUID, $editXMLFilename ) =  mysql_fetch_array( $result );
     60      mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysqli_error( $us3_link ) );
     61      return( -1 );
     62   }
     63
     64   list( $email_address, $investigatorGUID, $editXMLFilename ) =  mysqli_fetch_array( $result );
    7465
    7566   $query  = "SELECT personID FROM people " .
    7667             "WHERE personGUID='$investigatorGUID'";
    77    $result = mysql_query( $query, $us3_link );
    78 
    79    list( $personID ) = mysql_fetch_array( $result );
     68   $result = mysqli_query( $us3_link, $query );
     69
     70   list( $personID ) = mysqli_fetch_array( $result );
    8071
    8172   /*
     
    9081             "AND h.HPCAnalysisRequestID=r.HPCAnalysisRequestID";
    9182
    92    $result = mysql_query( $query, $us3_link );
    93 
    94    if ( ! $result )
    95    {
    96       write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
    97       return( -1 );
    98    }
    99 
    100    if ( mysql_num_rows( $result ) == 0 )
     83   $result = mysqli_query( $us3_link, $query );
     84
     85   if ( ! $result )
     86   {
     87      write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
     88      return( -1 );
     89   }
     90
     91   if ( mysqli_num_rows( $result ) == 0 )
    10192   {
    10293      write_log( "$me: US3 Table error - No records for requestID: $requestID" );
     
    10495   }
    10596
    106    list( $cluster, $submittime, $queuestatus, $jobtype ) = mysql_fetch_array( $result );
     97   list( $cluster, $submittime, $queuestatus, $jobtype ) = mysqli_fetch_array( $result );
    10798
    10899   // Get the GFAC ID
     
    110101            "WHERE HPCAnalysisRequestID=$requestID";
    111102
    112    $result = mysql_query( $query, $us3_link );
     103   $result = mysqli_query( $us3_link, $query );
    113104
    114105   if ( ! $result )
    115106   {
    116107      write_log( "$me: Bad query: $query" );
    117       mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysql_error( $us3_link ) );
    118       return( -1 );
    119    }
    120 
    121    list( $HPCAnalysisResultID, $gfacID ) = mysql_fetch_array( $result );
     108      mail_to_user( "fail", "Internal Error $requestID\n$query\n" . mysqli_error( $us3_link ) );
     109      return( -1 );
     110   }
     111
     112   list( $HPCAnalysisResultID, $gfacID ) = mysqli_fetch_array( $result );
    122113
    123114   ////////
    124115   // Get data from global GFAC DB and insert it into US3 DB
    125    // $gfac_link = mysql_connect( $dbhost, $guser, $gpasswd );
    126 
    127    $result = mysql_select_db( $gDB, $gfac_link );
    128 
    129    if ( ! $result )
    130    {
    131       write_log( "$me: Could not connect to DB $gDB" );
     116   $gfac_link = mysqli_connect( $dbhost, $guser, $gpasswd, $gDB );
     117
     118   if ( ! $gfac_link )
     119   {
     120      write_log( "$me: Could not connect to DB $dbhost : $gDB" );
    132121      mail_to_user( "fail", "Internal Error $requestID\nCould not connect to DB $gDB" );
    133122      return( -1 );
     
    137126            "WHERE gfacID='$gfacID'";
    138127
    139    $result = mysql_query( $query, $gfac_link );
     128   $result = mysqli_query( $gfac_link, $query );
    140129   if ( ! $result )
    141130   {
     
    145134   }
    146135
    147    $num_rows = mysql_num_rows( $result );
     136   $num_rows = mysqli_num_rows( $result );
    148137   if ( $num_rows == 0 )
    149138   {
     
    156145//}
    157146
    158    list( $status, $cluster, $id ) = mysql_fetch_array( $result );
     147   list( $status, $cluster, $id ) = mysqli_fetch_array( $result );
    159148//write_log( "$me:     db=$db; requestID=$requestID; status=$status; cluster=$cluster" );
    160149
     
    176165            "WHERE gfacID='$gfacID'";
    177166
    178    $result = mysql_query( $query, $gfac_link );
    179 
    180    if ( ! $result )
    181    {
    182       write_log( "$me: Bad query:\n$query\n" . mysql_error( $gfac_link ) );
    183       mail_to_user( "fail", "Internal error " . mysql_error( $gfac_link ) );
    184       return( -1 );
    185    }
    186 
    187    $num_rows = mysql_num_rows( $result );
     167   $result = mysqli_query( $gfac_link, $query );
     168
     169   if ( ! $result )
     170   {
     171      write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
     172      mail_to_user( "fail", "Internal error " . mysqli_error( $gfac_link ) );
     173      return( -1 );
     174   }
     175
     176   $num_rows = mysqli_num_rows( $result );
    188177   if ( $num_rows == 0 )
    189178   {
     
    192181   }
    193182
    194    list( $analysisID, $stderr, $stdout, $tarfile ) = mysql_fetch_array( $result );
     183   list( $analysisID, $stderr, $stdout, $tarfile ) = mysqli_fetch_array( $result );
    195184
    196185   if ( strlen( $tarfile ) > 0 )
     
    209198            "WHERE analysisID = $analysisID " .
    210199            "ORDER BY time ";
    211    $result = mysql_query( $query, $gfac_link );
     200   $result = mysqli_query( $gfac_link, $query );
    212201
    213202   if ( ! $result )
    214203   {
    215204      // Just log it and continue
    216       write_log( "$me: Bad query:\n$query\n" . mysql_error( $gfac_link ) );
     205      write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
    217206   }
    218207
     
    226215   $need_finish = ( $status == 'COMPLETE' );
    227216
    228    if ( mysql_num_rows( $result ) > 0 )
     217   if ( mysqli_num_rows( $result ) > 0 )
    229218   {
    230219      $time_msg = time();
    231       while ( list( $message, $time ) = mysql_fetch_array( $result ) )
     220      while ( list( $message, $time ) = mysqli_fetch_array( $result ) )
    232221      {
    233222//write_log( "$me: message=$message" );
     
    263252            "WHERE analysisID = $analysisID ";
    264253
    265    $result = mysql_query( $query, $gfac_link );
     254   $result = mysqli_query( $gfac_link, $query );
    266255
    267256   if ( ! $result )
    268257   {
    269258      // Just log it and continue
    270       write_log( "$me: Bad query:\n$query\n" . mysql_error( $gfac_link ) );
     259      write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
    271260   }
    272261
     
    274263   $query  = "SELECT stdout, stderr, status, queue_msg FROM analysis " .
    275264             "WHERE gfacID='$gfacID' ";
    276    $result = mysql_query( $query, $gfac_link );
     265   $result = mysqli_query( $gfac_link, $query );
    277266   try
    278267   {
    279268      // What if this is too large?
    280       list( $stdout, $stderr, $status, $queue_msg ) = mysql_fetch_array( $result );
     269      list( $stdout, $stderr, $status, $queue_msg ) = mysqli_fetch_array( $result );
    281270   }
    282271   catch ( Exception $e )
    283272   {
    284       write_log( "$me: stdout + stderr larger than 128M - $gfacID\n" . mysql_error( $gfac_link ) );
     273      write_log( "$me: stdout + stderr larger than 128M - $gfacID\n" . mysqli_error( $gfac_link ) );
    285274      // Just go ahead and clean up
    286275   }
     
    301290   $query = "DELETE from analysis WHERE gfacID='$gfacID'";
    302291
    303    $result = mysql_query( $query, $gfac_link );
     292   $result = mysqli_query( $gfac_link, $query );
    304293
    305294   if ( ! $result )
    306295   {
    307296      // Just log it and continue
    308       write_log( "$me: Bad query:\n$query\n" . mysql_error( $gfac_link ) );
     297      write_log( "$me: Bad query:\n$query\n" . mysqli_error( $gfac_link ) );
    309298   }
    310299write_log( "$me: GFAC DB entry deleted" );
     
    316305   $query  = "SELECT HPCAnalysisRequestGUID FROM HPCAnalysisRequest " .
    317306             "WHERE HPCAnalysisRequestID = $requestID ";
    318    $result = mysql_query( $query, $us3_link );
     307   $result = mysqli_query( $us3_link, $query );
    319308   
    320309   if ( ! $result )
    321310   {
    322       write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
     311      write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
    323312   }
    324313   
    325    list( $requestGUID ) = mysql_fetch_array( $result );
     314   list( $requestGUID ) = mysqli_fetch_array( $result );
    326315   $output_dir = "$submit_dir/$requestGUID";
    327316write_log( "$me: Output dir determined: $output_dir" );
     
    334323   $message_filename = "$output_dir/$db-$requestID-messages.txt";
    335324   file_put_contents( $message_filename, $message_log, FILE_APPEND );
    336   // mysql_close( $gfac_link );
     325  // mysqli_close( $gfac_link );
    337326write_log( "$me: *messages.txt written" );
    338327
     
    341330
    342331   $query = "UPDATE HPCAnalysisResult SET "                              .
    343             "stderr='" . mysql_real_escape_string( $stderr, $us3_link ) . "', " .
    344             "stdout='" . mysql_real_escape_string( $stdout, $us3_link ) . "' "  .
     332            "stderr='" . mysqli_real_escape_string( $us3_link, $stderr ) . "', " .
     333            "stdout='" . mysqli_real_escape_string( $us3_link, $stdout ) . "' "  .
    345334            "WHERE HPCAnalysisResultID=$HPCAnalysisResultID";
    346335
    347    $result = mysql_query( $query, $us3_link );
    348 
    349    if ( ! $result )
    350    {
    351       write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
    352       mail_to_user( "fail", "Bad query:\n$query\n" . mysql_error( $us3_link ) );
     336   $result = mysqli_query( $us3_link, $query );
     337
     338   if ( ! $result )
     339   {
     340      write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
     341      mail_to_user( "fail", "Bad query:\n$query\n" . mysqli_error( $us3_link ) );
    353342      return( -1 );
    354343   }
     
    442431                  "mgroupcount = {$otherdata['groupcount']} " .
    443432                  "WHERE HPCAnalysisResultID=$HPCAnalysisResultID";
    444          $result = mysql_query( $query, $us3_link );
     433         $result = mysqli_query( $us3_link, $query );
    445434
    446435         if ( ! $result )
    447436         {
    448             write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
     437            write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
    449438         }
    450439
     
    463452         $modelGUID  = $noise_data[ 'modelGUID' ];
    464453         $noiseGUID  = $noise_data[ 'noiseGUID' ];
     454         $editGUID   = '00000000-0000-0000-0000-000000000000';
     455         if ( isset( $model_data[ 'editGUID' ] ) )
     456            $editGUID   = $model_data[ 'editGUID' ];
    465457
    466458         $query = "INSERT INTO noise SET "  .
    467459                  "noiseGUID='$noiseGUID'," .
    468460                  "modelGUID='$modelGUID'," .
    469                   "editedDataID=2, "        .
     461                  "editedDataID="                .
     462                  "(SELECT editedDataID FROM editedData WHERE editGUID='$editGUID')," .
    470463                  "modelID=1, "             .
    471464                  "noiseType='$type',"      .
    472465                  "description='$desc',"    .
    473                   "xml='" . mysql_real_escape_string( $xml, $us3_link ) . "'";
     466                  "xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'";
    474467
    475468         // Add later after all files are processed: editDataID, modelID
    476469
    477          $result = mysql_query( $query, $us3_link );
     470         $result = mysqli_query( $us3_link, $query );
    478471
    479472         if ( ! $result )
    480473         {
    481             write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
    482             mail_to_user( "fail", "Internal error\n$query\n" . mysql_error( $us3_link ) );
     474            write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
     475            mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
    483476            return( -1 );
    484477         }
    485478
    486          $id        = mysql_insert_id( $us3_link );
     479         $id        = mysqli_insert_id( $us3_link );
    487480         $file_type = "noise";
    488481         $noiseIDs[] = $id;
     
    490483         // Keep track of modelGUIDs for later, when we replace them
    491484         $modelGUIDs[ $id ] = $modelGUID;
    492 //write_log( "$me:   noise file inserted into DB : id=$id" );
     485//write_log( "$me:   noise file inserted into DB : id=$id  modelGUID=$modelGUID" );
    493486         
    494487      }
     
    512505                  "mrecsGUID='$mrecGUID'," .
    513506                  "description='$desc',"    .
    514                   "xml='" . mysql_real_escape_string( $xml, $us3_link ) . "'";
     507                  "xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'";
    515508
    516509         // Add later after all files are processed: editDataID, modelID
    517510
    518          $result = mysql_query( $query, $us3_link );
     511         $result = mysqli_query( $us3_link, $query );
    519512
    520513         if ( ! $result )
    521514         {
    522             write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
    523             mail_to_user( "fail", "Internal error\n$query\n" . mysql_error( $us3_link ) );
     515            write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
     516            mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
    524517            return( -1 );
    525518         }
    526519
    527          $id         = mysql_insert_id( $us3_link );
     520         $id         = mysqli_insert_id( $us3_link );
    528521         $file_type  = "mrecs";
    529522         $mrecsIDs[] = $id;
     
    560553                  "meniscus='$meniscus'," .
    561554                  "variance='$variance'," .
    562                   "xml='" . mysql_real_escape_string( $xml, $us3_link ) . "'";
    563 
    564          $result = mysql_query( $query, $us3_link );
     555                  "xml='" . mysqli_real_escape_string( $us3_link, $xml ) . "'";
     556
     557         $result = mysqli_query( $us3_link, $query );
    565558
    566559         if ( ! $result )
    567560         {
    568             write_log( "$me: Bad query:\n$query " . mysql_error( $us3_link ) );
    569             mail_to_user( "fail", "Internal error\n$query\n" . mysql_error( $us3_link ) );
     561            write_log( "$me: Bad query:\n$query " . mysqli_error( $us3_link ) );
     562            mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
    570563            return( -1 );
    571564         }
    572565
    573          $modelID   = mysql_insert_id( $us3_link );
     566         $modelID   = mysqli_insert_id( $us3_link );
    574567         $id        = $modelID;
    575568         $file_type = "model";
     
    577570         $query = "INSERT INTO modelPerson SET " .
    578571                  "modelID=$modelID, personID=$personID";
    579          $result = mysql_query( $query, $us3_link );
     572         $result = mysqli_query( $us3_link, $query );
    580573//write_log( "$me:   model file inserted into DB : id=$id" );
    581574      }
     
    586579               "resultID=$id";
    587580
    588       $result = mysql_query( $query, $us3_link );
     581      $result = mysqli_query( $us3_link, $query );
    589582
    590583      if ( ! $result )
    591584      {
    592          write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
    593          mail_to_user( "fail", "Internal error\n$query\n" . mysql_error( $us3_link ) );
     585         write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
     586         mail_to_user( "fail", "Internal error\n$query\n" . mysqli_error( $us3_link ) );
    594587         return( -1 );
    595588      }
     
    611604               "WHERE noiseID=$noiseID";
    612605
    613       $result = mysql_query( $query, $us3_link );
     606      $result = mysqli_query( $us3_link, $query );
    614607
    615608      if ( ! $result )
    616609      {
    617          write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
    618          mail_to_user( "fail", "Bad query\n$query\n" . mysql_error( $us3_link ) );
     610         write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
     611         mail_to_user( "fail", "Bad query\n$query\n" . mysqli_error( $us3_link ) );
    619612         return( -1 );
    620613      }
     
    633626               "WHERE mrecsID=$mrecsID";
    634627
    635       $result = mysql_query( $query, $us3_link );
     628      $result = mysqli_query( $us3_link, $query );
    636629
    637630      if ( ! $result )
    638631      {
    639          write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
    640          mail_to_user( "fail", "Bad query\n$query\n" . mysql_error( $us3_link ) );
     632         write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
     633         mail_to_user( "fail", "Bad query\n$query\n" . mysqli_error( $us3_link ) );
    641634         return( -1 );
    642635      }
     
    651644   $query  = "SELECT HPCAnalysisRequestGUID FROM HPCAnalysisRequest " .
    652645             "WHERE HPCAnalysisRequestID = $requestID ";
    653    $result = mysql_query( $query, $us3_link );
    654 
    655    if ( ! $result )
    656    {
    657       write_log( "$me: Bad query:\n$query\n" . mysql_error( $us3_link ) );
    658    }
    659 
    660    list( $requestGUID ) = mysql_fetch_array( $result );
     646   $result = mysqli_query( $us3_link, $query );
     647
     648   if ( ! $result )
     649   {
     650      write_log( "$me: Bad query:\n$query\n" . mysqli_error( $us3_link ) );
     651   }
     652
     653   list( $requestGUID ) = mysqli_fetch_array( $result );
    661654
    662655   chdir( "$submit_dir/$requestGUID" );
     
    669662   // exec( "rm -rf $gfacID" );
    670663
    671    mysql_close( $us3_link );
     664   mysqli_close( $us3_link );
    672665
    673666   /////////
Note: See TracChangeset for help on using the changeset viewer.