function lingotek_sync_batch_create in Lingotek Translation 7.4
Same name and namespace in other branches
- 7.7 lingotek.batch.inc \lingotek_sync_batch_create()
- 7.2 lingotek.batch.inc \lingotek_sync_batch_create()
- 7.3 lingotek.batch.inc \lingotek_sync_batch_create()
- 7.5 lingotek.batch.inc \lingotek_sync_batch_create()
- 7.6 lingotek.batch.inc \lingotek_sync_batch_create()
Batch Create - Sync: Uploads new and changed documents for translation and Downloads translated documents.
Creates the batch operations array. Downloads first, then uploads.
3 calls to lingotek_sync_batch_create()
- lingotek_download_translations_form_submit in ./
lingotek.page.inc - Download Translations Form Submit
- lingotek_form_bulk_sync_submit in ./
lingotek.sync.inc - Submit handler for the lingotek_form_bulk_sync form. Calls the function that creates a batch job to do bulk sync.
- lingotek_sync in ./
lingotek.sync.inc - The main function responsible for syncing node/document translation.
File
- ./
lingotek.batch.inc, line 77 - Central location for batch create functions, before control is handed off to individual batch command files.
Code
function lingotek_sync_batch_create($upload_nids = array(), $upload_config = array(), $download_targets = array(), $download_targets_incomplete = array(), $redirect = '', $extra_operations = array()) {
$has_upload = !empty($upload_nids);
$has_upload_config = !empty($upload_config);
$has_download = !empty($download_targets);
$has_download_incomplete = !empty($download_targets_incomplete);
// Grab the Nodes that need to be Downloaded & Uploaded. These are batch operation arrays.
$download_commands = $has_download ? lingotek_get_sync_download_batch_elements($download_targets, LingotekSync::STATUS_CURRENT) : array();
$download_commands_inc = $has_download_incomplete ? lingotek_get_sync_download_batch_elements($download_targets_incomplete, LingotekSync::STATUS_PENDING) : array();
$upload_commands = $has_upload ? lingotek_get_sync_upload_batch_elements($upload_nids) : array();
$upload_config_commands = $has_upload_config ? lingotek_get_sync_upload_config_batch_elements($upload_config) : array();
$operations = array();
$operations = array_merge($operations, $download_commands, $download_commands_inc, $upload_commands, $upload_config_commands);
$operations = array_merge($operations, $extra_operations);
// Where to send the user after the batch has processed. If redirect_url GET param exists, then use it
if (empty($redirect)) {
$redirect = isset($_GET['redirect_url']) && strlen($_GET['redirect_url']) ? $_GET['redirect_url'] : LINGOTEK_MENU_LANG_BASE_URL;
}
if (count($operations) > 0) {
// Note, the first step of the batch process sets a session variable that tracks that we are in a sync state.
// The Node update hook uses that so it knows NOT to reupload the content we just recieved.
// The last step of the sync process clears the sync flag. $_SESSION['lingotek_sync_in_progress']
// As a backup (in case there is an error and the batch doesnt complete successfully) there is a backup on the lingotek_dashboard() that clears the sync status flag.
$batch = array(
'title' => t('Syncing Content and Translations'),
'operations' => $operations,
'file' => 'lingotek.batch.inc',
'finished' => 'lingotek_sync_batch_finished',
);
batch_set($batch);
lingotek_mt_sync_set_status('set');
// this status unsets itself when the dashboard is loaded on redirect
batch_process($redirect);
// Needed if not inside a form _submit handler. Setting redirect in batch_process.
}
else {
$options = strpos($redirect, '//') !== FALSE ? array(
'external' => TRUE,
) : array();
drupal_goto($redirect, $options);
}
}