You are here

function globallink_interface_import in GlobalLink Connect for Drupal 7.7

1 call to globallink_interface_import()
globallink_background_import in ./globallink_background_jobs.inc
Imports the documents

File

globallink_interface/globallink_interface.inc, line 181

Code

function globallink_interface_import(&$globallink) {
  module_load_include('inc', 'globallink', 'globallink');
  $target_xml = $globallink->targetXML;
  if (!isset($target_xml)) {
    $globallink->status = GLOBALLINK_STATUS_TRANSLATION_ERROR;
    return;
  }
  $language = globallink_get_drupal_locale_code($globallink->targetLocale);
  $translated_arr = globallink_interface_get_translated_items($target_xml);
  $lid = $translated_arr['lid'];
  foreach ($translated_arr as $attribute => $translations) {
    try {
      if ($attribute == 'lid') {
        continue;
      }
      $interface = '';
      if ($attribute == 'source') {
        $interface = globallink_load_source_data($translations['lid']);
        if ($interface == '') {
          throw new Exception('Source string not found for interface id ' . $lid . ' and field name ' . $attribute);
        }
      }
      $textgroup = 'default';
      $context = '';
      if (!empty($interface[0]->textgroup)) {
        $textgroup = $interface[0]->textgroup;
      }
      if (!empty($interface[0]->context)) {
        $context = $interface[0]->context;
      }
      $report =& drupal_static(__FUNCTION__, array(
        'additions' => 0,
        'updates' => 0,
        'deletes' => 0,
        'skips' => 0,
      ));
      _locale_import_one_string_db($report, $language, $context, $interface[0]->source, $translations['translation'], $textgroup, $translations['location'], LOCALE_IMPORT_OVERWRITE);
    } catch (Exception $e) {
      $globallink->status = GLOBALLINK_STATUS_TRANSLATION_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);
    }
  }
  if ($globallink->status != GLOBALLINK_STATUS_TRANSLATION_ERROR) {
    $globallink->status = GLOBALLINK_STATUS_TRANSLATION_IMPORTED;
  }
  return;
}