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)); }
public function doAction() { $files_found = array(); $lang_handler = languages::getInstance("en"); // CASMACAT extension start // if ($this->casIsReplaying) { // $data = getSegmentsInfoWithoutTranslation($this->jid, $this->password, $this->start_from, $this->step); // } // else { $data = getSegmentsInfo($this->jid, $this->password); // } // CASMACAT extension end if (empty($data) or $data < 0) { $this->job_not_found = true; } // echo "<pre>"; // print_r ($data); // exit; $first_not_translated_found = false; foreach ($data as $i => $seg) { if (empty($this->pname)) { $this->pname = $seg['pname']; $this->downloadFileName = $seg['pname'] . ".zip"; // will be overwritten below in case of one file job } if (empty($this->last_opened_segment)) { $this->last_opened_segment = $seg['last_opened_segment']; } if (empty($this->cid)) { $this->cid = $seg['cid']; } if (empty($this->pid)) { $this->pid = $seg['pid']; } if (empty($this->tid)) { $this->tid = $seg['tid']; } if (empty($this->create_date)) { $this->create_date = $seg['create_date']; } if (empty($this->source_code)) { $this->source_code = $seg['source']; } if (empty($this->target_code)) { $this->target_code = $seg['target']; } if (empty($this->source)) { $s = explode("-", $seg['source']); $source = strtoupper($s[0]); $this->source = $source; } if (empty($this->target)) { $t = explode("-", $seg['target']); $target = strtoupper($t[0]); $this->target = $target; } $id_file = $seg['id_file']; $this->fid = $id_file; if (!isset($this->data["{$id_file}"])) { $files_found[] = $seg['filename']; $file_stats = CatUtils::getStatsForFile($id_file); $this->data["{$id_file}"]['jid'] = $seg['jid']; $this->data["{$id_file}"]["filename"] = $seg['filename']; $this->data["{$id_file}"]["mime_type"] = $seg['mime_type']; $this->data["{$id_file}"]['id_segment_start'] = $seg['id_segment_start']; $this->data["{$id_file}"]['id_segment_end'] = $seg['id_segment_end']; $this->data["{$id_file}"]['source'] = $lang_handler->iso2Language($seg['source']); $this->data["{$id_file}"]['target'] = $lang_handler->iso2Language($seg['target']); $this->data["{$id_file}"]['source_code'] = $seg['source']; $this->data["{$id_file}"]['target_code'] = $seg['target']; $this->data["{$id_file}"]['last_opened_segment'] = $seg['last_opened_segment']; $this->data["{$id_file}"]['file_stats'] = $file_stats; //$this->data["$id_file"]['segments'] = array(); } //if (count($this->data["$id_file"]['segments'])>100){continue;} $this->filetype_handler = new filetype($seg['mime_type']); unset($seg['id_file']); unset($seg['source']); unset($seg['target']); unset($seg['source_code']); unset($seg['target_code']); unset($seg['mime_type']); unset($seg['filename']); unset($seg['jid']); unset($seg['pid']); unset($seg['cid']); unset($seg['tid']); unset($seg['pname']); unset($seg['create_date']); unset($seg['id_segment_end']); unset($seg['id_segment_start']); unset($seg['last_opened_segment']); } if (empty($this->last_opened_segment)) { $this->last_opened_segment = getFirstSegmentId($this->jid, $this->password); log::doLog($this->last_opened_segment); } $this->job_stats = CatUtils::getStatsForJob($this->jid, $this->casIsReplaying); if (count($files_found) == 1) { $this->downloadFileName = $files_found[0]; } // CASMACAT start if ($this->casIsReplaying) { $this->initCfg = json_decode(fetchInitialConfig($this->jid, $this->fid)); log::doLog("CASMACAT: Initial config: " . print_r($this->initCfg, true)); } // CASMACAT end // echo "<pre>"; // print_r($this->data); // exit; }