You are here

public static function LingotekSync::getEntityIdsToUpload in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.5 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getEntityIdsToUpload()
  2. 7.6 lib/Drupal/lingotek/LingotekSync.php \LingotekSync::getEntityIdsToUpload()
1 call to LingotekSync::getEntityIdsToUpload()
lingotek_grid_upload_edited in ./lingotek.bulk_grid.inc

File

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

Class

LingotekSync
A utility class for Lingotek Syncing.

Code

public static function getEntityIdsToUpload($entity_type, $entity_ids = null) {
  $info = entity_get_info($entity_type);
  $id_key = $info['entity keys']['id'];
  $query = db_select($info['base table'], 'base');
  $query
    ->addField('base', $id_key);
  $query
    ->leftJoin('lingotek_entity_metadata', 'upload', 'upload.entity_id = base.' . $id_key . ' and upload.entity_type =\'' . $entity_type . '\' and upload.entity_key = \'upload_status\'');
  $query2 = db_select('lingotek_entity_metadata', 'lem');
  $query2
    ->distinct();
  $query2
    ->addField('lem', 'entity_id');
  $query2
    ->condition('entity_key', 'profile');
  $query2
    ->condition('entity_type', $entity_type);
  $query2
    ->condition('value', 'DISABLED');
  $query
    ->condition('upload.entity_id', $query2, 'NOT IN');
  if ($entity_type == 'node') {

    // Exclude any target nodes created using node-based translation.
    $tnid_query = db_or();
    $tnid_query
      ->condition('base.tnid', 0);
    $tnid_query
      ->where('base.tnid = base.nid');
    $query
      ->condition($tnid_query);
  }
  $or = db_or();
  $or
    ->condition('upload.value', LingotekSync::STATUS_EDITED);
  $or
    ->condition('upload.value', LingotekSync::STATUS_NONE);
  $or
    ->condition('upload.value', LingotekSync::STATUS_ARCHIVED);
  $or
    ->condition('upload.value', LingotekSync::STATUS_GONE);
  $or
    ->isNull('upload.value');
  $query
    ->condition($or);
  if ($entity_type === 'menu_link') {
    $min_query = db_select('menu_links', 'base')
      ->condition('base.i18n_tsid', 0, '!=')
      ->groupBy('i18n_tsid');
    $min_query
      ->addExpression('MIN(mlid)', 'minimum');
    $ml_or = db_or();
    $ml_or
      ->condition('base.i18n_tsid', 0);
    $ml_or
      ->condition('base.mlid', $min_query, 'IN');
    $query
      ->condition('base.language', LANGUAGE_NONE, '!=');
    $query
      ->condition($ml_or);
  }
  if ($entity_ids !== null) {
    $query
      ->condition('upload.entity_id', $entity_ids, 'IN');
  }
  $result = $query
    ->execute()
    ->fetchCol();
  return $result;
}