Пример #1
0
 public function doAction()
 {
     $this->generateAuthURL();
     //pay a little query to avoid to fetch 5000 rows
     $this->jobData = $jobData = getJobData($this->jid, $this->password);
     $wStruct = new WordCount_Struct();
     $wStruct->setIdJob($this->jid);
     $wStruct->setJobPassword($this->password);
     $wStruct->setNewWords($jobData['new_words']);
     $wStruct->setDraftWords($jobData['draft_words']);
     $wStruct->setTranslatedWords($jobData['translated_words']);
     $wStruct->setApprovedWords($jobData['approved_words']);
     $wStruct->setRejectedWords($jobData['rejected_words']);
     if ($jobData['status'] == Constants_JobStatus::STATUS_ARCHIVED || $jobData['status'] == Constants_JobStatus::STATUS_CANCELLED) {
         //this job has been archived
         $this->job_archived = true;
         $this->job_owner_email = $jobData['job_owner'];
     }
     $tmp = CatUtils::getEditingLogData($this->jid, $this->password);
     $this->data = $tmp[0];
     $this->stats = $tmp[1];
     $this->job_stats = CatUtils::getFastStatsForJob($wStruct);
     $proj = getProject($jobData['id_project']);
     $this->project_status = $proj[0];
 }
Пример #2
0
 public function doAction()
 {
     $this->generateAuthURL();
     //pay a little query to avoid to fetch 5000 rows
     $this->data = $jobData = getJobData($this->jid, $this->password);
     $wStruct = new WordCount_Struct();
     $wStruct->setIdJob($this->jid);
     $wStruct->setJobPassword($this->password);
     $wStruct->setNewWords($jobData['new_words']);
     $wStruct->setDraftWords($jobData['draft_words']);
     $wStruct->setTranslatedWords($jobData['translated_words']);
     $wStruct->setApprovedWords($jobData['approved_words']);
     $wStruct->setRejectedWords($jobData['rejected_words']);
     if ($jobData['status'] == Constants_JobStatus::STATUS_ARCHIVED || $jobData['status'] == Constants_JobStatus::STATUS_CANCELLED) {
         //this job has been archived
         $this->job_archived = true;
         $this->job_owner_email = $jobData['job_owner'];
     }
     $this->job_stats = CatUtils::getFastStatsForJob($wStruct);
     $proj = getProject($jobData['id_project']);
     $this->project_status = $proj[0];
     /**
      * Retrieve information about job errors
      * ( Note: these information are fed by the revision process )
      * @see setRevisionController
      */
     $jobQA = new Revise_JobQA($this->jid, $this->password, $wStruct->getTotal());
     $jobQA->retrieveJobErrorTotals();
     $jobVote = $jobQA->evalJobVote();
     $this->totalJobWords = $wStruct->getTotal();
     $this->qa_data = $jobQA->getQaData();
     $this->qa_overall_text = $jobVote['minText'];
     $this->qa_overall_avg = $jobVote['avg'];
     $this->qa_equivalent_class = $jobVote['equivalent_class'];
 }
Пример #3
0
 public function initializeJobWordCount($id_job, $jPassword)
 {
     $_details = getStatsForJob($id_job, null, $jPassword);
     //Log::doLog( "--- trying to Iitialize/reset job total word count." );
     $job_details = array_pop($_details);
     //get the row
     $wStruct = new WordCount_Struct();
     $wStruct->setIdJob($job_details['id']);
     $wStruct->setJobPassword($jPassword);
     $wStruct->setNewWords($job_details[Constants_TranslationStatus::STATUS_NEW]);
     $wStruct->setDraftWords($job_details[Constants_TranslationStatus::STATUS_DRAFT] - $job_details[Constants_TranslationStatus::STATUS_NEW]);
     $wStruct->setTranslatedWords($job_details[Constants_TranslationStatus::STATUS_TRANSLATED]);
     $wStruct->setApprovedWords($job_details[Constants_TranslationStatus::STATUS_APPROVED]);
     $wStruct->setRejectedWords($job_details[Constants_TranslationStatus::STATUS_REJECTED]);
     initializeWordCount($wStruct);
     //Log::doLog( $wStruct );
     return $wStruct;
 }
