function lingotek_get_sync_download_batch_elements in Lingotek Translation 7.7
Same name and namespace in other branches
- 7.2 lingotek.batch.inc \lingotek_get_sync_download_batch_elements()
- 7.3 lingotek.batch.inc \lingotek_get_sync_download_batch_elements()
- 7.4 lingotek.batch.inc \lingotek_get_sync_download_batch_elements()
- 7.5 lingotek.batch.inc \lingotek_get_sync_download_batch_elements()
- 7.6 lingotek.batch.inc \lingotek_get_sync_download_batch_elements()
Sync - Download Batch Elements: Creates the batch elements for nodes/documents that need to be downloaded.
Parameters
download_targets: list of objects (document_id, lingotek_locale) //json_decode([ {"document_id": "191", "locale": "fr_FR" }, ... ]);
2 calls to lingotek_get_sync_download_batch_elements()
- lingotek_config_download_selected in ./
lingotek.config.inc - lingotek_sync_batch_create in ./
lingotek.batch.inc - Batch Create - Sync: Uploads new and changed documents for translation and Downloads translated documents.
File
- ./
lingotek.batch.inc, line 220 - Central location for batch create functions, before control is handed off to individual batch command files.
Code
function lingotek_get_sync_download_batch_elements($download_targets = NULL, $sync_success_target = LingotekSync::STATUS_CURRENT) {
$operations = array();
if (is_null($download_targets)) {
$target_locales = lingotek_get_target_locales();
foreach ($target_locales as $lingotek_locale) {
// get all nodes that have pending translations
$key = 'target_sync_status_' . $lingotek_locale;
$query = db_select('lingotek_entity_metadata', 'l')
->fields('l');
$query
->condition('entity_type', 'node');
$query
->condition('entity_key', $key);
$status_or = db_or()
->condition('value', LingotekSync::STATUS_PENDING)
->condition('value', LingotekSync::STATUS_READY);
$query
->condition($status_or);
$result = $query
->execute();
while ($record = $result
->fetchAssoc()) {
$operations[] = array(
'lingotek_entity_download',
array(
$record['entity'],
'node',
$lingotek_locale,
),
);
}
// get all config sets that have pending translations
$key = 'target_sync_status_' . $lingotek_locale;
$query = db_select('lingotek_config_metadata', 'meta')
->fields('meta');
$query
->condition('config_key', $key);
$status_or = db_or()
->condition('value', LingotekSync::STATUS_PENDING)
->condition('value', LingotekSync::STATUS_READY);
$query
->condition($status_or);
$result = $query
->execute();
while ($record = $result
->fetchAssoc()) {
$operations[] = array(
'lingotek_sync_download_config_target',
array(
$record['id'],
$lingotek_locale,
$sync_success_target,
),
);
}
}
}
elseif (is_array($download_targets)) {
$doc_ids = array();
foreach ($download_targets as $download_target) {
list($id, $entity_type) = LingotekSync::getEntityIdFromDocId($download_target->document_id);
if ($id != NULL) {
$lingotek_locale = $download_target->locale;
$doc_ids[] = $download_target->document_id;
$entity = lingotek_entity_load_single($entity_type, $id);
$operations[] = array(
'lingotek_entity_download',
array(
$entity,
$entity_type,
$lingotek_locale,
),
);
}
else {
// since no node was found associated with the document ID, check config chunks
$sid = LingotekConfigSet::getIdByDocId($download_target->document_id);
if ($sid !== FALSE) {
$lingotek_locale = $download_target->locale;
$operations[] = array(
'lingotek_sync_download_config_target',
array(
$sid,
$lingotek_locale,
$sync_success_target,
),
);
}
}
}
$doc_ids = array_unique($doc_ids);
}
return $operations;
}