function taxonomy_xml_add_all_children_to_queue in Taxonomy import/export via XML 6
Same name and namespace in other branches
- 6.2 taxonomy_xml.module \taxonomy_xml_add_all_children_to_queue()
- 7 taxonomy_xml.process.inc \taxonomy_xml_add_all_children_to_queue()
If the currently processing term refers to other terms by URI, set up a process to retrieve them recursively later.
For all unknown $term->predicates[TAXONOMY_XML_CHILD] URIs, add a job to the batch queue.
Helper function for parser routines
See also
taxonomy_xml_add_term_to_batch_queue
3 calls to taxonomy_xml_add_all_children_to_queue()
- taxonomy_xml_mesh_parse in ./
mesh_format.inc - Reads a XML file and creates the term definitions found in it.
- taxonomy_xml_rdf_parse in ./
rdf_format.inc - Read in RDF taxonomies and vocabularies. Create vocabs and terms as needed.
- taxonomy_xml_tcs_parse in ./
tcs_format.inc - Reads a TCS file and creates the term definitions found in it.
File
- ./
taxonomy_xml.module, line 771 - taxonomy_xml.module This module makes it possible to import and export taxonomies as XML documents.
Code
function taxonomy_xml_add_all_children_to_queue($term) {
if (variable_get('taxonomy_xml_recurse_down', TRUE) && !empty($term->predicates[TAXONOMY_XML_CHILD])) {
// Add child items to the import queue.
$children = $term->predicates[TAXONOMY_XML_CHILD];
#dpm(array('Queuing children' => $children));
foreach ((array) $children as $child_ref) {
// Check that it looks like a valid URL we can request
$url_parts = @parse_url($child_ref);
if (!empty($url_parts['host'])) {
// The ref is a URI.
// Check we don't know it already.
if ($found_term = taxonomy_xml_get_term_by_uri($child_ref)) {
#dpm("Found known term by URI, $child_ref is ". $found_term->tid );
// This is cool, we have a handle on this term. Make a note in the global list
$terms =& taxonomy_xml_current_terms();
$terms[$child_ref] = $found_term;
}
else {
// Save the request as a batch job to do later. Our session queue will tuck this away and remember it.
// Create a placeholder so at least we know where this item is being imported to
// Beware memory. This should be lightweight, as the batch API seems to be treating it inefficiently.
$placeholder_term = (object) array(
'uri' => $child_ref,
'parent' => array(
$term->tid => $term->tid,
),
'vid' => $term->vid,
);
taxonomy_xml_add_term_to_batch_queue($placeholder_term);
#drupal_set_message(t("While processing %term_name, did not immediately recognise external reference to child term !child_ref . Queuing it for later retrieval and import", array('%term_name' => $term->name, '!child_ref' => l($child_ref, $child_ref))));
}
}
else {
// The referred term is not a URI, nor do we recognise its identifier so far.
// It's a dangling reference. What can we do?
// Handle URI/GUID lookup services?
//
// TODO Should do this with a hook/service-callback rather than built into this module.
// TODO - this uses a global, should use batch context info
if ($service_id = variable_get('taxonomy_xml_service_id', '')) {
$services = taxonomy_xml_lookup_services(NULL, 'full');
$service = $services[$service_id];
$lookup_uri = taxonomy_xml_sub_placeholders_into_pattern($service['pattern'], array(
$service['identifier'] => $child_ref,
));
#drupal_set_message(t('Will use service lookup to find !child_ref', array('!child_ref' => l($child_ref, $lookup_uri), '%servicename' => $service['servicename'])));
$placeholder_term = (object) array(
'uri' => $lookup_uri,
'parent' => array(
$term->tid => $term->tid,
),
);
taxonomy_xml_add_term_to_batch_queue($placeholder_term);
}
else {
drupal_set_message(t('Cannot yet resolve non-URI references, and no resolver service is active. %child_ref', array(
'%child_ref' => $child_ref,
)));
}
}
}
}
}