예제 #1
0
 public function mergeALL(ArrayObject $projectStructure, $renewPassword = false)
 {
     $query_job = "SELECT *\n            FROM jobs\n            WHERE id = %u\n            ORDER BY job_first_segment";
     $query_job = sprintf($query_job, $projectStructure['job_to_merge']);
     //$projectStructure[ 'job_to_split' ]
     $rows = $this->dbHandler->fetch_array($query_job);
     //get the min and
     $first_job = reset($rows);
     $job_first_segment = $first_job['job_first_segment'];
     //the max segment from job list
     $last_job = end($rows);
     $job_last_segment = $last_job['job_last_segment'];
     //change values of first job
     $first_job['job_first_segment'] = $job_first_segment;
     // redundant
     $first_job['job_last_segment'] = $job_last_segment;
     //merge TM keys: preserve only owner's keys
     $tm_keys = array();
     foreach ($rows as $chunk_info) {
         $tm_keys[] = $chunk_info['tm_keys'];
     }
     try {
         $owner_tm_keys = TmKeyManagement_TmKeyManagement::getOwnerKeys($tm_keys);
         /**
          * @var $owner_key TmKeyManagement_TmKeyStruct
          */
         foreach ($owner_tm_keys as $i => $owner_key) {
             $owner_tm_keys[$i] = $owner_key->toArray();
         }
         $first_job['tm_keys'] = json_encode($owner_tm_keys);
     } catch (Exception $e) {
         Log::doLog(__METHOD__ . " -> Merge Jobs error - TM key problem: " . $e->getMessage());
     }
     $oldPassword = $first_job['password'];
     if ($renewPassword) {
         $first_job['password'] = self::_generatePassword();
     }
     $_data = array();
     foreach ($first_job as $field => $value) {
         $_data[] = "`{$field}`='{$value}'";
     }
     //----------------------------------------------------
     $queries = array();
     $queries[] = "UPDATE jobs SET " . implode(", \n", $_data) . " WHERE id = {$first_job['id']} AND password = '******'";
     //ose old password
     //delete all old jobs
     $queries[] = "DELETE FROM jobs WHERE id = {$first_job['id']} AND password != '{$first_job['password']}' ";
     //use new password
     foreach ($queries as $query) {
         $res = $this->dbHandler->query($query);
         if ($res !== true) {
             $msg = "Failed to merge job  " . $rows[0]['id'] . " from " . count($rows) . " chunks\n";
             $msg .= "Tried to perform SQL: \n" . print_r($queries, true) . " \n\n";
             $msg .= "Failed Statement is: \n" . print_r($query, true) . "\n";
             $msg .= "Original Status for rebuild job and project was: \n" . print_r($rows, true) . "\n";
             Utils::sendErrMailReport($msg);
             throw new Exception('Failed to merge jobs, project damaged. Contact Matecat Support to rebuild project.', -8);
         }
     }
     $wCountManager = new WordCount_Counter();
     $wCountManager->initializeJobWordCount($first_job['id'], $first_job['password']);
     Shop_Cart::getInstance('outsource_to_external_cache')->emptyCart();
 }
