You are here

public static function LingotekSync::insertTargetEntriesForAllNodes in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.3 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::insertTargetEntriesForAllNodes()
1 call to LingotekSync::insertTargetEntriesForAllNodes()
LingotekSync::insertTargetEntriesForAllDocs in lib/Drupal/lingotek/LingotekSync.php

File

lib/Drupal/lingotek/LingotekSync.php, line 107
LingotekSync

Class

LingotekSync
A utility class for Lingotek Syncing.

Code

public static function insertTargetEntriesForAllNodes($lingotek_locale) {

  // select all nids where the node's source is the locale provided
  $drupal_language_code = Lingotek::convertLingotek2Drupal($lingotek_locale);
  $subquery = db_select('node', 'n')
    ->fields('n', array(
    'nid',
  ));
  $subquery
    ->condition('language', $drupal_language_code);
  $subquery2 = db_select('lingotek', 'l2')
    ->fields('l2', array(
    'nid',
  ));
  $subquery2
    ->condition('lingokey', 'target_sync_status_' . $lingotek_locale);

  //already has status
  $query = db_select('lingotek', 'l')
    ->fields('l');
  $query
    ->condition('lingokey', 'node_sync_status');
  $query
    ->condition('nid', $subquery, 'NOT IN');

  // exclude adding to nodes where this locale is the source
  $query
    ->condition('nid', $subquery2, 'NOT IN');

  // exclude nodes that already have this language as a target
  $result = $query
    ->execute();
  while ($record = $result
    ->fetchAssoc()) {
    $node_id = $record['nid'];

    // If the Node is CURRENT or PENDING, then we just need to pull down the new translation (because the source will have been uploaded), so set the Node and Target to PENDING.
    if ($record['lingovalue'] == self::STATUS_CURRENT) {
      self::setTargetStatus($node_id, $lingotek_locale, self::STATUS_PENDING);
    }
    else {
      if ($record['lingovalue'] == self::STATUS_TARGET) {
      }
      else {
        if ($record['lingovalue'] == self::STATUS_DISABLED) {
          self::setTargetStatus($node_id, $lingotek_locale, self::STATUS_DISABLED);
        }
        else {

          // Otherwise, set it to EDITED
          self::setNodeStatus($node_id, self::STATUS_EDITED);
          self::setTargetStatus($node_id, $lingotek_locale, self::STATUS_EDITED);
        }
      }
    }
  }
}