예제 #1
0
 /**
  * Poll this function to know the status of a TMX upload
  *
  */
 public function tmxUploadStatus()
 {
     //remove spaces because of MyMemory remove them and status check does not works
     $name_space_replaced = str_replace(" ", "_", $this->name);
     $allMemories = $this->mymemory_engine->getStatus($this->tm_key, $name_space_replaced);
     //        Log::doLog( $allMemories );
     if ($allMemories->responseStatus != "200" || count($allMemories->responseData['tm']) == 0) {
         Log::doLog("Can't find TMX files to check for status");
         //what the hell? No memories although I've just loaded some? Eject!
         throw new Exception("Can't find TMX files to check for status", -15);
     }
     $tmx_max_id = 0;
     $current_tm = array();
     //scan through memories
     foreach ($allMemories->responseData['tm'] as $memory) {
         //obtain max id
         $tmx_max_id = max($tmx_max_id, $memory['id']);
         //if maximum is current, pick it (it means that, among duplicates, it's the latest)
         if ($tmx_max_id == $memory['id']) {
             $current_tm = $memory;
         }
     }
     $result = array();
     switch ($current_tm['status']) {
         case "0":
             //wait for the daemon to process it
             //LOADING
             Log::doLog("waiting for \"" . $current_tm['file_name'] . "\" to be loaded into MyMemory");
             $result['data'] = array("done" => $current_tm["temp_seg_ins"], "total" => $current_tm["num_seg_tot"], "source_lang" => $current_tm["source_lang"], "target_lang" => $current_tm["target_lang"]);
             $result['completed'] = false;
             break;
         case "1":
             //loaded (or error, in any case go ahead)
             Log::doLog("\"" . $current_tm['file_name'] . "\" has been loaded into MyMemory");
             $result['data'] = array("done" => $current_tm["temp_seg_ins"], "total" => $current_tm["num_seg_tot"], "source_lang" => $current_tm["source_lang"], "target_lang" => $current_tm["target_lang"]);
             $result['completed'] = true;
             break;
         default:
             throw new Exception("Invalid TMX (\"" . $current_tm['file_name'] . "\")", -14);
             break;
     }
     return $result;
 }