function drush_lingotek_push in Lingotek Translation 7.7
Callback function for drush command batch upload translatable content
File
- ./
lingotek.drush.inc, line 123 - Drush command file
Code
function drush_lingotek_push($entity_type) {
try {
$operations = array();
if ($entity_type == 'config') {
// adapted from lingotek_config_upload_selected() in lingotek.confg.inc
$query = db_select('locales_source', 'ls');
$query
->addField('ls', 'textgroup');
$query
->addField('ls', 'lid');
$results = $query
->execute();
$lid_map = array();
foreach ($results as $result) {
$lid_map[$result->textgroup][$result->lid] = $result->lid;
}
$unique_set_ids = LingotekConfigSet::bulkGetSetId($lid_map);
foreach ($lid_map as $textgroup) {
LingotekConfigSet::markLidsNotCurrent($textgroup);
}
if (!empty($not_current_lids)) {
LingotekConfigSet::markLidsNotCurrent($not_current_lids);
}
$operations = lingotek_get_sync_upload_config_batch_elements($unique_set_ids);
}
else {
$query = new EntityFieldQuery();
$entity_ids = array();
$query
->entityCondition('entity_type', $entity_type);
if ($bundles = drush_get_option('bundles')) {
$list = explode(',', $bundles);
$query
->entityCondition('bundle', $list, 'IN');
}
$result = $query
->execute();
if (is_array($result[$entity_type])) {
$entity_ids = array_keys($result[$entity_type]);
}
if (!empty($entity_ids)) {
foreach ($entity_ids as $id) {
$operations[] = array(
'lingotek_entity_upload',
array(
$id,
$entity_type,
),
);
}
}
else {
throw new Exception(dt('No entities of @type were found in the database', array(
'@type' => $entity_type,
)));
}
}
$batch = array(
'operations' => $operations,
'finished' => 'lingotek_drush_push_complete',
'title' => dt('Upload entities to Lingotek TMS'),
'init_message' => dt('Beginning batch uploads of @type to Lingotek', array(
'@type' => $entity_type,
)),
);
batch_set($batch);
drush_backend_batch_process();
} catch (Exception $e) {
drush_set_error('lt-push', $e
->getMessage());
}
}