Пример #4
0
 /**
  * @param WordCount_Struct $wCount
  *
  * @return array
  */
 public static function getFastStatsForJob(WordCount_Struct $wCount)
 {
     $job_stats = array();
     $job_stats['id'] = $wCount->getIdJob();
     //        $job_stats[ 'NEW' ]        = $wCount->getNewWords();
     $job_stats['DRAFT'] = $wCount->getNewWords() + $wCount->getDraftWords();
     $job_stats['TRANSLATED'] = $wCount->getTranslatedWords();
     $job_stats['APPROVED'] = $wCount->getApprovedWords();
     $job_stats['REJECTED'] = $wCount->getRejectedWords();
     //sometimes new_words + draft_words < 0 (why?). If it happens, set draft words to 0
     if ($job_stats['DRAFT'] < 0) {
         $job_stats['DRAFT'] = 0;
     }
     //avoid division by zero warning
     $total = $wCount->getTotal();
     $job_stats['TOTAL'] = $total == 0 ? 1 : $total;
     $job_stats = self::_getStatsForJob($job_stats, true);
     //true set estimation check if present
     return self::_performanceEstimationTime($job_stats);
 }
Пример #5
0
 /**
  * @return array
  */
 private function getFastStatsForJob()
 {
     $wStruct = new WordCount_Struct();
     $wStruct->setIdJob($this->jid);
     $wStruct->setJobPassword($this->password);
     $wStruct->setNewWords($this->jobData['new_words']);
     $wStruct->setDraftWords($this->jobData['draft_words']);
     $wStruct->setTranslatedWords($this->jobData['translated_words']);
     $wStruct->setApprovedWords($this->jobData['approved_words']);
     $wStruct->setRejectedWords($this->jobData['rejected_words']);
     return CatUtils::getFastStatsForJob($wStruct);
 }
Пример #6
0
 /**
  * When Called it perform the controller action to retrieve/manipulate data
  *
  * @throws Exception
  */
 public function doAction()
 {
     if (!empty($this->result['errors'])) {
         return;
     }
     $job_data = getJobData((int) $this->id_job, $this->password_job);
     if (empty($job_data)) {
         $msg = "Error : empty job data \n\n " . var_export($_POST, true) . "\n";
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
     }
     //add check for job status archived.
     if (strtolower($job_data['status']) == Constants_JobStatus::STATUS_ARCHIVED) {
         $this->result['errors'][] = array("code" => -6, "message" => "job archived");
     }
     $this->parseIDSegment();
     $pCheck = new AjaxPasswordCheck();
     //check for Password correctness
     if (empty($job_data) || !$pCheck->grantJobAccessByJobData($job_data, $this->password_job, $this->id_segment)) {
         $this->result['errors'][] = array("code" => -7, "message" => "wrong password");
     }
     $wStruct = new WordCount_Struct();
     $wStruct->setIdJob($this->id_job);
     $wStruct->setJobPassword($this->password_job);
     $wStruct->setNewWords($job_data['new_words']);
     $wStruct->setDraftWords($job_data['draft_words']);
     $wStruct->setTranslatedWords($job_data['translated_words']);
     $wStruct->setApprovedWords($job_data['approved_words']);
     $wStruct->setRejectedWords($job_data['rejected_words']);
     $reviseDAO = new Revise_ReviseDAO(Database::obtain());
     //store segment revision in DB
     $revisionStruct = Revise_ReviseStruct::getStruct();
     $revisionStruct->id_job = $this->id_job;
     $revisionStruct->id_segment = $this->id_segment;
     //check if an old revision exists. If it does, retrieve it and save it.
     $oldRevision = $reviseDAO->read($revisionStruct);
     $oldRevision = isset($oldRevision[0]) ? $oldRevision[0] : Revise_ReviseStruct::setDefaultValues(Revise_ReviseStruct::getStruct());
     $revisionStruct->err_typing = $this->err_typing;
     $revisionStruct->err_translation = $this->err_translation;
     $revisionStruct->err_terminology = $this->err_terminology;
     $revisionStruct->err_language = $this->err_language;
     $revisionStruct->err_style = $this->err_style;
     $revisionStruct->original_translation = $this->original_translation;
     //save the new revision in the database.
     try {
         $reviseDAO->create($revisionStruct);
     } catch (Exception $e) {
         Log::doLog(__METHOD__ . " -> " . $e->getMessage());
         $this->result['errors'][] = array('code' => -4, 'message' => "Insert failed");
         return;
     }
     /**
      * Refresh error counters in the job table
      */
     $errorCountStruct = new ErrorCount_DiffStruct($oldRevision, $revisionStruct);
     $errorCountStruct->setIdJob($this->id_job);
     $errorCountStruct->setJobPassword($this->password_job);
     $errorCountDao = new ErrorCount_ErrorCountDAO(Database::obtain());
     try {
         $errorCountDao->update($errorCountStruct);
     } catch (Exception $e) {
         Log::doLog(__METHOD__ . " -> " . $e->getMessage());
         $this->result['errors'][] = array('code' => -5, 'message' => "Did not update job error counters.");
         return;
     }
     /**
      * Retrieve information about job errors
      * ( Note: these information are fed by the revision process )
      * @see setRevisionController
      */
     $jobQA = new Revise_JobQA($this->id_job, $this->password_job, $wStruct->getTotal());
     $jobQA->retrieveJobErrorTotals();
     $jobVote = $jobQA->evalJobVote();
     $this->result['data']['message'] = 'OK';
     $this->result['data']['stat_quality'] = $jobQA->getQaData();
     $this->result['data']['overall_quality'] = $jobVote['minText'];
     $this->result['data']['overall_quality_class'] = strtolower(str_replace(' ', '', $jobVote['minText']));
 }
