You are here

function globallink_auto_receive in GlobalLink Connect for Drupal 7.7

Same name and namespace in other branches
  1. 7.5 globallink.module \globallink_auto_receive()
  2. 7.6 globallink.module \globallink_auto_receive()

Automatically receives translated contents.

Parameters

string $cron_type: The type of cron job.

1 string reference to 'globallink_auto_receive'
globallink_cron_queue_info in ./globallink.module
Implements hook_cron_queue_info().

File

./globallink.module, line 1554
GlobalLink translation module.

Code

function globallink_auto_receive($cron_type) {
  module_load_include('inc', 'globallink', 'globallink_settings');
  module_load_include('inc', 'globallink', 'globallink');
  module_load_include('inc', 'globallink', 'globallink_background_jobs');
  if (0 == variable_get('globallink_cron_type', 0)) {
    watchdog(GLOBALLINK_MODULE, "Cron is not enabled for {$cron_type}", array(), WATCHDOG_INFO);
    return FALSE;
  }

  // Set it so your cron won't time out if it takes a long time to process.
  drupal_set_time_limit(0);
  watchdog(GLOBALLINK_MODULE, 'Cron Started by %cron_type', array(
    '%cron_type' => $cron_type,
  ), WATCHDOG_INFO);
  try {

    //importing all active submissions.
    $results = db_select('globallink_submission', 'gs')
      ->condition('status', array(
      GLOBALLINK_STATUS_TRANSLATION_SENT,
      GLOBALLINK_STATUS_TRANSLATION_COMPLETED,
    ), 'IN')
      ->fields('gs', array(
      'rid',
    ))
      ->execute()
      ->fetchAll();
    if (count($results) > 0) {
      $pd4 = globallink_get_project_director_details();
      foreach ($results as $row) {
        if (module_exists('background_process') && module_exists('background_batch')) {
          $operations = array();
          $operations[] = array(
            'globallink_background_import',
            array(
              $pd4,
              $row->rid,
              NULL,
            ),
          );
          $batch = array(
            'title' => t('Importing'),
            'operations' => $operations,
            'error_message' => t('Import has encountered an error.'),
            'file' => drupal_get_path('module', 'globallink') . '/globallink_background_jobs.inc',
          );
          $batch['progressive'] = FALSE;
          batch_set($batch);
          background_batch_process_batch('admin/globallink-translations/activeSubmissions');
        }
        else {
          globallink_background_import($pd4, $row->rid, NULL);
        }
      }
    }
  } 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);
  }
  watchdog(GLOBALLINK_MODULE, 'Cron Completed.', array(), WATCHDOG_INFO);
}