You are here

public function LingotekConfigChunk::contentUpdated in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.3 lib/Drupal/lingotek/LingotekConfigChunk.php \LingotekConfigChunk::contentUpdated()
  2. 7.5 lib/Drupal/lingotek/LingotekConfigChunk.php \LingotekConfigChunk::contentUpdated()

Event handler for updates to the config chunk's data.

File

lib/Drupal/lingotek/LingotekConfigChunk.php, line 416
Defines LingotekConfigChunk.

Class

LingotekConfigChunk
A class wrapper for Lingotek-specific behavior on ConfigChunks.

Code

public function contentUpdated() {
  $metadata = $this
    ->metadata();
  if (empty($metadata['document_id'])) {
    $this
      ->createLingotekDocument();
  }
  else {
    $update_result = $this
      ->updateLingotekDocument();
  }

  // Synchronize the local content with the translations from Lingotek.
  // We instruct the users to configure config chunk translation with a
  // single-phase machine translation-only Workflow, so the updated content
  // should be available right after our create/update document calls from above.
  // If it isn't, Lingotek will call us back via LINGOTEK_NOTIFICATIONS_URL
  // when machine translation for the item has finished.
  if (!self::$content_update_in_progress) {

    // Only update the local content if the Document is 100% complete
    // according to Lingotek.
    $document_id = $this
      ->getMetadataValue('document_id');
    if ($document_id) {
      $document = $this->api
        ->getDocument($document_id);
      if (!empty($document->percentComplete) && $document->percentComplete == 100) {
        $this
          ->updateLocalContent();
      }
    }
    else {
      LingotekLog::error('Unable to retrieve Lingotek Document ID for config chunk @id', array(
        '@id' => $this->cid,
      ));
    }
  }
}