Пример #7
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' : '&nbsp;', "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;
 }
Пример #8
0
 public function doAction()
 {
     $files_found = array();
     $lang_handler = Langs_Languages::getInstance();
     $data = getSegmentsInfo($this->jid, $this->password);
     if (empty($data) or $data < 0) {
         $this->job_not_found = true;
         //stop execution
         return;
     }
     //retrieve job owner. It will be useful also if the job is archived or cancelled
     $this->job_owner = $data[0]['job_owner'] != "" ? $data[0]['job_owner'] : "*****@*****.**";
     if ($data[0]['status'] == Constants_JobStatus::STATUS_CANCELLED) {
         $this->job_cancelled = true;
         //stop execution
         return;
     }
     if ($data[0]['status'] == Constants_JobStatus::STATUS_ARCHIVED) {
         $this->job_archived = true;
         //stop execution
         return;
     }
     /*
      * I prefer to use a programmatic approach to the check for the archive date instead of a pure query
      * because the query to check "Utils::getArchivableJobs($this->jid)" should be
      * executed every time a job is loaded ( F5 or CTRL+R on browser ) and it cost some milliseconds ( ~0.1s )
      * and it is little heavy for the database.
      * We use the data we already have from last query and perform
      * the check on the last translation only if the job is older than 30 days
      *
      */
     $lastUpdate = new DateTime($data[0]['last_update']);
     $oneMonthAgo = new DateTime();
     $oneMonthAgo->modify('-' . INIT::JOB_ARCHIVABILITY_THRESHOLD . ' days');
     if ($lastUpdate < $oneMonthAgo && !$this->job_cancelled) {
         $lastTranslationInJob = new Datetime(getLastTranslationDate($this->jid));
         if ($lastTranslationInJob < $oneMonthAgo) {
             $res = "job";
             $new_status = Constants_JobStatus::STATUS_ARCHIVED;
             updateJobsStatus($res, $this->jid, $new_status, null, null, $this->password);
             $this->job_archived = true;
         }
     }
     foreach ($data as $i => $job) {
         $this->project_status = $job;
         // get one row values for the project are the same for every row
         if (empty($this->pname)) {
             $this->pname = $job['pname'];
             $this->downloadFileName = $job['pname'] . ".zip";
             // will be overwritten below in case of one file job
         }
         if (empty($this->last_opened_segment)) {
             $this->last_opened_segment = $job['last_opened_segment'];
         }
         if (empty($this->cid)) {
             $this->cid = $job['cid'];
         }
         if (empty($this->pid)) {
             $this->pid = $job['pid'];
         }
         if (empty($this->create_date)) {
             $this->create_date = $job['create_date'];
         }
         if (empty($this->source_code)) {
             $this->source_code = $job['source'];
         }
         if (empty($this->target_code)) {
             $this->target_code = $job['target'];
         }
         if (empty($this->source)) {
             $s = explode("-", $job['source']);
             $source = strtoupper($s[0]);
             $this->source = $source;
             $this->source_rtl = $lang_handler->isRTL(strtolower($this->source)) ? ' rtl-source' : '';
         }
         if (empty($this->target)) {
             $t = explode("-", $job['target']);
             $target = strtoupper($t[0]);
             $this->target = $target;
             $this->target_rtl = $lang_handler->isRTL(strtolower($this->target)) ? ' rtl-target' : '';
         }
         //check if language belongs to supported right-to-left languages
         if ($job['status'] == Constants_JobStatus::STATUS_ARCHIVED) {
             $this->job_archived = true;
             $this->job_owner = $data[0]['job_owner'];
         }
         $id_file = $job['id_file'];
         if (!isset($this->data["{$id_file}"])) {
             $files_found[] = $job['filename'];
         }
         $wStruct = new WordCount_Struct();
         $wStruct->setIdJob($this->jid);
         $wStruct->setJobPassword($this->password);
         $wStruct->setNewWords($job['new_words']);
         $wStruct->setDraftWords($job['draft_words']);
         $wStruct->setTranslatedWords($job['translated_words']);
         $wStruct->setApprovedWords($job['approved_words']);
         $wStruct->setRejectedWords($job['rejected_words']);
         unset($job['id_file']);
         unset($job['source']);
         unset($job['target']);
         unset($job['source_code']);
         unset($job['target_code']);
         unset($job['mime_type']);
         unset($job['filename']);
         unset($job['jid']);
         unset($job['pid']);
         unset($job['cid']);
         unset($job['tid']);
         unset($job['pname']);
         unset($job['create_date']);
         unset($job['owner']);
         unset($job['last_opened_segment']);
         unset($job['new_words']);
         unset($job['draft_words']);
         unset($job['translated_words']);
         unset($job['approved_words']);
         unset($job['rejected_words']);
         //For projects created with No tm analysis enabled
         if ($wStruct->getTotal() == 0 && ($job['status_analysis'] == Constants_ProjectStatus::STATUS_DONE || $job['status_analysis'] == Constants_ProjectStatus::STATUS_NOT_TO_ANALYZE)) {
             $wCounter = new WordCount_Counter();
             $wStruct = $wCounter->initializeJobWordCount($this->jid, $this->password);
             Log::doLog("BackWard compatibility set Counter.");
         }
         $this->job_stats = CatUtils::getFastStatsForJob($wStruct);
     }
     //Needed because a just created job has last_opened segment NULL
     if (empty($this->last_opened_segment)) {
         $this->last_opened_segment = getFirstSegmentId($this->jid, $this->password);
     }
     $this->first_job_segment = $this->project_status['job_first_segment'];
     $this->last_job_segment = $this->project_status['job_last_segment'];
     if (count($files_found) == 1) {
         $this->downloadFileName = $files_found[0];
     }
     /**
      * get first segment of every file
      */
     $fileInfo = getFirstSegmentOfFilesInJob($this->jid);
     $TotalPayable = array();
     foreach ($fileInfo as &$file) {
         $file['file_name'] = ZipArchiveExtended::getFileName($file['file_name']);
         $TotalPayable[$file['id_file']]['TOTAL_FORMATTED'] = $file['TOTAL_FORMATTED'];
     }
     $this->firstSegmentOfFiles = json_encode($fileInfo);
     $this->fileCounter = json_encode($TotalPayable);
     list($uid, $user_email) = $this->getLoginUserParams();
     if (self::isRevision()) {
         $this->userRole = TmKeyManagement_Filter::ROLE_REVISOR;
     } elseif ($user_email == $data[0]['job_owner']) {
         $this->userRole = TmKeyManagement_Filter::OWNER;
     } else {
         $this->userRole = TmKeyManagement_Filter::ROLE_TRANSLATOR;
     }
     /*
      * Take the keys of the user
      */
     try {
         $_keyList = new TmKeyManagement_MemoryKeyDao(Database::obtain());
         $dh = new TmKeyManagement_MemoryKeyStruct(array('uid' => $uid));
         $keyList = $_keyList->read($dh);
     } catch (Exception $e) {
         $keyList = array();
         Log::doLog($e->getMessage());
     }
     $reverse_lookup_user_personal_keys = array('pos' => array(), 'elements' => array());
     /**
      * Set these keys as editable for the client
      *
      * @var $keyList TmKeyManagement_MemoryKeyStruct[]
      */
     foreach ($keyList as $_j => $key) {
         /**
          * @var $_client_tm_key TmKeyManagement_TmKeyStruct
          */
         //create a reverse lookup
         $reverse_lookup_user_personal_keys['pos'][$_j] = $key->tm_key->key;
         $reverse_lookup_user_personal_keys['elements'][$_j] = $key;
         $this->_keyList['totals'][$_j] = new TmKeyManagement_ClientTmKeyStruct($key->tm_key);
     }
     /*
      * Now take the JOB keys
      */
     $job_keyList = json_decode($data[0]['tm_keys'], true);
     $this->tid = count($job_keyList) > 0;
     /**
      * Start this N^2 cycle from keys of the job,
      * these should be statistically lesser than the keys of the user
      *
      * @var $keyList array
      */
     foreach ($job_keyList as $jobKey) {
         $jobKey = new TmKeyManagement_ClientTmKeyStruct($jobKey);
         if ($this->isLoggedIn() && count($reverse_lookup_user_personal_keys['pos'])) {
             /*
              * If user has some personal keys, check for the job keys if they are present, and obfuscate
              * when they are not
              */
             $_index_position = array_search($jobKey->key, $reverse_lookup_user_personal_keys['pos']);
             if ($_index_position !== false) {
                 //i found a key in the job that is present in my database
                 //i'm owner?? and the key is an owner type key?
                 if (!$jobKey->owner && $this->userRole != TmKeyManagement_Filter::OWNER) {
                     $jobKey->r = $jobKey->{TmKeyManagement_Filter::$GRANTS_MAP[$this->userRole]['r']};
                     $jobKey->w = $jobKey->{TmKeyManagement_Filter::$GRANTS_MAP[$this->userRole]['w']};
                     $jobKey = $jobKey->hideKey($uid);
                 } else {
                     if ($jobKey->owner && $this->userRole != TmKeyManagement_Filter::OWNER) {
                         // I'm not the job owner, but i know the key because it is in my keyring
                         // so, i can upload and download TMX, but i don't want it to be removed from job
                         // in tm.html relaxed the control to "key.edit" to enable buttons
                         //                            $jobKey = $jobKey->hideKey( $uid ); // enable editing
                     } else {
                         if ($jobKey->owner && $this->userRole == TmKeyManagement_Filter::OWNER) {
                             //do Nothing
                         }
                     }
                 }
                 unset($this->_keyList['totals'][$_index_position]);
             } else {
                 /*
                  * This is not a key of that user, set right and obfuscate
                  */
                 $jobKey->r = true;
                 $jobKey->w = true;
                 $jobKey = $jobKey->hideKey(-1);
             }
             $this->_keyList['job_keys'][] = $jobKey;
         } else {
             /*
              * This user is anonymous or it has no keys in its keyring, obfuscate all
              */
             $jobKey->r = true;
             $jobKey->w = true;
             $this->_keyList['job_keys'][] = $jobKey->hideKey(-1);
         }
     }
     //clean unordered keys
     $this->_keyList['totals'] = array_values($this->_keyList['totals']);
     /**
      * Retrieve information about job errors
      * ( Note: these information are fed by the revision process )
      * @see setRevisionController
      */
     $jobQA = new Revise_JobQA($this->jid, $this->password, $wStruct->getTotal());
     $jobQA->retrieveJobErrorTotals();
     $jobVote = $jobQA->evalJobVote();
     $this->qa_data = json_encode($jobQA->getQaData());
     $this->qa_overall = $jobVote['minText'];
     $engine = new EnginesModel_EngineDAO(Database::obtain());
     //this gets all engines of the user
     if ($this->isLoggedIn()) {
         $engineQuery = new EnginesModel_EngineStruct();
         $engineQuery->type = 'MT';
         $engineQuery->uid = $uid;
         $engineQuery->active = 1;
         $mt_engines = $engine->read($engineQuery);
     } else {
         $mt_engines = array();
     }
     // this gets MyMemory
     $engineQuery = new EnginesModel_EngineStruct();
     $engineQuery->type = 'TM';
     $engineQuery->active = 1;
     $tms_engine = $engine->setCacheTTL(3600 * 24 * 30)->read($engineQuery);
     //this gets MT engine active for the job
     $engineQuery = new EnginesModel_EngineStruct();
     $engineQuery->id = $this->project_status['id_mt_engine'];
     $engineQuery->active = 1;
     $active_mt_engine = $engine->setCacheTTL(60 * 10)->read($engineQuery);
     /*
      * array_unique cast EnginesModel_EngineStruct to string
      *
      * EnginesModel_EngineStruct implements __toString method
      *
      */
     $this->translation_engines = array_unique(array_merge($active_mt_engine, $tms_engine, $mt_engines));
 }