예제 #2
0
 private static function sanitizeTmKeyArr($elem)
 {
     $elem = TmKeyManagement_TmKeyManagement::sanitize(new TmKeyManagement_TmKeyStruct($elem));
     return $elem->toArray();
 }
 public function doAction()
 {
     if (empty($this->source_lang)) {
         $this->result['errors'][] = array("code" => -1, "message" => "missing source_lang");
     }
     if (empty($this->target_lang)) {
         $this->result['errors'][] = array("code" => -2, "message" => "missing target_lang");
     }
     if (empty($this->source)) {
         $this->result['errors'][] = array("code" => -3, "message" => "missing source");
     }
     if (empty($this->target)) {
         $this->result['errors'][] = array("code" => -4, "message" => "missing target");
     }
     //get Job Infos
     $job_data = getJobData((int) $this->id_job, $this->password);
     $pCheck = new AjaxPasswordCheck();
     //check for Password correctness
     if (empty($job_data) || !$pCheck->grantJobAccessByJobData($job_data, $this->password)) {
         $this->result['errors'][] = array("code" => -10, "message" => "wrong password");
         return;
     }
     $this->tm_keys = $job_data['tm_keys'];
     $this->checkLogin();
     $tms = Engine::getInstance($job_data['id_tms']);
     $config = $tms->getConfigStruct();
     //        $config = TMS::getConfigStruct();
     $config['segment'] = CatUtils::view2rawxliff($this->source);
     $config['translation'] = CatUtils::view2rawxliff($this->target);
     $config['source'] = $this->source_lang;
     $config['target'] = $this->target_lang;
     $config['email'] = "*****@*****.**";
     $config['id_user'] = array();
     //get job's TM keys
     try {
         $tm_keys = $this->tm_keys;
         if (self::isRevision()) {
             $this->userRole = TmKeyManagement_Filter::ROLE_REVISOR;
         } elseif ($this->userMail == $job_data['owner']) {
             $tm_keys = TmKeyManagement_TmKeyManagement::getOwnerKeys(array($tm_keys), 'r', 'tm');
             $tm_keys = json_encode($tm_keys);
         }
         //get TM keys with read grants
         $tm_keys = TmKeyManagement_TmKeyManagement::getJobTmKeys($tm_keys, 'r', 'tm', $this->uid, $this->userRole);
         if (is_array($tm_keys) && !empty($tm_keys)) {
             foreach ($tm_keys as $tm_key) {
                 $config['id_user'][] = $tm_key->key;
             }
         }
     } catch (Exception $e) {
         $this->result['errors'][] = array("code" => -11, "message" => "Cannot retrieve TM keys info.");
         return;
     }
     //prepare the errors report
     $set_code = array();
     /**
      * @var $tm_key TmKeyManagement_TmKeyStruct
      */
     //if there's no key
     if (empty($tm_keys)) {
         //try deleting anyway, it may be a public segment and it may work
         $TMS_RESULT = $tms->delete($config);
         $set_code[] = $TMS_RESULT;
     } else {
         //loop over the list of keys
         foreach ($tm_keys as $tm_key) {
             //issue a separate call for each key
             $config['id_user'] = $tm_key->key;
             $TMS_RESULT = $tms->delete($config);
             $set_code[] = $TMS_RESULT;
         }
     }
     $set_successful = true;
     if (array_search(false, $set_code, true)) {
         //There's an errors
         $set_successful = false;
     }
     $this->result['data'] = $set_successful ? "OK" : null;
     $this->result['code'] = $set_successful;
 }
