public function LingotekApi::addContentDocument in Lingotek Translation 7.4
Same name and namespace in other branches
- 7.7 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocument()
- 7.2 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocument()
- 7.3 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocument()
- 7.5 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocument()
- 7.6 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::addContentDocument()
Add a document to the Lingotek platform.
Uploads the translatable object's content in the selected language.
Parameters
object $translatable_object: A Drupal node object or lingotek ConfigChunk object
File
- lib/
Drupal/ lingotek/ LingotekApi.php, line 68 - Defines Drupal\lingotek\LingotekApi
Class
- LingotekApi
- @file Defines Drupal\lingotek\LingotekApi
Code
public function addContentDocument(LingotekTranslatableEntity $translatable_object, $with_targets = FALSE) {
$success = FALSE;
$project_id = $translatable_object
->getProjectId();
$vault_id = $translatable_object
->getVaultId();
$workflow_id = $translatable_object
->getWorkflowId();
$source_lingotek_locale = $translatable_object
->getSourceLocale();
$source_language = isset($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' => $vault_id,
);
$parameters['documentName'] = $translatable_object
->getTitle();
$parameters['documentDesc'] = $translatable_object
->getDescription();
$parameters['content'] = $translatable_object
->documentLingotekXML();
if (get_class($translatable_object) == 'LingotekConfigChunk') {
$cid = $translatable_object
->getId();
if (!$cid) {
$cid = '(new/unassigned)';
}
$parameters['note'] = 'config chunk #' . $cid;
}
else {
$parameters['note'] = url($translatable_object
->getEntityType() . '/' . $translatable_object
->getId(), array(
'absolute' => TRUE,
'alias' => TRUE,
));
}
if (!empty($workflow_id)) {
$parameters['workflowId'] = $workflow_id;
}
$this
->addAdvancedParameters($parameters, $translatable_object);
if ($with_targets) {
$parameters['targetAsJSON'] = Lingotek::availableLanguageTargetsWithoutSourceAsJSON($source_language);
$parameters['applyWorkflow'] = 'true';
// API expects a 'true' string
$result = $this
->request('addContentDocumentWithTargetsAsync', $parameters);
}
else {
$result = $this
->request('addContentDocumentAsync', $parameters);
}
if ($result) {
if (get_class($translatable_object) == 'LingotekConfigChunk') {
$translatable_object
->setDocumentId($result->id);
$translatable_object
->setProjectId($project_id);
$translatable_object
->setChunkStatus(LingotekSync::STATUS_CURRENT);
$translatable_object
->setChunkTargetsStatus(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...
lingotek_lingonode($translatable_object
->getId(), 'document_id', $result->id);
LingotekSync::setNodeAndTargetsStatus($translatable_object, LingotekSync::STATUS_CURRENT, LingotekSync::STATUS_PENDING);
lingotek_lingonode($translatable_object
->getId(), 'last_uploaded', time());
}
$success = TRUE;
}
}
return $success;
}