Beispiel #1
0
 /**
  * @param WordCount_Struct $wordCount_Struct
  *
  * @return WordCount_Struct
  * @throws Exception
  */
 public function updateDB(WordCount_Struct $wordCount_Struct)
 {
     $res = updateWordCount($wordCount_Struct);
     if ($res < 0) {
         throw new Exception("Failed to update counter", $res);
     }
     $newWCount = new WordCount_Struct();
     $newWCount->setNewWords($this->oldWCount->getNewWords() + $wordCount_Struct->getNewWords());
     $newWCount->setTranslatedWords($this->oldWCount->getTranslatedWords() + $wordCount_Struct->getTranslatedWords());
     $newWCount->setApprovedWords($this->oldWCount->getApprovedWords() + $wordCount_Struct->getApprovedWords());
     $newWCount->setRejectedWords($this->oldWCount->getRejectedWords() + $wordCount_Struct->getRejectedWords());
     $newWCount->setDraftWords($this->oldWCount->getDraftWords() + $wordCount_Struct->getDraftWords());
     $newWCount->setIdSegment($this->oldWCount->getIdSegment());
     $newWCount->setOldStatus($this->oldStatus);
     $newWCount->setNewStatus($this->newStatus);
     $newWCount->setIdJob($this->oldWCount->getIdJob());
     $newWCount->setJobPassword($this->oldWCount->getJobPassword());
     return $newWCount;
 }
Beispiel #2
0
 /**
  * @param WordCount_Struct[] $wordCount_Struct
  *
  * @return WordCount_Struct
  */
 public function sumDifferentials($wordCount_Struct)
 {
     $newWCount = new WordCount_Struct();
     $newWCount->setIdSegment($this->oldWCount->getIdSegment());
     $newWCount->setOldStatus($this->oldStatus);
     $newWCount->setNewStatus($this->newStatus);
     $newWCount->setIdJob($this->oldWCount->getIdJob());
     $newWCount->setJobPassword($this->oldWCount->getJobPassword());
     /**
      * @var WordCount_Struct $count
      */
     foreach ($wordCount_Struct as $count) {
         $newWCount->setNewWords($newWCount->getNewWords() + $count->getNewWords());
         $newWCount->setTranslatedWords($newWCount->getTranslatedWords() + $count->getTranslatedWords());
         $newWCount->setApprovedWords($newWCount->getApprovedWords() + $count->getApprovedWords());
         $newWCount->setRejectedWords($newWCount->getRejectedWords() + $count->getRejectedWords());
         $newWCount->setDraftWords($newWCount->getDraftWords() + $count->getDraftWords());
     }
     return $newWCount;
 }
Beispiel #3
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;
}
Beispiel #4
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;
}