You are here

public function LingotekConfigSet::downloadTriggered in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.6 lib/Drupal/lingotek/LingotekConfigSet.php \LingotekConfigSet::downloadTriggered()

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 LingotekConfigSet::downloadTriggered()
LingotekConfigSet::updateLocalContent in lib/Drupal/lingotek/LingotekConfigSet.php
Updates the local content with data from a Lingotek Document.

File

lib/Drupal/lingotek/LingotekConfigSet.php, line 872
Defines LingotekConfigSet.

Class

LingotekConfigSet
A class wrapper for Lingotek-specific behavior on ConfigSets.

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 set @sid. Could not find Lingotek Document ID.', array(
      '@sid' => $this->sid,
    ));
    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::getDirtyLidsBySetIdAndLanguage($this->sid, $target_language);

  // 2. delete all segment targets associated with given language
  self::deleteSegmentTranslationsBySetIdAndLanguage($this->sid, $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 */
  $target_status = LingotekSync::getConfigTargetStatus($this->sid, $lingotek_locale);

  // assign set status to current
  $this
    ->setStatus(LingotekSync::STATUS_CURRENT);
  if ($target_status === LingotekSync::STATUS_READY_INTERIM) {
    $this
      ->setTargetsStatus(LingotekSync::STATUS_INTERIM, $lingotek_locale);
  }
  else {
    $this
      ->setTargetsStatus(LingotekSync::STATUS_CURRENT, $lingotek_locale);
  }
  self::markSetsCurrent($this->sid);
  return TRUE;
}