예제 #4
0
 /**
  * @param $start                int
  * @param $step                 int
  * @param $search_in_pname      string|null
  * @param $search_source        string|null
  * @param $search_target        string|null
  * @param $search_status        string|null
  * @param $search_onlycompleted bool
  * @param $filter_enabled       bool
  * @param $project_id           int
  *
  * @return array
  * @throws Exception
  */
 public static function queryProjects($start, $step, $search_in_pname, $search_source, $search_target, $search_status, $search_onlycompleted, $filter_enabled, $project_id)
 {
     $data = getProjects($start, $step, $search_in_pname, $search_source, $search_target, $search_status, $search_onlycompleted, $filter_enabled, $project_id);
     $projects = array();
     $projectIDs = array();
     $project2info = array();
     //get project IDs from projects array
     foreach ($data as $item) {
         $projectIDs[] = $item['pid'];
     }
     if (empty($projectIDs)) {
         return array();
     }
     //get job data using job IDs
     $jobData = getJobsFromProjects($projectIDs, $search_source, $search_target, $search_status, $search_onlycompleted);
     $lang_handler = Langs_Languages::getInstance();
     //Prepare job data
     $project2jobChunk = array();
     foreach ($jobData as $job_array) {
         $job = array();
         /**
          * Assign job extracted variables
          */
         $job['id'] = $job_array['id'];
         $job['pid'] = $job_array['id_project'];
         $job['password'] = $job_array['password'];
         $job['source'] = $job_array['source'];
         $job['target'] = $job_array['target'];
         $job['subject'] = $job_array['subject'];
         $job['sourceTxt'] = $lang_handler->getLocalizedName($job['source']);
         $job['targetTxt'] = $lang_handler->getLocalizedName($job['target']);
         $job['create_date'] = $job_array['create_date'];
         $job['formatted_create_date'] = self::formatJobDate($job_array['create_date']);
         $job['job_first_segment'] = $job_array['job_first_segment'];
         $job['job_last_segment'] = $job_array['job_last_segment'];
         $job['mt_engine_name'] = $job_array['name'];
         $job['id_tms'] = $job_array['id_tms'];
         //generate and set job stats
         $jobStats = new WordCount_Struct();
         $jobStats->setDraftWords($job_array['DRAFT']);
         $jobStats->setRejectedWords($job_array['REJECT']);
         $jobStats->setTranslatedWords($job_array['TRANSLATED']);
         $jobStats->setApprovedWords($job_array['APPROVED']);
         //These would be redundant in response. Unset them.
         unset($job_array['DRAFT']);
         unset($job_array['REJECT']);
         unset($job_array['TRANSLATED']);
         unset($job_array['APPROVED']);
         $job['stats'] = CatUtils::getFastStatsForJob($jobStats);
         //generate and set job tm_keys
         $tm_keys_json = $job_array['tm_keys'];
         $tm_keys_json = TmKeyManagement_TmKeyManagement::getOwnerKeys(array($tm_keys_json));
         $tm_keys = array();
         foreach ($tm_keys_json as $tm_key_struct) {
             /**
              * @var $tm_key_struct TmKeyManagement_TmKeyStruct
              */
             $tm_keys[] = array("key" => $tm_key_struct->key, "r" => $tm_key_struct->r ? 'Lookup' : ' ', "w" => $tm_key_struct->w ? 'Update' : '');
         }
         $job['private_tm_key'] = json_encode($tm_keys);
         $job['disabled'] = $job_array['status_owner'] == Constants_JobStatus::STATUS_CANCELLED ? "disabled" : "";
         $job['status'] = $job_array['status_owner'];
         //These vars will be used in projects loop for some flag evaluation.
         $project2info[$job['pid']]['status'][] = $job['status'];
         $project2info[$job['pid']]['mt_engine_name'] = $job['mt_engine_name'];
         $project2info[$job['pid']]['id_tms'] = $job['id_tms'];
         $project2jobChunk[$job['pid']][$job['id']][$job['job_first_segment']] = $job;
     }
     //Prepare project data
     foreach ($data as $item) {
         $project = array();
         $project['id'] = $item['pid'];
         $project['name'] = $item['name'];
         $project['jobs'] = array();
         $project['no_active_jobs'] = true;
         $project['has_cancelled'] = 0;
         $project['has_archived'] = 0;
         $project['password'] = $item['password'];
         $project['tm_analysis'] = number_format($item['tm_analysis_wc'], 0, ".", ",");
         $project['jobs'] = $project2jobChunk[$project['id']];
         $project['no_active_jobs'] = $project['no_active_jobs'] ? ' allCancelled' : '';
         $project2info[$project['id']]['status'] = array_unique($project2info[$project['id']]['status']);
         $project['no_active_jobs'] = !in_array(Constants_JobStatus::STATUS_ACTIVE, $project2info[$project['id']]['status']) ? ' allCancelled' : '';
         $project['has_cancelled'] = in_array(Constants_JobStatus::STATUS_CANCELLED, $project2info[$project['id']]['status']);
         $project['has_archived'] = in_array(Constants_JobStatus::STATUS_ARCHIVED, $project2info[$project['id']]['status']);
         $project['mt_engine_name'] = $project2info[$project['id']]['mt_engine_name'];
         $project['id_tms'] = $project2info[$project['id']]['id_tms'];
         $projects[] = $project;
     }
     return $projects;
 }
 /**
  * if the description is empty, get cascading default descriptions
  *
  * First get the job key description, if empty, get the job owner email
  *
  * @param $key
  *
  * @return null|string
  * @throws Exception
  */
 private function __getDefaultDescription($key)
 {
     $description = null;
     $ownerKeys = TmKeyManagement_TmKeyManagement::getOwnerKeys(array($this->jobData['tm_keys']));
     //search the current key
     $currentKey = null;
     for ($i = 0; $i < count($ownerKeys); $i++) {
         if ($ownerKeys[$i]->key == $key) {
             $description = $ownerKeys[$i]->name;
         }
     }
     //return if something was found, avoid other computations
     if (!empty($description)) {
         return $description;
     }
     return $this->jobData['owner'];
 }
