/**
  * 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_language = $translatable_object->getSourceLocale();
     if (empty($source_language)) {
         drupal_set_message('Some entities not uploaded because the source language was language neutral.', 'warning', FALSE);
         LingotekLog::warning('Document @docname not uploaded. Language was language neutral.', array('@docname' => $translatable_object->getDocumentName()));
         return FALSE;
     }
     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) == 'LingotekConfigSet') {
                 $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.
                 LingotekConfigSet::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;
 }