public function LingotekApi::updateContentDocument in Lingotek Translation 7.4
Same name and namespace in other branches
- 7.7 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::updateContentDocument()
- 7.2 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::updateContentDocument()
- 7.3 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::updateContentDocument()
- 7.5 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::updateContentDocument()
- 7.6 lib/Drupal/lingotek/LingotekApi.php \LingotekApi::updateContentDocument()
Updates the content of an existing Lingotek document with the current object contents.
Parameters
stdClass $translatable_object: A Drupal node object or another object, such as a config chunk, etc.
Return value
bool TRUE on success, FALSE on failure.
File
- lib/
Drupal/ lingotek/ LingotekApi.php, line 908 - Defines Drupal\lingotek\LingotekApi
Class
- LingotekApi
- @file Defines Drupal\lingotek\LingotekApi
Code
public function updateContentDocument($translatable_object) {
$isContentNode = FALSE;
switch (get_class($translatable_object)) {
case 'LingotekConfigChunk':
case 'LingotekComment':
// Comments and Config Chunks have their own way to format the content.
$document_id = $translatable_object
->getMetadataValue('document_id');
$content = $translatable_object
->documentLingotekXML();
break;
default:
// Normal content do the regular formating.
$isContentNode = TRUE;
$document_id = $translatable_object->lingotek['document_id'];
$content = lingotek_xml_node_body($translatable_object);
break;
}
$parameters = array(
'documentId' => $document_id,
'documentName' => $translatable_object->title,
'documentDesc' => $translatable_object->title,
'content' => $content,
'format' => $this
->xmlFormat(),
);
if (get_class($translatable_object) == 'LingotekConfigChunk') {
$parameters['note'] = 'configuration file #' . $translatable_object->cid;
}
else {
$parameters['note'] = url('node/' . $translatable_object->nid, array(
'absolute' => TRUE,
'alias' => TRUE,
));
}
$this
->addAdvancedParameters($parameters, $translatable_object);
$result = $this
->request('updateContentDocument', $parameters);
if ($result) {
if (get_class($translatable_object) == 'LingotekConfigChunk') {
$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 {
LingotekSync::setNodeAndTargetsStatus($translatable_object, LingotekSync::STATUS_CURRENT, LingotekSync::STATUS_PENDING);
}
if ($isContentNode) {
lingotek_lingonode($translatable_object->nid, 'last_uploaded', time());
}
}
return $result ? TRUE : FALSE;
}