You are here

function taxonomy_xml_import_from_url in Taxonomy import/export via XML 7

Same name and namespace in other branches
  1. 6.2 taxonomy_xml.module \taxonomy_xml_import_from_url()
  2. 6 taxonomy_xml.module \taxonomy_xml_import_from_url()

Import data from one URL. Function used by the batch operation

$param $term_placeholder A term object that is expected to be provided with at least a guid to go fetch data from. May have other context info (like the parent attribute) already set. This data should be merged onto that which is absorbed.

@ingroup batch_operations

1 string reference to 'taxonomy_xml_import_from_url'
taxonomy_xml_add_term_to_batch_queue in ./taxonomy_xml.process.inc
Manage batch queues by dividing them into recursive 'rounds'.

File

./taxonomy_xml.process.inc, line 1059
The workhorse processes for importing taxonomies.

Code

function taxonomy_xml_import_from_url($term_placeholder, &$context) {

  // TODO need to pass the per-service context around better than variable_get
  $format = variable_get('taxonomy_xml_format', 'rdf');
  $text = taxonomy_xml_cached_get_contents($term_placeholder->guid);
  if (empty($text)) {
    drupal_set_message(__FUNCTION__ . ' ' . t('Retrieved no content from URL %url. Returning failure.', array(
      '%url' => $term_placeholder->guid,
    )), 'error');
    return FALSE;
  }

  // drupal_set_message(t('Retrieved Queued URL %url. Now processing it.', array('%url' => $term_placeholder->guid)));
  // taxonomy_xml_cached_get_contents() used content negotiation.
  // @todo maybe add rdf-alternative awareness.
  // If we got given XHTML+RDFa, maybe that's useful too
  $vid = isset($term_placeholder->vid) ? $term_placeholder->vid : variable_get('taxonomy_xml_vid', 0);

  // Conditionally include and invoke the appropriate format library
  taxonomy_xml_load_format($format);
  $funcname = "taxonomy_xml_{$format}_parse";
  if (function_exists($funcname)) {
    $terms = $funcname($text, $vid, $term_placeholder->guid);

    // $terms is an array, as one URL may produce several terms,
    // It also contains all the known terms we referred to this round, not just the new one.
  }
  else {
    watchdog('taxonomy_xml', 'Error loading expected parse function %funcname . This is pretty bad and wholly unexpeceted. The library %format_format must be broken?', array(
      '%funcname' => $funcname,
      '%format' => $format,
    ), WATCHDOG_ERROR);
  }

  #dpm(array('placeholder was' => $term_placeholder, 'terms are' => $terms));
  $context['message'] = "Imported from " . $term_placeholder->guid;
  if (!empty($terms[$term_placeholder->guid])) {
    $this_term = $terms[$term_placeholder->guid];
    $context['results'][$this_term->tid] = $this_term->name;
    $context['message'] .= "<br/>Result: " . $this_term->name;
  }
  return $terms;
}