function field__translation_memory_id($record)
 {
     $out = $record->val('effective_translation_memory_id');
     if (!isset($out)) {
         $webpage = new SweteWebpage($record->val('webpage'));
         $record->setValue('effective_translation_memory_id', $webpage->getTranslationMemoryId(true));
         $out = $record->val('effective_translation_memory_id');
     }
     return $out;
 }
Exemple #2
0
 /**
  * @brief Imports a node and all of its children into the database.
  *
  * @param stdClass $node The root node to import.
  * @param Dataface_Record $parentPage A record of the @e webpages table
  * that represents the parent page of the current page.
  *
  * @see SiteCrawler for more information about nodes and the properties
  * they can have.
  */
 public function importNode(stdClass $node, $parentPage = null)
 {
     $page = null;
     if (isset($node->path) and isset($node->httpStatus)) {
         $page = df_get_record('webpages', array('webpage_url' => '=' . $node->path, 'website_id' => '=' . $this->site->getRecord()->val('website_id')));
         if (!$page) {
             $page = new Dataface_Record('webpages', array());
             $page->setValues(array('website_id' => $this->site->getRecord()->val('website_id'), 'webpage_url' => $node->path, 'active' => -1, 'posted_by' => $this->username, 'parent_id' => $parentPage ? $parentPage->val('webpage_id') : null, 'is_loaded' => 0));
             $res = $page->save();
             if (PEAR::isError($res)) {
                 throw new Exception($res->getMessage());
             }
             $this->pagesAdded[] = $page;
         } else {
             $this->pagesUpdated[] = $page;
         }
         $page->setValues(array('last_checked' => date('Y-m-d H:i:s'), 'last_checked_response_code' => $node->httpStatus, 'last_checked_content_type' => $node->contentType, 'last_checked_by' => $this->username));
         $updateRefreshLog = false;
         $translationStats = array();
         //if ( $node->content and $this->loadContent and (!$page->val('locked') or $this->overrideLocks) ){
         if (@$node->content and @$this->loadContent) {
             if ($page->val('locked') and !$this->overrideLocks) {
                 error_log("Skipping refresh of " . @$node->path . " because the page is locked.");
             } else {
                 $page->setValues(array('last_refresh' => date('Y-m-d H:i:s'), 'last_refresh_response_code' => $node->httpStatus, 'is_loaded' => 1, 'webpage_content' => $node->content));
                 // Now log the check
                 $logEntry = new Dataface_Record('webpage_refresh_log', array());
                 $logEntry->setValues(array('webpage_id' => $page->val('webpage_id'), 'date_checked' => date('Y-m-d H:i:s'), 'response_code' => $node->httpStatus, 'content_type' => $node->contentType, 'content' => $node->content, 'checked_by' => $this->username));
                 $res = $logEntry->save();
                 if (PEAR::isError($res)) {
                     throw new Exception($res->getMessage());
                 }
                 if ($this->translate) {
                     $pageWrapper = new SweteWebpage($page);
                     $tmid = $pageWrapper->getTranslationMemoryId(true);
                     if ($tmid) {
                         $tm = $this->getTranslationMemory($tmid);
                         if ($tm) {
                             import('inc/PageProcessor.php');
                             $processor = new PageProcessor();
                             $processor->webpageRefreshLogId = $logEntry->val('refresh_log_id');
                             $processor->site = $this->site;
                             $processor->translationMemory = $tm;
                             $processor->page = $pageWrapper;
                             $processor->translateMinStatus = $this->translateMinStatus;
                             $processor->translateMaxStatus = $this->translateMaxStatus;
                             $processor->logTranslationMisses = $this->logTranslationMisses;
                             $processor->savePage = false;
                             $processor->saveTranslationLogRecord = true;
                             $processor->process();
                         }
                     }
                 }
             }
         }
         $res = $page->save();
         // Now log the check
         $logEntry = new Dataface_Record('webpage_check_log', array());
         $logEntry->setValues(array('webpage_id' => $page->val('webpage_id'), 'date_checked' => date('Y-m-d H:i:s'), 'response_code' => $node->httpStatus, 'content_type' => $node->contentType, 'checked_by' => $this->username));
         $res = $logEntry->save();
         if (PEAR::isError($res)) {
             throw new Exception($res->getMessage());
         }
     }
     if (isset($node->children) and is_array($node->children)) {
         foreach ($node->children as $child) {
             $this->importNode($child, $page);
         }
     }
 }
Exemple #3
0
 public function addWebpage(SweteWebpage $webpage, $strings = array(), $ignoreNoStrings = false)
 {
     if (!$strings) {
         $site = $webpage->getSite();
         $proxyWriter = $site->getProxyWriter();
         $tmid = $webpage->getTranslationMemoryId(true);
         $tm = XFTranslationMemory::loadTranslationMemoryById($tmid);
         if (!$tm) {
             throw new Exception("No translation memory found for webpage.");
         }
         $proxyWriter->setTranslationMemory($tm);
         $proxyWriter->translateHtml($webpage->getRecord()->val('webpage_content'), $stats, true);
         if (@$stats['log']) {
             $strings = $stats['log'];
         }
     }
     if (!$strings && !$ignoreNoStrings) {
         throw new Exception("No strings found to translate.");
     }
     $sql = "insert ";
     if ($ignoreNoStrings) {
         $sql .= "ignore ";
     }
     $sql .= "into job_inputs_webpages (job_id, webpage_id) \n\t\t\tvalues\n\t\t\t\t('" . addslashes($this->_rec->val('job_id')) . "','" . addslashes($webpage->getRecord()->val('webpage_id')) . "')";
     SweteDb::q($sql);
     if ($strings) {
         foreach ($strings as $string) {
             if (!$this->containsString($string)) {
                 $nstr = TMTools::normalize($string);
                 unset($params);
                 $estr = TMTools::encode($nstr, $params);
                 $hash = md5($estr);
                 SweteDb::q("insert into job_inputs_webpages_strings (job_id, webpage_id, string, string_hash)\n\t\t\t\t\tvalues\n\t\t\t\t\t(\n\t\t\t\t\t\t'" . addslashes($this->_rec->val('job_id')) . "',\n\t\t\t\t\t\t'" . addslashes($webpage->getRecord()->val('webpage_id')) . "',\n\t\t\t\t\t\t'" . addslashes($string) . "',\n\t\t\t\t\t\t'" . addslashes($hash) . "'\n\t\t\t\t\t)");
             }
         }
     }
 }