You are here

function taxonomy_xml_import_from_url in Taxonomy import/export via XML 6

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

Import one URL. Function used by the batch operation

$param $term_placeholder A term object that is expected to be provided with at least a URI 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 absobed.

@ingroup batch_operations

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

File

./taxonomy_xml.module, line 1257
taxonomy_xml.module This module makes it possible to import and export taxonomies as XML documents.

Code

function taxonomy_xml_import_from_url($term_placeholder, &$context) {
  $text = taxonomy_xml_cached_get_contents($term_placeholder->uri);

  #drupal_set_message(t('Retrieved Queued URL %url. Now processing it.', array('%url' => $term_placeholder->URI)));
  $format = variable_get('taxonomy_xml_format', 'xml');
  $vid = isset($term_placeholder->vid) ? $term_placeholder->vid : variable_get('taxonomy_xml_vid', 0);

  // Conditionally include and invoke the appropriate format library
  $incfile = dirname(drupal_get_filename('module', 'taxonomy_xml')) . '/' . $format . '.inc';
  include_once $incfile;
  $format_name = preg_replace('/_format$/', '', $format);
  $funcname = "taxonomy_xml_{$format_name}_parse";
  if (function_exists($funcname)) {
    $terms = $funcname($text, $vid, $term_placeholder->uri);

    // $terms is an array, as one URL may produce several terms,
    // It also contains all the known terms, not just the new one.
  }

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