Пример #9
0
 public function doAction()
 {
     try {
         $this->_checkData();
     } catch (Exception $e) {
         if ($e->getCode() == -1) {
             Utils::sendErrMailReport($e->getMessage());
         }
         Log::doLog($e->getMessage());
         return $e->getCode();
     }
     //check tag mismatch
     //get original source segment, first
     $segment = getSegment($this->id_segment);
     //compare segment-translation and get results
     $check = new QA($segment['segment'], $this->translation);
     $check->performConsistencyCheck();
     if ($check->thereAreWarnings()) {
         $err_json = $check->getWarningsJSON();
         $translation = $this->translation;
     } else {
         $err_json = '';
         $translation = $check->getTrgNormalized();
     }
     /*
      * begin stats counter
      *
      * It works good with default InnoDB Isolation level
      *
      * REPEATABLE-READ offering a row level lock for this id_segment
      *
      */
     $db = Database::obtain();
     $db->begin();
     $old_translation = getCurrentTranslation($this->id_job, $this->id_segment);
     //        $old_version = ( empty( $old_translation['translation_date'] ) ? '0' : date_create( $old_translation['translation_date'] )->getTimestamp() );
     //        if( $this->client_target_version != $old_version ){
     //            $this->result[ 'errors' ][ ] = array( "code" => -102, "message" => "Translation version mismatch" );
     //            $db->rollback();
     //            return false;
     //        }
     //if volume analysis is not enabled and no translation rows exists
     //create the row
     if (!INIT::$VOLUME_ANALYSIS_ENABLED && empty($old_translation['status'])) {
         $_Translation = array();
         $_Translation['id_segment'] = (int) $this->id_segment;
         $_Translation['id_job'] = (int) $this->id_job;
         $_Translation['status'] = Constants_TranslationStatus::STATUS_NEW;
         $_Translation['segment_hash'] = $segment['segment_hash'];
         $_Translation['translation'] = $segment['segment'];
         $_Translation['standard_word_count'] = $segment['raw_word_count'];
         $_Translation['serialized_errors_list'] = '';
         $_Translation['suggestion_position'] = 0;
         $_Translation['warning'] = false;
         $_Translation['translation_date'] = date("Y-m-d H:i:s");
         $res = addTranslation($_Translation);
         if ($res < 0) {
             $this->result['errors'][] = array("code" => -101, "message" => "database errors");
             $db->rollback();
             return $res;
         }
         /*
          * begin stats counter
          *
          */
         $old_translation = $_Translation;
     }
     $_Translation = array();
     $_Translation['id_segment'] = $this->id_segment;
     $_Translation['id_job'] = $this->id_job;
     $_Translation['status'] = $this->status;
     $_Translation['time_to_edit'] = $this->time_to_edit;
     $_Translation['translation'] = preg_replace('/[ \\t\\n\\r\\0\\x0A\\xA0]+$/u', '', $translation);
     $_Translation['serialized_errors_list'] = $err_json;
     $_Translation['suggestion_position'] = $this->chosen_suggestion_index;
     $_Translation['warning'] = $check->thereAreWarnings();
     $_Translation['translation_date'] = date("Y-m-d H:i:s");
     /**
      * when the status of the translation changes, the auto propagation flag
      * must be removed
      */
     if ($_Translation['translation'] != $old_translation['translation'] || $this->status == Constants_TranslationStatus::STATUS_TRANSLATED || $this->status == Constants_TranslationStatus::STATUS_APPROVED) {
         $_Translation['autopropagated_from'] = 'NULL';
     }
     $res = CatUtils::addSegmentTranslation($_Translation);
     if (!empty($res['errors'])) {
         $this->result['errors'] = $res['errors'];
         $msg = "\n\n Error addSegmentTranslation \n\n Database Error \n\n " . var_export(array_merge($this->result, $_POST), true);
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
         $db->rollback();
         return -1;
     }
     if (INIT::$DQF_ENABLED && !empty($this->jobData['dqf_key']) && $_Translation['status'] == Constants_TranslationStatus::STATUS_TRANSLATED) {
         $dqfSegmentStruct = DQF_DqfSegmentStruct::getStruct();
         if ($old_translation['suggestion'] == null) {
             $dqfSegmentStruct->target_segment = "";
             $dqfSegmentStruct->tm_match = 0;
         } else {
             $dqfSegmentStruct->target_segment = $old_translation['suggestion'];
             $dqfSegmentStruct->tm_match = $old_translation['suggestion_match'];
         }
         $dqfSegmentStruct->task_id = $this->id_job;
         $dqfSegmentStruct->segment_id = $this->id_segment;
         $dqfSegmentStruct->source_segment = $segment['segment'];
         $dqfSegmentStruct->new_target_segment = $_Translation['translation'];
         $dqfSegmentStruct->time = $_Translation['time_to_edit'];
         //            $dqfSegmentStruct->mtengine = $this->jobData['id_mt_engine'];
         $dqfSegmentStruct->mt_engine_version = 1;
         try {
             $dqfQueueHandler = new Analysis_DqfQueueHandler();
             $dqfQueueHandler->createSegment($dqfSegmentStruct);
         } catch (Exception $exn) {
             $msg = $exn->getMessage() . "\n\n" . $exn->getTraceAsString();
             Log::doLog($msg);
             Utils::sendErrMailReport($msg);
         }
     }
     $propagateToTranslated = true;
     //for the moment, this is set explicitely
     if ($this->propagate == false) {
         $propagateToTranslated = false;
     }
     //propagate translations
     $TPropagation = array();
     //Warning: this value will NOT be used to update values,
     //but to exclude current segment from auto-propagation
     $_idSegment = $this->id_segment;
     $propagateToTranslated ? $TPropagation['status'] = $this->status : null;
     $TPropagation['id_job'] = $this->id_job;
     $TPropagation['translation'] = $translation;
     $TPropagation['autopropagated_from'] = $this->id_segment;
     $TPropagation['serialized_errors_list'] = $err_json;
     $TPropagation['warning'] = $check->thereAreWarnings();
     //        $TPropagation[ 'translation_date' ]       = date( "Y-m-d H:i:s" );
     $TPropagation['segment_hash'] = $old_translation['segment_hash'];
     $propagationTotal = array();
     if ($propagateToTranslated && in_array($this->status, array(Constants_TranslationStatus::STATUS_TRANSLATED, Constants_TranslationStatus::STATUS_APPROVED, Constants_TranslationStatus::STATUS_REJECTED))) {
         try {
             $propagationTotal = propagateTranslation($TPropagation, $this->jobData, $_idSegment, $propagateToTranslated);
         } catch (Exception $e) {
             $msg = $e->getMessage() . "\n\n" . $e->getTraceAsString();
             Log::doLog($msg);
             Utils::sendErrMailReport($msg);
         }
     }
     //Recount Job Totals
     $old_wStruct = new WordCount_Struct();
     $old_wStruct->setIdJob($this->id_job);
     $old_wStruct->setJobPassword($this->password);
     $old_wStruct->setNewWords($this->jobData['new_words']);
     $old_wStruct->setDraftWords($this->jobData['draft_words']);
     $old_wStruct->setTranslatedWords($this->jobData['translated_words']);
     $old_wStruct->setApprovedWords($this->jobData['approved_words']);
     $old_wStruct->setRejectedWords($this->jobData['rejected_words']);
     $old_wStruct->setIdSegment($this->id_segment);
     //redundant, this is made into WordCount_Counter::updateDB
     $old_wStruct->setOldStatus($old_translation['status']);
     $old_wStruct->setNewStatus($this->status);
     //redundant because the update is made only where status = old status
     if ($this->status != $old_translation['status']) {
         //cambiato status, sposta i conteggi
         $old_count = !is_null($old_translation['eq_word_count']) ? $old_translation['eq_word_count'] : $segment['raw_word_count'];
         //if there is not a row in segment_translations because volume analysis is disabled
         //search for a just created row
         $old_status = !empty($old_translation['status']) ? $old_translation['status'] : Constants_TranslationStatus::STATUS_NEW;
         $counter = new WordCount_Counter($old_wStruct);
         $counter->setOldStatus($old_status);
         $counter->setNewStatus($this->status);
         $newValues = array();
         $newValues[] = $counter->getUpdatedValues($old_count);
         foreach ($propagationTotal as $__pos => $old_value) {
             $counter->setOldStatus($old_value['status']);
             $counter->setNewStatus($this->status);
             $newValues[] = $counter->getUpdatedValues($old_value['total']);
         }
         try {
             $newTotals = $counter->updateDB($newValues);
         } catch (Exception $e) {
             $this->result['errors'][] = array("code" => -101, "message" => "database errors");
             //                Log::doLog("Lock: Transaction Aborted. " . $e->getMessage() );
             //                $x1 = explode( "\n" , var_export( $old_translation, true) );
             //                Log::doLog("Lock: Translation status was " . implode( " ", $x1 ) );
             $db->rollback();
             return $e->getCode();
         }
     } else {
         $newTotals = $old_wStruct;
     }
     $job_stats = CatUtils::getFastStatsForJob($newTotals);
     $project = getProject($this->jobData['id_project']);
     $project = array_pop($project);
     $job_stats['ANALYSIS_COMPLETE'] = $project['status_analysis'] == Constants_ProjectStatus::STATUS_DONE || $project['status_analysis'] == Constants_ProjectStatus::STATUS_NOT_TO_ANALYZE ? true : false;
     $file_stats = array();
     $this->result['stats'] = $job_stats;
     $this->result['file_stats'] = $file_stats;
     $this->result['code'] = 1;
     $this->result['data'] = "OK";
     $this->result['version'] = date_create($_Translation['translation_date'])->getTimestamp();
     /* FIXME: added for code compatibility with front-end. Remove. */
     $_warn = $check->getWarnings();
     $warning = $_warn[0];
     /* */
     $this->result['warning']['cod'] = $warning->outcome;
     if ($warning->outcome > 0) {
         $this->result['warning']['id'] = $this->id_segment;
     } else {
         $this->result['warning']['id'] = 0;
     }
     //strtoupper transforms null to "" so check for the first element to be an empty string
     if (!empty($this->split_statuses[0]) && !empty($this->split_num)) {
         /* put the split inside the transaction if they are present */
         $translationStruct = TranslationsSplit_SplitStruct::getStruct();
         $translationStruct->id_segment = $this->id_segment;
         $translationStruct->id_job = $this->id_job;
         $translationStruct->target_chunk_lengths = array('len' => $this->split_chunk_lengths, 'statuses' => $this->split_statuses);
         $translationDao = new TranslationsSplit_SplitDAO(Database::obtain());
         $result = $translationDao->update($translationStruct);
     }
     $db->commit();
     if ($job_stats['TRANSLATED_PERC'] == '100') {
         $update_completed = setJobCompleteness($this->id_job, 1);
     }
     if (@$update_completed < 0) {
         $msg = "\n\n Error setJobCompleteness \n\n " . var_export($_POST, true);
         Log::doLog($msg);
         Utils::sendErrMailReport($msg);
     }
 }
