globallink_background_jobs.inc in GlobalLink Connect for Drupal 7.7
To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor.
File
globallink_background_jobs.incView source
<?php
/**
* @file
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*/
function globallink_background_send($all_content, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority, $parents) {
module_load_include('inc', 'globallink', 'gl_ws/gl_ws_send_translations');
module_load_include('inc', 'globallink', 'gl_ws/gl_ws_common');
module_load_include('php', 'globallink', 'gl_ws/glc/model/Submission.inc.php');
module_load_include('inc', 'globallink', 'globallink');
module_load_include('inc', 'globallink', 'globallink_node');
module_load_include('inc', 'globallink', 'globallink_entity/globallink_entity');
module_load_include('inc', 'globallink', 'globallink_block/globallink_block');
module_load_include('inc', 'globallink', 'globallink_fieldable_panels/globallink_fieldable_panels');
module_load_include('inc', 'globallink', 'globallink_interface/globallink_interface');
module_load_include('inc', 'globallink', 'globallink_menu/globallink_menu');
module_load_include('inc', 'globallink', 'globallink_taxonomy/globallink_taxonomy');
module_load_include('inc', 'globallink', 'globallink_webform/globallink_webform');
module_load_include('inc', 'globallink', 'globallink_beans/globallink_beans');
module_load_include('inc', 'globallink', 'globallink_file_entity/globallink_file_entity');
module_load_include('inc', 'globallink', 'globallink_commerce/globallink_commerce');
watchdog(GLOBALLINK_MODULE, 'Sending submission [%submission_name] in background', array(
'%submission_name' => $submission_name,
), WATCHDOG_INFO);
$globallink_arr = array();
try {
if (isset($all_content['eids'])) {
$eids = $all_content['eids'];
$entity_content = globallink_entity_send_for_translations($eids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
if (isset($entity_content) && !empty($entity_content) && isset($entity_content[GLOBALLINK_ENTITY_TYPE_ENTITY])) {
$globallink_arr[GLOBALLINK_ENTITY_TYPE_ENTITY] = $entity_content[GLOBALLINK_ENTITY_TYPE_ENTITY];
}
}
if (isset($all_content['bids'])) {
$bids = $all_content['bids'];
$block_content = globallink_block_send_blocks_for_translations($bids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
if (isset($block_content) && !empty($block_content) && isset($block_content[GLOBALLINK_ENTITY_TYPE_BLOCK])) {
$globallink_arr[GLOBALLINK_ENTITY_TYPE_BLOCK] = $block_content[GLOBALLINK_ENTITY_TYPE_BLOCK];
}
}
if (isset($all_content['int_ids'])) {
$int_ids = $all_content['int_ids'];
$int_content = globallink_interface_send_for_translations($int_ids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
if (isset($int_content) && !empty($int_content) && isset($int_content[GLOBALLINK_ENTITY_TYPE_INTERFACE])) {
$globallink_arr[GLOBALLINK_ENTITY_TYPE_INTERFACE] = $int_content[GLOBALLINK_ENTITY_TYPE_INTERFACE];
}
}
if (isset($all_content['fpids'])) {
$fpids = $all_content['fpids'];
$fpp_content = globallink_fieldable_panels_pane_send_for_translations($fpids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
if (isset($fpp_content) && !empty($fpp_content) && isset($fpp_content[GLOBALLINK_ENTITY_TYPE_FPP])) {
$globallink_arr[GLOBALLINK_ENTITY_TYPE_FPP] = $fpp_content[GLOBALLINK_ENTITY_TYPE_FPP];
}
}
if (isset($all_content['mids'])) {
$mids = $all_content['mids'];
$menu_content = globallink_menu_send_for_translations($mids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
if (isset($menu_content) && !empty($menu_content) && isset($menu_content[GLOBALLINK_ENTITY_TYPE_MENU])) {
$globallink_arr[GLOBALLINK_ENTITY_TYPE_MENU] = $menu_content[GLOBALLINK_ENTITY_TYPE_MENU];
}
}
if (isset($all_content['tids'])) {
$tids = $all_content['tids'];
$tax_content = globallink_taxonomy_send_for_translations($tids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
if (isset($tax_content) && !empty($tax_content) && isset($tax_content[GLOBALLINK_ENTITY_TYPE_TAXONOMY])) {
$globallink_arr[GLOBALLINK_ENTITY_TYPE_TAXONOMY] = $tax_content[GLOBALLINK_ENTITY_TYPE_TAXONOMY];
}
}
if (isset($all_content['wfids'])) {
$wfids = $all_content['wfids'];
$webform_content = globallink_webform_send_for_translations($wfids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority, $parents);
if (isset($webform_content) && !empty($webform_content) && isset($webform_content[GLOBALLINK_ENTITY_TYPE_WEBFORM])) {
$globallink_arr[GLOBALLINK_ENTITY_TYPE_WEBFORM] = $webform_content[GLOBALLINK_ENTITY_TYPE_WEBFORM];
}
}
if (isset($all_content['nids'])) {
$nids = $all_content['nids'];
$node_content = globallink_send_for_translations($nids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
if (isset($node_content) && !empty($node_content) && isset($node_content[GLOBALLINK_ENTITY_TYPE_NODE])) {
$globallink_arr[GLOBALLINK_ENTITY_TYPE_NODE] = $node_content[GLOBALLINK_ENTITY_TYPE_NODE];
}
}
if (isset($all_content['bnids'])) {
$bnids = $all_content['bnids'];
$bean_content = globallink_beans_send_for_translations($bnids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
if (isset($bean_content) && !empty($bean_content) && isset($bean_content[GLOBALLINK_ENTITY_TYPE_BEAN])) {
$globallink_arr[GLOBALLINK_ENTITY_TYPE_BEAN] = $bean_content[GLOBALLINK_ENTITY_TYPE_BEAN];
}
}
if (isset($all_content['fids'])) {
$fids = $all_content['fids'];
$file_content = globallink_send_file_entity_for_translations($fids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
if (isset($file_content) && !empty($file_content) && isset($file_content[GLOBALLINK_ENTITY_TYPE_FILE_ENTITY])) {
$globallink_arr[GLOBALLINK_ENTITY_TYPE_FILE_ENTITY] = $file_content[GLOBALLINK_ENTITY_TYPE_FILE_ENTITY];
}
}
if (isset($all_content['pids'])) {
$pids = $all_content['pids'];
$product_content = globallink_commerce_send_for_translations($pids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority);
if (isset($product_content) && !empty($product_content) && isset($product_content[GLOBALLINK_ENTITY_TYPE_COM])) {
$globallink_arr[GLOBALLINK_ENTITY_TYPE_COM] = $product_content[GLOBALLINK_ENTITY_TYPE_COM];
}
}
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Error in getting GlobalLink XML objects for submission [%submission_name]', array(
'%submission_name' => $submission_name,
), WATCHDOG_ERROR);
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
return;
}
$submission_info = array(
'source_locale' => $source_locale,
'target_locale' => $target_locale_arr,
'submission_name' => $submission_name,
'due_date' => $due_date,
'submission_details' => $submission_details,
'project_code' => $project_code,
);
$submitter = $submission_details['submitter'];
drupal_alter('transperfect_node_send', $globallink_arr, $submission_info);
if (!empty($globallink_arr)) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Final GlobalLink Array - %arr', array(
'%arr' => print_r($globallink_arr, TRUE),
), WATCHDOG_DEBUG);
watchdog(GLOBALLINK_MODULE, 'Submission Info - %arr', array(
'%arr' => print_r($submission_info, TRUE),
), WATCHDOG_DEBUG);
}
try {
$submission = new PDSubmission();
if ($submission_priority == 2) {
$submission->isUrgent = TRUE;
}
$projects = globallink_get_user_pdProjects($pd4);
if (isset($projects[$project_code])) {
$submission->project = $projects[$project_code];
$project_name = $projects[$project_code]->name;
}
else {
throw new Exception("Invalid Project Code");
}
$submission->name = $submission_name;
$submission->dueDate = $due_date;
$submission->submitter = $pd4->username;
$submission->instructions = $submission_details['instructions'] . "\nSubmitter: " . $submitter;
globallink_send_documents_for_translation_to_pd($globallink_arr, $pd4, $submission);
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Submission [%sub] sent successfully to GlobalLink Project Director', array(
'%sub' => $submission_info['submission_name'],
), WATCHDOG_DEBUG);
}
$sub_arr = array();
foreach ($globallink_arr as $gl_arr) {
foreach ($gl_arr as $globallink) {
foreach ($globallink->targetLocale as $target_locale) {
if (!isset($sub_arr[$target_locale]) && !isset($sub_arr[$target_locale][[
'globallink_submission',
]])) {
$sub_arr[$target_locale] = array();
$sub_arr[$target_locale]['globallink_submission'] = array();
$sub_arr[$target_locale]['globallink_submission']['submission'] = $globallink->submissionName;
$sub_arr[$target_locale]['globallink_submission']['submission_ticket'] = $globallink->submissionTicket;
// Todo - Update it with real PD Id.
$sub_arr[$target_locale]['globallink_submission']['pd_submission_id'] = 12345678;
$sub_arr[$target_locale]['globallink_submission']['source_lang_code'] = $source_locale;
$sub_arr[$target_locale]['globallink_submission']['project_code'] = $project_code;
$sub_arr[$target_locale]['globallink_submission']['project_name'] = $project_name;
$sub_arr[$target_locale]['globallink_submission']['due_date'] = $globallink->dueDate;
}
if (isset($sub_arr[$target_locale]) && isset($sub_arr[$target_locale]['globallink_document'])) {
$sub_arr[$target_locale]['globallink_document'][] = $globallink;
}
else {
$sub_arr[$target_locale]['globallink_document'] = array(
$globallink,
);
}
}
}
}
globallink_create_submission($sub_arr);
watchdog(GLOBALLINK_MODULE, 'Submission [%submission_name] created successfully.', array(
'%submission_name' => $submission_name,
), WATCHDOG_INFO);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
return;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
return;
}
}
}
/**
* Pull submissions or documents
*/
function globallink_background_pull($pd4, $sub_rid, $document_rids = NULL, $single = 0) {
module_load_include('inc', 'globallink', 'gl_ws/gl_ws_receive_translations');
module_load_include('inc', 'globallink', 'globallink');
$sub_sql = db_select('globallink_submission', 'gs');
$sub_sql
->condition('rid', $sub_rid, '=');
$sub_sql
->fields('gs');
$sub_sql_result = $sub_sql
->execute()
->fetchAll();
$submission_row = $sub_sql_result[0];
watchdog(GLOBALLINK_MODULE, 'Pulling submission status for - [%sub] for target language [%target]', array(
'%sub' => $submission_row->submission,
'%target' => $submission_row->sub_target_lang_name,
), WATCHDOG_INFO);
$target_locale = $submission_row->sub_target_lang_code;
$submission_ticket = $submission_row->submission_ticket;
$sql = db_select('globallink_document', 'gd');
$sql
->fields('gd');
$sql
->condition('gd.submission_rid', $sub_rid, '=');
$sql_results = $sql
->execute()
->fetchAll();
$document_tickets = array();
if ($document_rids != NULL) {
foreach ($sql_results as $row) {
if (in_array($row->rid, $document_rids)) {
if (!in_array($row->document_ticket, $document_tickets)) {
$document_tickets[] = $row->document_ticket;
}
}
}
}
else {
foreach ($sql_results as $row) {
if (!in_array($row->document_ticket, $document_tickets)) {
$document_tickets[] = $row->document_ticket;
}
}
}
try {
if (check_if_submission_cancelled_or_deleted($pd4, $submission_ticket)) {
db_update('globallink_document')
->fields(array(
'target_status' => GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED,
'target_last_updated' => REQUEST_TIME,
))
->condition('submission_rid', $sub_rid, '=')
->condition('target_lang_code', $target_locale, '=')
->execute();
db_update('globallink_submission')
->fields(array(
'status' => GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED,
'updated' => REQUEST_TIME,
))
->condition('rid', $sub_rid, '=')
->execute();
return;
}
else {
$cancelled_arr = get_cancelled_targets_by_documents($pd4, $document_tickets);
if (!empty($cancelled_arr)) {
foreach ($cancelled_arr as $cancelled_locale => $tickets) {
if ($cancelled_locale == $target_locale) {
foreach ($tickets as $cancelled_doc_ticket) {
db_update('globallink_document')
->fields(array(
'target_status' => GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED,
'target_last_updated' => REQUEST_TIME,
))
->condition('submission_rid', $sub_rid, '=')
->condition('target_lang_code', $target_locale, '=')
->condition('document_ticket', $cancelled_doc_ticket, '=')
->execute();
}
}
}
$sql = db_select('globallink_document', 'gd');
$sql
->fields('gd');
$sql
->condition('gd.submission_rid', $sub_rid, '=');
$sql
->condition('gd.target_status', GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED, '<>');
$sql_results = $sql
->execute()
->fetchAll();
if (count($sql_results) == 0) {
db_update('globallink_submission')
->fields(array(
'status' => GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED,
'updated' => REQUEST_TIME,
))
->condition('rid', $sub_rid, '=')
->execute();
return;
}
}
}
if ($document_rids != NULL) {
$globallink_arr = globallink_get_ready_translations_for_documents($pd4, $document_tickets);
}
else {
$globallink_arr = globallink_get_ready_translations_for_submission($pd4, array(
$submission_ticket,
));
}
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'GlobalLink Array from Project Director - %arr', array(
'%arr' => print_r($globallink_arr, TRUE),
), WATCHDOG_DEBUG);
}
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
return;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
return;
}
$delete_count = 0;
if (sizeof($globallink_arr) > 0) {
foreach ($globallink_arr as $globallink) {
if ($globallink->targetLocale == $target_locale) {
if ($document_rids != NULL) {
if (!in_array($globallink->documentTicket, $document_tickets)) {
continue;
}
}
$status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
if ($globallink->type == GLOBALLINK_ENTITY_TYPE_NODE) {
module_load_include('inc', 'globallink', 'globallink_node');
if (globallink_check_node_deleted($globallink->nid)) {
$status = GLOBALLINK_STATUS_TRANSLATION_SOURCE_DELETED;
try {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$delete_count++;
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
else {
$status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
}
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_ENTITY) {
module_load_include('inc', 'globallink', 'globallink_node');
if (globallink_check_node_deleted($globallink->nid)) {
$status = GLOBALLINK_STATUS_TRANSLATION_SOURCE_DELETED;
try {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$delete_count++;
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
else {
$status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
}
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_BLOCK) {
module_load_include('inc', 'globallink', 'globallink_block/globallink_block');
if (globallink_block_check_delete($globallink->otherObjectId)) {
$status = GLOBALLINK_STATUS_TRANSLATION_SOURCE_DELETED;
try {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$delete_count++;
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
else {
$status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
}
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_FPP) {
module_load_include('inc', 'globallink', 'globallink_fieldable_panels/globallink_fieldable_panels');
if (globallink_fieldable_panels_check_delete($globallink->otherObjectId)) {
$status = GLOBALLINK_STATUS_TRANSLATION_SOURCE_DELETED;
try {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$delete_count++;
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
else {
$status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
}
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_INTERFACE) {
module_load_include('inc', 'globallink', 'globallink_interface/globallink_interface');
if (globallink_interface_check_delete($globallink->otherObjectId)) {
$status = GLOBALLINK_STATUS_TRANSLATION_SOURCE_DELETED;
try {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$delete_count++;
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
else {
$status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
}
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_MENU) {
module_load_include('inc', 'globallink', 'globallink_menu/globallink_menu');
if (globallink_menu_check_delete($globallink->otherObjectId)) {
$status = GLOBALLINK_STATUS_TRANSLATION_SOURCE_DELETED;
try {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$delete_count++;
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
else {
$status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
}
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_TAXONOMY) {
module_load_include('inc', 'globallink', 'globallink_taxonomy/globallink_taxonomy');
if (globallink_taxonomy_check_delete($globallink->otherObjectId)) {
$status = GLOBALLINK_STATUS_TRANSLATION_SOURCE_DELETED;
try {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$delete_count++;
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
else {
$status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
}
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_WEBFORM) {
module_load_include('inc', 'globallink', 'globallink_webform/globallink_webform');
$parent_id = $globallink->otherObjectId;
$docs = globallink_webform_get_doc_rows_by_parent($sub_rid, $parent_id);
$wf_count = count($docs);
foreach ($docs as $doc) {
$lid = $doc->object_id;
$status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
if (globallink_check_webform_delete($lid)) {
$status = GLOBALLINK_STATUS_TRANSLATION_SOURCE_DELETED;
$wf_count--;
}
$query = db_update('globallink_document');
$query
->fields(array(
'target_status' => $status,
'target_last_updated' => REQUEST_TIME,
));
$query
->condition('rid', $doc->rid, '=');
if ($single == 1 && $doc->rid == $document_rids[0]) {
$query
->condition('rid', $document_rids[0], '=');
$query
->execute();
continue 1;
}
elseif ($single != 1) {
$query
->execute();
}
else {
continue;
}
}
// All the child webforms are deleted.
if ($wf_count == 0) {
try {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_FILE_ENTITY) {
module_load_include('inc', 'globallink', 'globallink_file_entity/globallink_file_entity');
if (globallink_file_entity_check_delete($globallink->otherObjectId)) {
$status = GLOBALLINK_STATUS_TRANSLATION_SOURCE_DELETED;
try {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$delete_count++;
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
else {
$status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
}
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_COM) {
module_load_include('inc', 'globallink', 'globallink_commerce/globallink_commerce');
if (globallink_commerce_check_delete($globallink->otherObjectId)) {
$status = GLOBALLINK_STATUS_TRANSLATION_SOURCE_DELETED;
try {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$delete_count++;
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
}
}
else {
$status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
}
}
if ($status != '' && $globallink->type != GLOBALLINK_ENTITY_TYPE_WEBFORM) {
$globallink->status = $status;
globallink_update_status($globallink, $sub_rid);
}
}
}
if ($delete_count > 0) {
watchdog(GLOBALLINK_MODULE, '%count source deleted record(s).', array(
'%count' => $delete_count,
), WATCHDOG_INFO);
}
watchdog(GLOBALLINK_MODULE, 'Submissions pulled successfully', array(), WATCHDOG_INFO);
}
return;
}
/**
* Imports the documents
*/
function globallink_background_import($pd4, $sub_rid, $document_rids = NULL) {
sleep(5);
module_load_include('inc', 'globallink', 'gl_ws/gl_ws_receive_translations');
module_load_include('inc', 'globallink', 'globallink');
$count = 0;
$sub_sql = db_select('globallink_submission', 'gs');
$sub_sql
->condition('rid', $sub_rid, '=');
$sub_sql
->fields('gs');
$sub_sql_result = $sub_sql
->execute()
->fetchAll();
$submission_row = $sub_sql_result[0];
watchdog(GLOBALLINK_MODULE, 'Importing submission - [%sub] for target language [%target]', array(
'%sub' => $submission_row->submission,
'%target' => $submission_row->sub_target_lang_name,
), WATCHDOG_INFO);
$submission_ticket = $submission_row->submission_ticket;
$target_locale = $submission_row->sub_target_lang_code;
$sql = db_select('globallink_document', 'gd');
$sql
->fields('gd');
$sql
->condition('gd.submission_rid', $sub_rid, '=');
$sql_results = $sql
->execute()
->fetchAll();
$document_tickets = array();
if ($document_rids != NULL) {
foreach ($sql_results as $row) {
if (in_array($row->rid, $document_rids)) {
if (!in_array($row->document_ticket, $document_tickets)) {
$document_tickets[] = $row->document_ticket;
}
}
}
}
else {
foreach ($sql_results as $row) {
if (!in_array($row->document_ticket, $document_tickets)) {
$document_tickets[] = $row->document_ticket;
}
}
}
$globallink_arr = array();
try {
if (check_if_submission_cancelled_or_deleted($pd4, $submission_ticket)) {
db_update('globallink_document')
->fields(array(
'target_status' => GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED,
'target_last_updated' => REQUEST_TIME,
))
->condition('submission_rid', $sub_rid, '=')
->condition('target_lang_code', $target_locale, '=')
->execute();
db_update('globallink_submission')
->fields(array(
'status' => GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED,
'updated' => REQUEST_TIME,
))
->condition('rid', $sub_rid, '=')
->execute();
return;
}
else {
$cancelled_arr = get_cancelled_targets_by_documents($pd4, $document_tickets);
if (!empty($cancelled_arr)) {
foreach ($cancelled_arr as $cancelled_locale => $tickets) {
if ($cancelled_locale == $target_locale) {
foreach ($tickets as $cancelled_doc_ticket) {
db_update('globallink_document')
->fields(array(
'target_status' => GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED,
'target_last_updated' => REQUEST_TIME,
))
->condition('submission_rid', $sub_rid, '=')
->condition('target_lang_code', $target_locale, '=')
->condition('document_ticket', $cancelled_doc_ticket, '=')
->execute();
}
}
}
$sql = db_select('globallink_document', 'gd');
$sql
->fields('gd');
$sql
->condition('gd.submission_rid', $sub_rid, '=');
$sql
->condition('gd.target_status', GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED, '<>');
$sql_results = $sql
->execute()
->fetchAll();
if (count($sql_results) == 0) {
$query = db_update('globallink_submission');
$query
->fields(array(
'status' => GLOBALLINK_STATUS_TRANSLATION_SOURCE_CANCELLED,
'updated' => REQUEST_TIME,
));
$query
->condition('rid', $sub_rid, '=');
$query
->execute();
return;
}
}
}
if ($document_rids != NULL) {
$globallink_arr = globallink_get_ready_translations_for_documents($pd4, $document_tickets);
}
else {
$globallink_arr = globallink_get_ready_translations_for_submission($pd4, array(
$submission_ticket,
));
}
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'GlobalLink Array from Project Director - %arr', array(
'%arr' => print_r($globallink_arr, TRUE),
), WATCHDOG_DEBUG);
}
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
return;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
return;
}
$globallink_arr_node = array();
$globallink_arr_entity = array();
$globallink_arr_block = array();
$globallink_arr_fpanel = array();
$globallink_arr_interface = array();
$globallink_arr_menu = array();
$globallink_arr_taxonomy = array();
$globallink_arr_webform = array();
$globallink_arr_bean = array();
$globallink_arr_file_entity = array();
$globallink_arr_commerce = array();
$globallink_arr_eck = array();
foreach ($globallink_arr as $globallink) {
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
if ($document_rids != NULL) {
if (!in_array($globallink->documentTicket, $document_tickets)) {
continue;
}
}
if ($globallink->type == GLOBALLINK_ENTITY_TYPE_NODE) {
module_load_include('inc', 'globallink', 'globallink_node');
array_push($globallink_arr_node, $globallink);
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_ENTITY) {
module_load_include('inc', 'globallink', 'globallink_entity/globallink_entity');
array_push($globallink_arr_entity, $globallink);
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_BLOCK) {
module_load_include('inc', 'globallink', 'globallink_block/globallink_block');
array_push($globallink_arr_block, $globallink);
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_FPP) {
module_load_include('inc', 'globallink', 'globallink_fieldable_panels/globallink_fieldable_panels');
array_push($globallink_arr_fpanel, $globallink);
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_INTERFACE) {
module_load_include('inc', 'globallink', 'globallink_interface/globallink_interface');
array_push($globallink_arr_interface, $globallink);
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_MENU) {
module_load_include('inc', 'globallink', 'globallink_menu/globallink_menu');
array_push($globallink_arr_menu, $globallink);
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_TAXONOMY) {
module_load_include('inc', 'globallink', 'globallink_taxonomy/globallink_taxonomy');
array_push($globallink_arr_taxonomy, $globallink);
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_WEBFORM) {
module_load_include('inc', 'globallink', 'globallink_webform/globallink_webform');
array_push($globallink_arr_webform, $globallink);
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_BEAN) {
module_load_include('inc', 'globallink', 'globallink_beans/globallink_beans');
array_push($globallink_arr_bean, $globallink);
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_FILE_ENTITY) {
module_load_include('inc', 'globallink', 'globallink_file_entity/globallink_file_entity');
array_push($globallink_arr_file_entity, $globallink);
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_COM) {
module_load_include('inc', 'globallink', 'globallink_commerce/globallink_commerce');
array_push($globallink_arr_commerce, $globallink);
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_ECK_ENTITY) {
module_load_include('inc', 'globallink', 'globallink_custom_entity/globallink_custom_entity');
array_push($globallink_arr_eck, $globallink);
}
}
}
if (count($globallink_arr_node) > 0) {
foreach ($globallink_arr_node as $globallink) {
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing Node - %arr ', array(
'%arr' => print_r($globallink_arr_node, TRUE),
), WATCHDOG_DEBUG);
}
try {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink->targetXML)) {
globallink_import_node($globallink);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$count++;
}
globallink_update_status($globallink, $sub_rid);
}
}
}
}
if (count($globallink_arr_entity) > 0) {
foreach ($globallink_arr_entity as $globallink) {
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing Entity - %arr ', array(
'%arr' => print_r($globallink_arr_entity, TRUE),
), WATCHDOG_DEBUG);
}
try {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink->targetXML)) {
globallink_entity_update_entity($globallink);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$count++;
}
globallink_update_status($globallink, $sub_rid);
}
}
}
}
if (count($globallink_arr_block) > 0) {
foreach ($globallink_arr_block as $globallink) {
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing Block - %arr ', array(
'%arr' => print_r($globallink_arr_block, TRUE),
), WATCHDOG_DEBUG);
}
try {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink->targetXML)) {
globallink_block_import($globallink);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$count++;
}
globallink_update_status($globallink, $sub_rid);
}
}
}
}
if (count($globallink_arr_fpanel) > 0) {
foreach ($globallink_arr_fpanel as $globallink) {
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing FPP - %arr ', array(
'%arr' => print_r($globallink_arr_fpanel, TRUE),
), WATCHDOG_DEBUG);
}
try {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink->targetXML)) {
globallink_fieldable_panels_import($globallink);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$count++;
}
globallink_update_status($globallink, $sub_rid);
}
}
}
}
if (count($globallink_arr_interface) > 0) {
foreach ($globallink_arr_interface as $globallink) {
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing Interface - %arr ', array(
'%arr' => print_r($globallink_arr_interface, TRUE),
), WATCHDOG_DEBUG);
}
try {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink->targetXML)) {
globallink_interface_import($globallink);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$count++;
}
globallink_update_status($globallink, $sub_rid);
}
}
}
}
if (count($globallink_arr_menu) > 0) {
usort($globallink_arr, 'globallink_menu_sort_gl_objects_by_menu_order');
foreach ($globallink_arr_menu as $globallink) {
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing Menu - %arr ', array(
'%arr' => print_r($globallink_arr_menu, TRUE),
), WATCHDOG_DEBUG);
}
try {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink->targetXML)) {
globallink_menu_import($globallink);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$count++;
}
globallink_update_status($globallink, $sub_rid);
}
}
}
}
if (count($globallink_arr_taxonomy) > 0) {
foreach ($globallink_arr_taxonomy as $globallink) {
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing Taxonomy - %arr ', array(
'%arr' => print_r($globallink_arr_taxonomy, TRUE),
), WATCHDOG_DEBUG);
}
try {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink->targetXML)) {
globallink_taxonomy_import($globallink);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$count++;
}
globallink_update_status($globallink, $sub_rid);
}
}
}
}
if (count($globallink_arr_webform) > 0) {
foreach ($globallink_arr_webform as $globallink) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing WebForm - %arr ', array(
'%arr' => print_r($globallink_arr_webform, TRUE),
), WATCHDOG_DEBUG);
}
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
try {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink->targetXML)) {
$send_confirmation = globallink_webform_import($globallink, $sub_rid, $document_rids);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR && $send_confirmation) {
$parent_id = $globallink->otherObjectId;
$docs = globallink_webform_get_doc_rows_by_parent($sub_rid, $parent_id);
$wf_count = count($docs);
foreach ($docs as $doc) {
if ($doc->submission_rid == $sub_rid && $doc->document_ticket == $globallink->documentTicket && $doc->object_parent_id == $globallink->otherObjectId && $doc->target_lang_code == $globallink->targetLocale) {
if (in_array($doc->object_id, $globallink->lids)) {
$wf_count--;
}
}
}
if ($wf_count == 0) {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
}
$count++;
}
globallink_update_status($globallink, $sub_rid);
}
}
}
}
if (count($globallink_arr_bean) > 0) {
foreach ($globallink_arr_bean as $globallink) {
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing beans - %arr ', array(
'%arr' => print_r($globallink_arr_bean, TRUE),
), WATCHDOG_DEBUG);
}
try {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink->targetXML)) {
globallink_beans_import($globallink);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$count++;
}
globallink_update_status($globallink, $sub_rid);
}
}
}
}
if (count($globallink_arr_file_entity > 0)) {
foreach ($globallink_arr_file_entity as $globallink_fe) {
if ($globallink_fe->targetLocale == $target_locale && $globallink_fe->submissionTicket == $submission_ticket) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing file enity - %arr ', array(
'%arr' => print_r($globallink_arr_file_entity, TRUE),
), WATCHDOG_DEBUG);
}
try {
$globallink_fe->targetXML = globallink_download_target_resource($pd4, $globallink_fe->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink_fe->targetXML)) {
globallink_file_entity_import($globallink_fe);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
globallink_send_download_confirmation($globallink_fe->targetTicket, $pd4);
$count++;
}
globallink_update_status($globallink_fe, $sub_rid);
}
}
}
}
if (count($globallink_arr_commerce) > 0) {
foreach ($globallink_arr_commerce as $globallink) {
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing commerce product - %arr ', array(
'%arr' => print_r($globallink_arr_commerce, TRUE),
), WATCHDOG_DEBUG);
}
try {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink->targetXML)) {
globallink_commerce_import($globallink);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$count++;
}
globallink_update_status($globallink, $sub_rid);
}
}
}
}
if (count($globallink_arr_eck > 0)) {
foreach ($globallink_arr_eck as $globallink) {
if ($globallink->targetLocale == $target_locale && $globallink->submissionTicket == $submission_ticket) {
if (globallink_debug_enabled()) {
watchdog(GLOBALLINK_MODULE, 'Importing custom entity - %arr ', array(
'%arr' => print_r($globallink_arr_eck, TRUE),
), WATCHDOG_DEBUG);
}
try {
$globallink->targetXML = globallink_download_target_resource($pd4, $globallink->targetTicket);
} catch (SoapFault $se) {
watchdog(GLOBALLINK_MODULE, 'SOAP Exception - %function - Code[%faultcode], Message[%faultstring]', array(
'%function' => __FUNCTION__,
'%faultcode' => $se->faultcode,
'%faultstring' => $se->faultstring,
), WATCHDOG_ERROR);
continue;
} catch (Exception $e) {
watchdog(GLOBALLINK_MODULE, 'Exception - %function - File[%file], Line[%line], Code[%code], Message[%message]', array(
'%function' => __FUNCTION__,
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
'%code' => $e
->getCode(),
'%message' => $e
->getMessage(),
), WATCHDOG_ERROR);
continue;
}
if (isset($globallink->targetXML)) {
globallink_eck_import($globallink);
if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
globallink_send_download_confirmation($globallink->targetTicket, $pd4);
$count++;
}
globallink_update_status($globallink, $sub_rid);
}
}
}
}
watchdog(GLOBALLINK_MODULE, '%count records updated successfully for submission [%submission_name].', array(
'%count' => $count,
'%submission_name' => $submission_row->submission,
), WATCHDOG_INFO);
return;
}
/**
* Updates the translation status.
*
* @param object $globallink
* The GlobalLink translation data.
*/
function globallink_update_status(&$globallink, $sub_rid = NULL) {
if ($sub_rid != NULL) {
$status = $globallink->status;
if ($status != '' && $globallink->type != GLOBALLINK_ENTITY_TYPE_WEBFORM) {
db_update('globallink_document')
->fields(array(
'target_status' => $status,
'target_last_updated' => REQUEST_TIME,
))
->condition('submission_rid', $sub_rid, '=')
->condition('target_lang_code', $globallink->targetLocale, '=')
->condition('document_ticket', $globallink->documentTicket, '=')
->execute();
}
elseif ($globallink->type == GLOBALLINK_ENTITY_TYPE_WEBFORM) {
db_update('globallink_document')
->fields(array(
'target_status' => $status,
'target_last_updated' => REQUEST_TIME,
))
->condition('submission_rid', $sub_rid, '=')
->condition('object_id', $globallink->lids, 'IN')
->condition('target_lang_code', $globallink->targetLocale, '=')
->condition('document_ticket', $globallink->documentTicket, '=')
->execute();
}
$query = db_select('globallink_document', 'gd');
$query
->condition('submission_rid', $sub_rid, '=');
$query
->condition('target_lang_code', $globallink->targetLocale, '=');
$query
->fields('gd');
$results = $query
->execute()
->fetchAll();
$row_count = count($results);
$published_count = 0;
$completed_count = 0;
$sub_status = '';
foreach ($results as $row) {
if ($row->target_status == GLOBALLINK_STATUS_TRANSLATION_ERROR) {
$sub_status = GLOBALLINK_STATUS_TRANSLATION_ERROR;
break;
}
if ($row->target_status == GLOBALLINK_STATUS_TRANSLATION_IMPORTED) {
$published_count++;
}
elseif ($row->target_status == GLOBALLINK_STATUS_TRANSLATION_COMPLETED) {
$completed_count++;
}
}
if ($published_count == $row_count) {
$sub_status = GLOBALLINK_STATUS_TRANSLATION_IMPORTED;
}
elseif ($completed_count == $row_count) {
$sub_status = GLOBALLINK_STATUS_TRANSLATION_COMPLETED;
}
if ($sub_status != '') {
db_update('globallink_submission')
->fields(array(
'status' => $sub_status,
'updated' => REQUEST_TIME,
))
->condition('rid', $sub_rid, '=')
->execute();
}
}
}
/**
*
*/
function globallink_create_submission($sub_arr) {
$node_types = globallink_get_translatable_node_types_and_names('');
foreach ($sub_arr as $target_locale => $arr) {
$submission_info = $arr['globallink_submission'];
$document_info = $arr['globallink_document'];
$source_lang_name = globallink_get_drupal_locale_name($submission_info['source_lang_code']);
$target_lang_name = globallink_get_drupal_locale_name($target_locale);
$sub_rid = db_insert('globallink_submission')
->fields(array(
'submission' => $submission_info['submission'],
'pd_submission_id' => $submission_info['pd_submission_id'],
'submission_ticket' => $submission_info['submission_ticket'],
'source_lang_code' => $submission_info['source_lang_code'],
'source_lang_name' => $source_lang_name,
'sub_target_lang_code' => $target_locale,
'sub_target_lang_name' => $target_lang_name,
'project_code' => $submission_info['project_code'],
'project_name' => $submission_info['project_name'],
'due_date' => $submission_info['due_date'],
'status' => GLOBALLINK_STATUS_TRANSLATION_SENT,
'created' => REQUEST_TIME,
'updated' => REQUEST_TIME,
))
->execute();
foreach ($document_info as $globallink) {
$type_name = '';
if ($globallink->metadata == GLOBALLINK_ENTITY_TYPE_NODE || $globallink->metadata == GLOBALLINK_ENTITY_TYPE_ENTITY) {
if (is_array($node_types) && isset($node_types[$globallink->type])) {
$type_name = $node_types[$globallink->type];
}
$id = $globallink->nid;
$t_query = db_select('globallink_core', 'tc');
$t_query
->condition('source', $submission_info['source_lang_code'], '=');
$t_query
->condition('target', $target_locale, '=');
$t_query
->fields('tc');
$t_query
->orderBy('nid', 'ASC');
$results = $t_query
->execute()
->fetchAll();
if ($globallink->metadata == GLOBALLINK_ENTITY_TYPE_NODE) {
if (count($results) > 0) {
db_delete('globallink_core')
->condition('nid', $id, '=')
->condition('source', $submission_info['source_lang_code'], '=')
->condition('target', $target_locale, '=')
->execute();
}
db_insert('globallink_core')
->fields(array(
'nid' => $id,
'vid' => $globallink->vid,
'source' => $submission_info['source_lang_code'],
'target' => $target_locale,
'last_modified' => REQUEST_TIME,
'changed' => 0,
))
->execute();
}
elseif ($globallink->metadata == GLOBALLINK_ENTITY_TYPE_ENTITY) {
if (count($results) > 0) {
db_delete('globallink_core')
->condition('nid', $id, '=')
->condition('source', $submission_info['source_lang_code'], '=')
->condition('target', $target_locale, '=')
->execute();
}
db_insert('globallink_core')
->fields(array(
'nid' => $id,
'vid' => $globallink->vid,
'source' => $submission_info['source_lang_code'],
'target' => $target_locale,
'last_modified' => REQUEST_TIME,
'changed' => 0,
))
->execute();
}
}
else {
$id = $globallink->otherObjectId;
}
if ($globallink->metadata == GLOBALLINK_ENTITY_TYPE_WEBFORM) {
$titles = $globallink->title;
foreach ($titles as $key => $title) {
db_insert('globallink_document')
->fields(array(
'submission_rid' => $sub_rid,
'document_ticket' => $globallink->documentTicket,
'entity_type' => $globallink->metadata,
'entity_type_name' => globallink_get_entity_type_name($globallink->metadata),
'object_type' => $globallink->type,
'object_type_name' => $type_name,
'object_id' => $key,
'object_parent_id' => $id,
'object_version_id' => $globallink->vid,
'object_title' => $title,
'target_lang_code' => $target_locale,
'target_status' => GLOBALLINK_STATUS_TRANSLATION_SENT,
'target_last_sent' => REQUEST_TIME,
'target_last_updated' => REQUEST_TIME,
))
->execute();
}
}
else {
db_insert('globallink_document')
->fields(array(
'submission_rid' => $sub_rid,
'document_ticket' => $globallink->documentTicket,
'entity_type' => $globallink->metadata,
'entity_type_name' => globallink_get_entity_type_name($globallink->metadata),
'object_type' => $globallink->type,
'object_type_name' => $type_name,
'object_id' => $id,
'object_parent_id' => $id,
'object_version_id' => $globallink->vid,
'object_title' => $globallink->title,
'target_lang_code' => $target_locale,
'target_status' => GLOBALLINK_STATUS_TRANSLATION_SENT,
'target_last_sent' => REQUEST_TIME,
'target_last_updated' => REQUEST_TIME,
))
->execute();
}
}
}
}
function globallink_send_entity_ref_for_translations($eids, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority, $globallink_arr) {
module_load_include('inc', 'globallink', 'gl_ws/gl_ws_send_translations');
module_load_include('inc', 'globallink', 'globallink');
module_load_include('inc', 'globallink', 'globallink_custom_entity/globallink_custom_entity');
$submitter = $submission_details['submitter'];
$drupal_locale_code = globallink_get_drupal_locale_code($source_locale);
$entity_ref = array();
foreach ($eids as $eid => $outer_arr) {
if (count($outer_arr) < 1) {
continue;
}
foreach ($outer_arr as $type => $outervalue) {
if (count($outervalue) < 1) {
continue;
}
foreach ($outervalue as $innerkey => $entity_id) {
$reference_entity = entity_load_single($type, $entity_id);
$rows = globallink_eck_get_sent_rows_by_id($entity_id, $reference_entity->type);
$target_arr = $target_locale_arr;
foreach ($rows as $row) {
if (array_search($row->target_lang_code, $target_locale_arr)) {
unset($target_arr[$row->target_lang_code]);
watchdog(GLOBALLINK_MODULE, 'Skipping entity Id - %id for locales %locale', array(
'%id' => $entity_id,
'%locale' => $row->target_lang_code,
), WATCHDOG_DEBUG);
}
}
if (empty($target_arr)) {
continue;
}
if (empty($target_arr)) {
watchdog(GLOBALLINK_MODULE, 'No target languages. Skipping nid - %eid', array(
'%eid' => $entity_id,
), WATCHDOG_CRITICAL);
continue;
}
$drupal_target_arr = array();
foreach ($target_arr as $target_locale) {
array_push($drupal_target_arr, globallink_get_drupal_locale_code($target_locale));
}
$tnid = NULL;
$tvid = NULL;
$name = '.xml';
$xml_targets = globallink_entity_reference_get_xml($reference_entity, $drupal_target_arr, $tnid, $tvid, $name, FALSE, $drupal_locale_code, $type);
$xml = $xml_targets[0];
$eck_entity = $xml_targets[1];
if (!$xml) {
watchdog(GLOBALLINK_MODULE, 'Cannot create entity XML. Skipping entity type %entitytype entity id - %eid', array(
'%eid' => $entity_id,
'%entitytype' => $type,
), WATCHDOG_CRITICAL);
continue;
}
$globallink = new GlobalLink();
$globallink->otherObjectId = $reference_entity->id;
$globallink->title = isset($reference_entity->title) ? $reference_entity->title : NULL;
$globallink->type = $reference_entity->type;
$globallink->metadata = GLOBALLINK_ENTITY_TYPE_ECK_ENTITY;
$globallink->sourceLocale = $source_locale;
$globallink->targetLocale = $target_arr;
$globallink->sourceXML = $xml;
$globallink->sourceFileName = $name;
$globallink->submissionName = $submission_name;
$globallink->submissionPriority = $submission_priority;
$globallink->dueDate = $due_date;
$globallink->submissionInstructions = $submission_details['instructions'] . "\nSubmitter: " . $submitter;
$globallink_arr[GLOBALLINK_ENTITY_TYPE_ENTITY][] = $globallink;
if (count($eck_entity) > 0) {
$globallink_arr = globallink_send_entity_ref_for_translations($eck_entity, $pd4, $submission_name, $due_date, $project_code, $source_locale, $target_locale_arr, $submission_details, $submission_priority, $globallink_arr);
}
}
}
}
return $globallink_arr;
}
Functions
Name | Description |
---|---|
globallink_background_import | Imports the documents |
globallink_background_pull | Pull submissions or documents |
globallink_background_send | |
globallink_create_submission | |
globallink_send_entity_ref_for_translations | |
globallink_update_status | Updates the translation status. |