Advertisement
luisfcastilla

Untitled

May 27th, 2020
1,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1.  /*
  2.      * Process the file, sent in the constructor.
  3.      * Return: Array with 1 or false. false on error.
  4.      */
  5.     public function processFile() {
  6.         global $wpdb;
  7.         $tariffs = $this->loadedFile;
  8.         $tableName = $wpdb->prefix."aranceles";
  9.  
  10.         if(empty($tariffs)){
  11.             error_log("Problem transform or loading import file.");
  12.             return;
  13.         }
  14.         $insertReturns = [];
  15.         $wpdb->query( 'SET autocommit = 0;' );
  16.         foreach ($tariffs as $row) {
  17.             $insert = "INSERT INTO '$tableName'
  18.                (internal_id, service_detail, particular_value, particular_non_business,
  19.                fonasa_value, fonasa_non_business, isapre_value, isapre_non_business, med_value,
  20.                pacakge_value, fonasa_code, category, subcategory)
  21.                VALUES (%s, %s, %d, %d, %d, %d, %d, %d, %d, %d, %s, %s, %s)
  22.                ON DUPLICATE KEY UPDATE service_detail=VALUES(service_detail),
  23.                particular_value=VALUES(particular_value), particular_non_business=VALUES(particular_non_business), fonasa_value=VALUES(fonasa_value),
  24.                fonasa_non_business=VALUES(fonasa_non_business), isapre_value=VALUES(isapre_value),
  25.                isapre_non_business=VALUES(isapre_non_business), med_value=VALUES(med_value), pacakge_value=VALUES(pacakge_value),
  26.                fonasa_code=VALUES(fonasa_code), category=VALUES(category), subcategory=VALUES(subcategory)";
  27.  
  28.             $insert = $wpdb->prepare($insert, row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12]);
  29.             $insertReturns[] = $wpdb->query( $insert );
  30.         }
  31.         $wpdb->query( 'COMMIT;' );
  32.         $wpdb->query( 'SET autocommit = 1;' );
  33.  
  34.         return $insertReturns;
  35.  
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement