Ejemplo n.º 1
0
 /**
  * Add a document to the Lingotek platform.
  *
  * Uploads the translatable object's content in the selected language.
  *
  * @param object $translatable_object
  *   A Drupal node object or lingotek ConfigChunk object
  */
 public function addContentDocument(LingotekTranslatableEntity $translatable_object, $with_targets = FALSE)
 {
     $success = FALSE;
     $project_id = $translatable_object->getProjectId();
     $source_lingotek_locale = $translatable_object->getSourceLocale();
     $source_language = isset($source_lingotek_locale) && !empty($source_lingotek_locale) ? $source_lingotek_locale : Lingotek::convertDrupal2Lingotek(lingotek_get_source_language());
     if ($project_id) {
         $parameters = array('projectId' => $project_id, 'format' => $this->xmlFormat(), 'sourceLanguage' => $source_language, 'tmVaultId' => $translatable_object->getVaultId());
         $parameters['documentName'] = $translatable_object->getDocumentName();
         $parameters['documentDesc'] = $translatable_object->getDescription();
         $parameters['content'] = $translatable_object->documentLingotekXML();
         $parameters['url'] = $translatable_object->getUrl();
         $parameters['workflowId'] = $translatable_object->getWorkflowId();
         $this->addAdvancedParameters($parameters, $translatable_object);
         if ($with_targets) {
             $parameters['targetAsJSON'] = Lingotek::getLanguagesWithoutSourceAsJSON($source_language);
             $parameters['applyWorkflow'] = 'true';
             // API expects a 'true' string
             $result = $this->request('addContentDocumentWithTargetsAsync', $parameters);
         } else {
             $result = $this->request('addContentDocumentAsync', $parameters);
         }
         if ($result) {
             if (isset($result->errors) && $result->errors) {
                 LingotekLog::error(t('Request to send document to Lingotek failed: ') . print_r($result->errors, TRUE), array());
                 $translatable_object->setStatus(LingotekSync::STATUS_FAILED);
                 $translatable_object->setLastError(is_array($result->errors) ? array_shift($result->errors) : $result->errors);
                 return FALSE;
             }
             if (get_class($translatable_object) == 'LingotekConfigChunk') {
                 $translatable_object->setDocumentId($result->id);
                 $translatable_object->setProjectId($project_id);
                 $translatable_object->setStatus(LingotekSync::STATUS_CURRENT);
                 $translatable_object->setTargetsStatus(LingotekSync::STATUS_PENDING);
                 // WTD: there is a race condition here where a user could modify a locales-
                 // source entry between the time the dirty segments are pulled and the time
                 // they are set to current at this point.  This same race condition exists
                 // for nodes as well; however, the odds may be lower due to number of entries.
                 LingotekConfigChunk::setSegmentStatusToCurrentById($translatable_object->getId());
             } else {
                 // node assumed (based on two functions below...
                 $entity_type = $translatable_object->getEntityType();
                 lingotek_keystore($entity_type, $translatable_object->getId(), 'document_id', $result->id);
                 lingotek_keystore($entity_type, $translatable_object->getId(), 'last_uploaded', time());
             }
             $success = TRUE;
         }
     }
     return $success;
 }
Ejemplo n.º 2
0
 /**
  * Add a document to the Lingotek platform.
  *
  * Uploads the node's field content in the node's selected language.
  *
  * @param object $node
  *   A Drupal node object.
  */
 public function addContentDocument($node, $with_targets = FALSE)
 {
     global $_lingotek_locale;
     $success = FALSE;
     $project_id = empty($node->lingotek_project_id) ? NULL : $node->lingotek_project_id;
     $project_id = empty($project_id) ? lingotek_lingonode($node->nid, 'project_id') : $project_id;
     $project_id = empty($project_id) ? variable_get('lingotek_project', NULL) : $project_id;
     $vault_id = empty($node->lingotek_vault_id) ? NULL : $node->lingotek_vault_id;
     $vault_id = empty($vault_id) ? lingotek_lingonode($node->nid, 'vault_id') : $vault_id;
     $vault_id = empty($vault_id) ? variable_get('lingotek_vault', 1) : $vault_id;
     $workflow_id = empty($node->workflow_id) ? NULL : $node->workflow_id;
     $workflow_id = empty($workflow_id) ? lingotek_lingonode($node->nid, 'workflow_id') : $workflow_id;
     $workflow_id = empty($workflow_id) ? variable_get('workflow_id', NULL) : $workflow_id;
     $source_language = isset($_lingotek_locale[$node->language]) ? $_lingotek_locale[$node->language] : $_lingotek_locale[lingotek_get_source_language()];
     if ($project_id) {
         $parameters = array('projectId' => $project_id, 'documentName' => $node->title, 'documentDesc' => $node->title, 'format' => $this->xmlFormat(), 'sourceLanguage' => $source_language, 'tmVaultId' => $vault_id, 'content' => lingotek_xml_node_body($node), 'note' => url('node/' . $node->nid, array('absolute' => TRUE, 'alias' => TRUE)));
         if (!empty($workflow_id)) {
             $parameters['workflowId'] = $workflow_id;
         }
         $this->addAdvancedParameters($parameters, $node);
         if ($with_targets) {
             $parameters['targetAsJSON'] = LingotekAccount::instance()->getManagedTargetsAsJSON();
             $parameters['applyWorkflow'] = 'true';
             // API expects a 'true' string
             $result = $this->request('addContentDocumentWithTargets', $parameters);
         } else {
             $result = $this->request('addContentDocument', $parameters);
         }
         if ($result) {
             lingotek_lingonode($node->nid, 'document_id', $result->id);
             lingotek_lingonode($node->nid, 'project_id', $project_id);
             LingotekSync::setNodeAndTargetsStatus($node->nid, LingotekSync::STATUS_CURRENT, LingotekSync::STATUS_PENDING);
             $success = TRUE;
         }
     }
     return $success;
 }