Пример #10
0
/**
 * Update the word count for the job
 *
 * We perform an update in join with jobs table
 * because we want to update the word count only for the current chunk
 *
 * Update the status of segment_translation is needed to avoid duplicated calls
 * ( The second call fails for status condition )
 *
 * @param WordCount_Struct $wStruct
 *
 * @return int
 */
function updateWordCount(WordCount_Struct $wStruct)
{
    $db = Database::obtain();
    //Update in Transaction
    $query = "UPDATE jobs AS j SET\n                new_words = new_words + " . $wStruct->getNewWords() . ",\n                draft_words = draft_words + " . $wStruct->getDraftWords() . ",\n                translated_words = translated_words + " . $wStruct->getTranslatedWords() . ",\n                approved_words = approved_words + " . $wStruct->getApprovedWords() . ",\n                rejected_words = rejected_words + " . $wStruct->getRejectedWords() . "\n                  WHERE j.id = " . (int) $wStruct->getIdJob() . "\n                  AND j.password = '******'";
    $db->query($query);
    //	Log::doLog( $query . "\n" );
    $err = $db->get_error();
    $errno = $err['error_code'];
    if ($errno != 0) {
        Log::doLog($err);
        return $errno * -1;
    }
    Log::doLog("Affected: " . $db->affected_rows . "\n");
    return $db->affected_rows;
}
 private function recountJobTotals($old_status)
 {
     $old_wStruct = new WordCount_Struct();
     $old_wStruct->setIdJob($this->id_job);
     $old_wStruct->setJobPassword($this->password);
     $old_wStruct->setNewWords($this->jobData['new_words']);
     $old_wStruct->setDraftWords($this->jobData['draft_words']);
     $old_wStruct->setTranslatedWords($this->jobData['translated_words']);
     $old_wStruct->setApprovedWords($this->jobData['approved_words']);
     $old_wStruct->setRejectedWords($this->jobData['rejected_words']);
     $old_wStruct->setIdSegment($this->id_segment);
     //redundant, this is made into WordCount_Counter::updateDB
     $old_wStruct->setOldStatus($old_status);
     $old_wStruct->setNewStatus($this->status);
     return $old_wStruct;
 }
