You are here

public function LingotekConfigChunk::downloadTriggered in Lingotek Translation 7.5

Updates the local content of $target_code with data from a Lingotek Document

Parameters

string $lingotek_locale: The code for the language that needs to be updated.

Return value

bool TRUE if the content updates succeeded, FALSE otherwise.

Overrides LingotekTranslatableEntity::downloadTriggered

1 call to LingotekConfigChunk::downloadTriggered()
LingotekConfigChunk::updateLocalContent in lib/Drupal/lingotek/LingotekConfigChunk.php
Updates the local content with data from a Lingotek Document.

File

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

Class

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

Code

public function downloadTriggered($lingotek_locale) {
  $metadata = $this
    ->metadata();
  $document_id = $metadata['document_id'];
  if (empty($document_id)) {
    LingotekLog::error('Unable to refresh local contents for config chunk @cid. Could not find Lingotek Document ID.', array(
      '@cid' => $this->cid,
    ));
    return FALSE;
  }
  $api = LingotekApi::instance();
  $document_xml = $api
    ->downloadDocument($document_id, $lingotek_locale);
  $target_language = Lingotek::convertLingotek2Drupal($lingotek_locale);

  /* FAST VERSION (git history for slow version) */

  // 1. save the dirty targets associated with given language
  $dirty_lids = self::getDirtyLidsByChunkIdAndLanguage($this->cid, $target_language);

  // 2. delete all segment targets associated with given language
  self::deleteSegmentTranslationsByChunkIdAndLanguage($this->cid, $target_language);

  // 3. insert all segments for the given language
  self::saveSegmentTranslations($document_xml, $target_language);

  // 4. return the dirty targets' statuses
  self::restoreDirtyLids($dirty_lids);

  /* END FAST */

  // set chunk status to current
  $this
    ->setStatus(LingotekSync::STATUS_CURRENT);
  $this
    ->setTargetsStatus(LingotekSync::STATUS_CURRENT, $lingotek_locale);
  return TRUE;
}