예제 #6
0
 public function testUniqueKeys()
 {
     $client_json = '[
                         {"key":"0000123MNO","name":"My MNO","r":1,"w":0},
                         {"key":"0000123ABC","name":"My ABC","r":0,"w":1},
                         {"key":"*****23ABC","name":"My ABC","r":0,"w":1}
                     ]';
     $server_json = '[
                         {"tm":true,"glos":false,"owner":true,"key":"0000123MNO","name":"My MNO","r":"1","w":"1","uid_transl":123,"uid_rev":null,"r_transl":0,"w_transl":1,"r_rev":null,"w_rev":null,"source":null,"target":null},
                         {"tm":true,"glos":false,"owner":false,"key":"0000123ABC","name":"","r":null,"w":null,"uid_transl":123,"uid_rev":456,"r_transl":1,"w_transl":0,"r_rev":1,"w_rev":1,"source":null,"target":null}
                     ]';
     /*
      * Expected Exception because the same key can not be sent twice
      *
      */
     $this->setExpectedException('Exception', "A key is already present in this project.", 5);
     TmKeyManagement_TmKeyManagement::mergeJsonKeys($client_json, $server_json, TmKeyManagement_Filter::ROLE_TRANSLATOR, 123);
 }
예제 #7
0
     $amqHandlerSubscriber->incrementAnalyzedCount($pid, 0, 0);
     $amqHandlerSubscriber->decrementTotalForWaitingProjects($pid);
     $amqHandlerSubscriber->tryToCloseProject($pid, $my_pid);
     $amqHandlerSubscriber->ack($msg);
     continue;
 }
 //reset vectors
 $matches = array();
 $tms_match = array();
 $mt_result = array();
 $_config = array();
 $_config['segment'] = $text;
 $_config['source'] = $source;
 $_config['target'] = $target;
 $_config['email'] = "*****@*****.**";
 $tm_keys = TmKeyManagement_TmKeyManagement::getJobTmKeys($objQueue['tm_keys'], 'r', 'tm');
 if (is_array($tm_keys) && !empty($tm_keys)) {
     foreach ($tm_keys as $tm_key) {
         $_config['id_user'][] = $tm_key->key;
     }
 }
 $_config['num_result'] = 3;
 $id_mt_engine = $objQueue['id_mt_engine'];
 $id_tms = $objQueue['id_tms'];
 $_TMS = $id_tms;
 //request
 /**
  * Call Memory Server for matches if it's enabled
  */
 $tms_enabled = false;
 if ($_TMS == 1) {
예제 #8
0
 public function doAction()
 {
     if (is_null($this->source) || $this->source === '') {
         $this->result['errors'][] = array("code" => -1, "message" => "missing source segment");
     }
     if (is_null($this->target) || $this->target === '') {
         $this->result['errors'][] = array("code" => -2, "message" => "missing target segment");
     }
     if (empty($this->source_lang)) {
         $this->result['errors'][] = array("code" => -3, "message" => "missing source lang");
     }
     if (empty($this->target_lang)) {
         $this->result['errors'][] = array("code" => -2, "message" => "missing target lang");
     }
     if (empty($this->id_job)) {
         $this->result['errors'][] = array("code" => -4, "message" => "id_job not valid");
         $msg = "\n\n Critical. Quit. \n\n " . var_export(array_merge($this->result, $_POST), true);
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
         // critical. Quit.
         return -1;
     }
     //get Job Infos, we need only a row of jobs ( split )
     $job_data = getJobData((int) $this->id_job, $this->password);
     $pCheck = new AjaxPasswordCheck();
     //check for Password correctness
     if (empty($job_data)) {
         $this->result['errors'][] = array("code" => -101, "message" => "error fetching job data");
     }
     if (empty($this->result['errors']) && !$pCheck->grantJobAccessByJobData($job_data, $this->password)) {
         $this->result['errors'][] = array("code" => -10, "message" => "wrong password");
     }
     if (!empty($this->result['errors'])) {
         $msg = "\n\n Error \n\n " . var_export(array_merge($this->result, $_POST), true);
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
         return -1;
     }
     $id_tms = $job_data['id_tms'];
     $tm_keys = $job_data['tm_keys'];
     if ($id_tms != 0) {
         $tms = Engine::getInstance(1);
         /**
          * @var $tms Engines_MyMemory
          */
         $config = $tms->getConfigStruct();
         $config['segment'] = CatUtils::view2rawxliff($this->source);
         $config['translation'] = CatUtils::view2rawxliff($this->target);
         $config['source'] = $this->source_lang;
         $config['target'] = $this->target_lang;
         $config['email'] = "*****@*****.**";
         //Props
         $config['prop'] = json_encode(CatUtils::getTMProps($job_data));
         //instantiate TMS object
         $result = array();
         $this->checkLogin();
         try {
             if (self::isRevision()) {
                 $this->userRole = TmKeyManagement_Filter::ROLE_REVISOR;
             }
             //find all the job's TMs with write grants and make a contribution to them
             $tm_keys = TmKeyManagement_TmKeyManagement::getJobTmKeys($tm_keys, 'w', 'tm', $this->uid, $this->userRole);
             if (!empty($tm_keys)) {
                 unset($config['id_user']);
                 foreach ($tm_keys as $i => $tm_info) {
                     $config['id_user'] = $tm_info->key;
                     $res = $tms->set($config);
                     if (!$res) {
                         $result[] = $res;
                         $this->result['errors'][] = array("code" => -5, "message" => "Set contribution error for key " . $tm_info->name);
                     }
                 }
             } else {
                 $res = $tms->set($config);
                 if (!$res) {
                     $result[] = $res;
                     $this->result['errors'][] = array("code" => -5, "message" => "Set contribution error");
                 }
             }
         } catch (Exception $e) {
             $this->result['errors'][] = array("code" => -6, "message" => "Error while retrieving job's TM.");
             Log::doLog(__METHOD__ . " -> " . $e->getMessage());
         }
         //if translator_username is empty no key is added to MyMemory API SET query string, so, anonymous by default
         if (count($result)) {
             $this->result['code'] = -1;
             $this->result['data'] = "KO";
             Log::doLog("Set Contribution Failed.");
             Log::doLog(var_export($_POST, true));
             return -1;
         }
         $this->result['code'] = 1;
         $this->result['data'] = "OK";
     } else {
         $this->result['code'] = 1;
         $this->result['data'] = "NOCONTRIB_OK";
     }
 }
예제 #9
0
 /**
  * Get matches from MyMemory and other engines
  *
  * @param $queueElement QueueElement
  *
  * @return array
  * @throws Exception
  */
 protected function _getMatches(QueueElement $queueElement)
 {
     $_config = array();
     $_config['segment'] = $queueElement->params->segment;
     $_config['source'] = $queueElement->params->source;
     $_config['target'] = $queueElement->params->target;
     $_config['email'] = \INIT::$MYMEMORY_TM_API_KEY;
     $tm_keys = \TmKeyManagement_TmKeyManagement::getJobTmKeys($queueElement->params->tm_keys, 'r', 'tm');
     if (is_array($tm_keys) && !empty($tm_keys)) {
         foreach ($tm_keys as $tm_key) {
             $_config['id_user'][] = $tm_key->key;
         }
     }
     $_config['num_result'] = 3;
     $id_mt_engine = $queueElement->params->id_mt_engine;
     $id_tms = $queueElement->params->id_tms;
     $_TMS = $id_tms;
     //request
     /**
      * Call Memory Server for matches if it's enabled
      */
     $tms_enabled = false;
     if ($_TMS == 1) {
         /**
          * MyMemory Enabled
          */
         $_config['get_mt'] = true;
         $_config['mt_only'] = false;
         if ($id_mt_engine != 1) {
             /**
              * Don't get MT contribution from MyMemory ( Custom MT )
              */
             $_config['get_mt'] = false;
         }
         $tms_enabled = true;
     } elseif ($_TMS == 0 && $id_mt_engine == 1) {
         /**
          * MyMemory disabled but MT Enabled and it is NOT a Custom one
          * So tell to MyMemory to get MT only
          */
         $_config['get_mt'] = true;
         $_config['mt_only'] = true;
         $_TMS = 1;
         /* MyMemory */
         $tms_enabled = true;
     }
     /*
      * This will be ever executed without damages because
      * fastAnalysis set Project as DONE when
      * MyMemory is disabled and MT is Disabled Too
      *
      * So don't worry, perform TMS Analysis
      *
      */
     if ($tms_enabled) {
         /**
          * @var $tms \Engines_MyMemory
          */
         $tms = \Engine::getInstance($_TMS);
         $tms->doLog = false;
         $config = $tms->getConfigStruct();
         $config = array_merge($config, $_config);
         $tms_match = $tms->get($config);
         /**
          * If No results found. Re-Queue
          *
          * MyMemory can return null if an error occurs (e.g http response code is 404, 410, 500, 503, etc.. )
          */
         if ($tms_match === null) {
             $this->_doLog("--- (Worker " . $this->_workerPid . ") : Error from MyMemory. NULL received.");
             throw new ReQueueException("--- (Worker " . $this->_workerPid . ") : Error from MyMemory. NULL received.", self::ERR_REQUEUE);
         }
         $tms_match = $tms_match->get_matches_as_array();
     }
     /**
      * Call External MT engine if it is a custom one ( mt not requested from MyMemory )
      */
     if ($id_mt_engine > 1) {
         try {
             $mt = \Engine::getInstance($id_mt_engine);
             $config = $mt->getConfigStruct();
             $config = array_merge($config, $_config);
             $mt_result = $mt->get($config);
             if (isset($mt_result['error']['code'])) {
                 $mt_result = false;
             }
         } catch (\Exception $e) {
             $this->_doLog($e->getMessage());
         }
     }
     $matches = array();
     if (!empty($tms_match)) {
         $matches = $tms_match;
     }
     if (isset($mt_result) && !empty($mt_result)) {
         $matches[] = $mt_result;
         usort($matches, "Executor::_compareScore");
     }
     /**
      * If No results found. Re-Queue
      */
     if (empty($matches) || !is_array($matches)) {
         $this->_doLog("--- (Worker " . $this->_workerPid . ") : No contribution found for this segment.");
         $this->_forceSetSegmentAnalyzed($queueElement);
         throw new EmptyElementException("--- (Worker " . $this->_workerPid . ") : No contribution found for this segment.", self::ERR_EMPTY_ELEMENT);
     }
     return $matches;
 }
예제 #10
0
 /**
  * When Called it perform the controller action to retrieve/manipulate data
  *
  * @return mixed
  */
 function doAction()
 {
     //if some error occured, stop execution.
     if (count(@$this->result['errors'])) {
         return false;
     }
     /*
      * The client send data as structured json, for now take it as a plain structure
      *
      *   $clientDecodedJson = Array
      *       (
      *           [owner] => Array
      *               (
      *                   [0] => Array
      *                       (
      *                           [tm] => 1
      *                           [glos] => 1
      *                           [owner] => 1
      *                           [key] => ***************da9a9
      *                           [name] =>
      *                           [r] => 1
      *                           [w] => 1
      *                       )
      *
      *               )
      *
      *           [mine] => Array
      *               (
      *                   [0] => Array
      *                       (
      *                           [tm] => 1
      *                           [glos] => 1
      *                           [owner] => 0
      *                           [key] => 952681baffb9c147b346
      *                           [name] => cgjhkmfgdcjkfh
      *                           [r] => 1
      *                           [w] => 1
      *                       )
      *
      *               )
      *
      *           [anonymous] => Array
      *               (
      *                   [0] => Array
      *                       (
      *                           [tm] => 1
      *                           [glos] => 1
      *                           [owner] => 0
      *                           [key] => ***************882eb
      *                           [name] => Chiave di anonimo
      *                           [r] => 0
      *                           [w] => 0
      *                       )
      *
      *               )
      *
      *       )
      *
      */
     $tm_keys = json_decode($this->tm_keys, true);
     /*
      * sanitize owner role key type
      */
     foreach ($tm_keys['mine'] as $k => $val) {
         $tm_keys['mine'][$k]['owner'] = $this->userRole == TmKeyManagement_Filter::OWNER;
     }
     $tm_keys = array_merge($tm_keys['ownergroup'], $tm_keys['mine'], $tm_keys['anonymous']);
     $this->tm_keys = json_encode($tm_keys);
     try {
         $totalTmKeys = TmKeyManagement_TmKeyManagement::mergeJsonKeys($this->tm_keys, $this->jobData['tm_keys'], $this->userRole, $this->uid);
         Log::doLog('Before:');
         Log::doLog($this->jobData['tm_keys']);
         Log::doLog('After:');
         Log::doLog(json_encode($totalTmKeys));
         TmKeyManagement_TmKeyManagement::setJobTmKeys($this->job_id, $this->job_pass, $totalTmKeys);
         $this->result['data'] = 'OK';
     } catch (Exception $e) {
         $this->result['data'] = 'KO';
         $this->result['errors'][] = array("code" => $e->getCode(), "message" => $e->getMessage());
     }
 }
예제 #11
0
 protected function _delete($config)
 {
     $tm_keys = $this->job_info['tm_keys'];
     if (self::isRevision()) {
         $this->userRole = TmKeyManagement_Filter::ROLE_REVISOR;
     }
     //get TM keys with read grants
     $tm_keys = TmKeyManagement_TmKeyManagement::getJobTmKeys($tm_keys, 'w', 'glos', $this->uid, $this->userRole);
     $config['segment'] = CatUtils::view2rawxliff($config['segment']);
     $config['translation'] = CatUtils::view2rawxliff($config['translation']);
     //prepare the error report
     $set_code = array();
     //set the glossary entry for each key with write grants
     if (count($tm_keys)) {
         /**
          * @var $tm_key TmKeyManagement_TmKeyStruct
          */
         foreach ($tm_keys as $tm_key) {
             $config['id_user'] = $tm_key->key;
             $TMS_RESULT = $this->_TMS->delete($config);
             $set_code[] = $TMS_RESULT;
         }
     }
     $set_successful = true;
     if (array_search(false, $set_code, true)) {
         $set_successful = false;
     }
     $this->result['code'] = $set_successful;
     $this->result['data'] = $set_successful ? 'OK' : null;
 }
 $pretranslate_100 = $segment['pretranslate_100'];
 $text = $segment['segment'];
 if ($raw_wc == 0) {
     echo "--- (child {$my_pid}) : empty segment. deleting lock and continue\n";
     continue;
 }
 //reset vectors
 $matches = array();
 $tms_match = array();
 $mt_result = array();
 $_config = array();
 $_config['segment'] = $text;
 $_config['source'] = $source;
 $_config['target'] = $target;
 $_config['email'] = "*****@*****.**";
 $tm_keys = TmKeyManagement_TmKeyManagement::getJobTmKeys($segment['tm_keys'], 'r', 'tm');
 if (is_array($tm_keys) && !empty($tm_keys)) {
     foreach ($tm_keys as $tm_key) {
         $_config['id_user'][] = $tm_key->key;
     }
 }
 $_config['num_result'] = 3;
 $id_mt_engine = $segment['id_mt_engine'];
 $id_tms = $segment['id_tms'];
 $_TMS = $id_tms;
 //request
 /**
  * Call Memory Server for matches if it's enabled
  */
 $tms_enabled = false;
 if ($_TMS == 1) {