Пример #12
0
/**
 * Update the word count for the job
 *
 * We perform an update in join with jobs table
 * because we want to update the word count only for the current chunk
 *
 * Update the status of segment_translation is needed to avoid duplicated calls
 * ( The second call fails for status condition )
 *
 * @param WordCount_Struct $wStruct
 *
 * @return int
 */
function updateWordCount(WordCount_Struct $wStruct)
{
    $db = Database::obtain();
    //Update in Transaction
    $query = "UPDATE jobs AS j SET\n                new_words = new_words + " . $wStruct->getNewWords() . ",\n                draft_words = draft_words + " . $wStruct->getDraftWords() . ",\n                translated_words = translated_words + " . $wStruct->getTranslatedWords() . ",\n                approved_words = approved_words + " . $wStruct->getApprovedWords() . ",\n                rejected_words = rejected_words + " . $wStruct->getRejectedWords() . "\n                  WHERE j.id = " . (int) $wStruct->getIdJob() . "\n                  AND j.password = '******'";
    try {
        $db->query($query);
    } catch (PDOException $e) {
        Log::doLog($e->getMessage());
        return $e->getCode() * -1;
    }
    $affectedRows = $db->affected_rows;
    Log::doLog("Affected: " . $affectedRows . "\n");
    return $affectedRows;
}