You are here

function globallink_background_pull in GlobalLink Connect for Drupal 7.7

Pull submissions or documents

4 calls to globallink_background_pull()
globallink_all_active_form_submit in ./globallink_workbench_all_active_submissions.inc
Handles submission of active entity form.
globallink_dashboard_active_submissions_page in ./globallink_workbench_all_active_submissions.inc
globallink_dashboard_active_submissions_page in ./globallink_workbench_all_submissions.inc
Builds forms on GlobalLink active submissions dashboard.
globallink_dashboard_active_submit in ./globallink_workbench_all_submissions.inc
Handles submission of active GlobalLink form.
4 string references to 'globallink_background_pull'
globallink_all_active_form_submit in ./globallink_workbench_all_active_submissions.inc
Handles submission of active entity form.
globallink_dashboard_active_submissions_page in ./globallink_workbench_all_active_submissions.inc
globallink_dashboard_active_submissions_page in ./globallink_workbench_all_submissions.inc
Builds forms on GlobalLink active submissions dashboard.
globallink_dashboard_active_submit in ./globallink_workbench_all_submissions.inc
Handles submission of active GlobalLink form.

File

./globallink_background_jobs.inc, line 201
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.

Code

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;
}