function testReturnsNonCompletedProject()
 {
     $this->setValidProjectWithAllTranslatedSegments();
     // get project chunks
     $chunksDao = new Chunks_ChunkDao(Database::obtain());
     $chunks = $chunksDao->getByProjectID($this->test_data->project->id_project);
     $this->assertEquals(1, count($chunks));
     $chunk = $chunks[0];
     // split job in two
     $splitTest = new CurlTest();
     $params = array('action' => 'splitJob', 'exec' => 'apply', 'project_id' => $this->test_data->project->id_project, 'project_pass' => $this->test_data->project->project_pass, 'job_id' => $chunk->id, 'job_pass' => $chunk->password, 'num_split' => 2, 'split_values' => array('5', '1'));
     $splitTest->params = $params;
     $splitTest->method = 'POST';
     $response = $splitTest->getResponse();
     $chunks = $chunksDao->getByProjectID($this->test_data->project->id_project);
     $this->assertEquals(2, count($chunks));
     $first_chunk = $chunks[0];
     $second_chunk = $chunks[1];
     integrationSetChunkAsComplete(array('params' => array('id_job' => $first_chunk->id, 'password' => $first_chunk->password)));
     $test = new CurlTest();
     $test->path = '/api/v2/project-completion-status/' . $this->test_data->project->id_project;
     $test->method = 'GET';
     $test->headers = $this->test_data->headers;
     $response = $test->getResponse();
     $expected = array('project_status' => array('id' => $this->test_data->project->id_project, 'completed' => false, 'chunks' => array(array('id' => $second_chunk->id, 'password' => $second_chunk->password))));
     $this->assertEquals(json_encode($expected), $response['body']);
 }
Example #2
0
function integrationSetSegmentsTranslated($project_id)
{
    $chunksDao = new Chunks_ChunkDao(Database::obtain());
    $chunks = $chunksDao->getByProjectID($project_id);
    foreach ($chunks as $chunk) {
        $segments = $chunk->getSegments();
        foreach ($segments as $segment) {
            integrationSetTranslation(array('id_segment' => $segment->id, 'id_job' => $chunk->id, 'password' => $chunk->password, 'status' => 'translated'));
        }
    }
    return $chunks;
}
Example #3
0
 public function __construct()
 {
     $this->start_time = microtime(1) * 1000;
     parent::__construct(false);
     parent::makeTemplate("index.html");
     $filterArgs = array('jid' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'password' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'start' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'page' => array('filter' => FILTER_SANITIZE_NUMBER_INT));
     $getInput = (object) filter_input_array(INPUT_GET, $filterArgs);
     $this->jid = $getInput->jid;
     $this->password = $getInput->password;
     $this->start_from = $getInput->start;
     $this->page = $getInput->page;
     $this->job = Chunks_ChunkDao::getByIdAndPassword($this->jid, $this->password);
     if (isset($_GET['step'])) {
         $this->step = $_GET['step'];
     } else {
         $this->step = 1000;
     }
     if (is_null($this->page)) {
         $this->page = 1;
     }
     if (is_null($this->start_from)) {
         $this->start_from = ($this->page - 1) * $this->step;
     }
     if (isset($_GET['filter'])) {
         $this->filter_enabled = true;
     } else {
         $this->filter_enabled = false;
     }
     $this->downloadFileName = "";
     $this->doAuth();
     $this->generateAuthURL();
 }
 public function doAction()
 {
     // ensure the record exists
     $this->chunk = Chunks_ChunkDao::getByIdAndPassword($this->__postInput['id_job'], $this->__postInput['password']);
     if ($this->chunk) {
         $this->processInsert();
     } else {
         $this->result['error'] = 'record not found';
     }
 }
Example #5
0
 function testStatusOnTranslated()
 {
     $project = integrationCreateTestProject();
     $this->params = array('id_project' => $project->id_project, 'project_pass' => $project->project_pass);
     $chunksDao = new Chunks_ChunkDao(Database::obtain());
     $chunks = $chunksDao->getByProjectID($project->id_project);
     $this->assertTrue(count($chunks) == 1);
     foreach ($chunks as $chunk) {
         $segments = $chunk->getSegments();
         foreach ($segments as $segment) {
             integrationSetTranslation(array('id_segment' => $segment->id, 'id_job' => $chunk->id, 'password' => $chunk->password, 'status' => 'translated'));
         }
     }
     foreach ($chunks as $chunk) {
         $translations = $chunk->getTranslations();
         $this->assertEquals(3, count($translations));
         foreach ($translations as $translation) {
             $this->assertEquals('TRANSLATED', $translation->status);
         }
     }
     // iterate all segments and setTranslations
     $request = $this->makeRequest();
     $response = json_decode($request['body']);
 }
Example #6
0
 public function doAction()
 {
     $files_found = array();
     $lang_handler = Langs_Languages::getInstance();
     try {
         $this->job = Chunks_ChunkDao::getByIdAndPassword($this->jid, $this->password);
     } catch (\Exception $e) {
         $this->job_not_found = true;
         return;
     }
     $data = getSegmentsInfo($this->jid, $this->password);
     //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));
 }
Example #7
0
 public function getChunks()
 {
     $dao = new Chunks_ChunkDao(Database::obtain());
     return $dao->getByProjectId($this->id_project);
 }