function taxonomy_xml_fetch_and_import in Taxonomy import/export via XML 6.2
Fetches the data according to the given method, then invokes the import on that data.
Parameters
$form_values - as submitted from the import form, but could also be an: array set programatically (by features or install hooks)
2 calls to taxonomy_xml_fetch_and_import()
- taxonomy_xml_import_form_submit in ./
taxonomy_xml.module - Imports the actual XML.
- taxonomy_xml_source_features_rebuild in ./
taxonomy_xml.features.inc - Create/recreate the items based on the data array.
File
- ./
taxonomy_xml.module, line 554 - This module makes it possible to import and export taxonomies as XML documents.
Code
function taxonomy_xml_fetch_and_import($form_values) {
// Allow either upload, web service or URL sources
//
switch ($form_values['protocol']) {
case 'upload-file':
// Retrieve submitted data and parse it
global $user;
// Try to limit bad uploads (limitation does not apply to uid1)
$validators = array(
'file_validate_extensions' => array(
TAXONOMY_XML_ALLOWED_UPLOAD_EXTENSIONS,
),
);
if ($file = file_save_upload('upload_file', $validators)) {
$fd = fopen($file->filepath, "rb");
if (!$fd) {
drupal_set_message(t('Vocabulary import failed: file %filename cannot be read.', array(
'%filename' => $file->filename,
)), 'error');
}
else {
$info = fstat($fd);
$len = $info["size"];
$text = fread($fd, $len);
fclose($fd);
drupal_set_message(t('Loaded file %filename. Now processing it.', array(
'%filename' => $file->filename,
)));
$form_values['file'] = $file;
taxonomy_xml_invoke_import($text, $form_values);
}
}
else {
drupal_set_message(t('Vocabulary import failed: file was not uploaded.'), 'error');
}
break;
case 'url':
// Retrieve remote URL and parser it
$url = $form_values['url'];
taxonomy_xml_invoke_import_on_url($url, $form_values);
break;
case 'filepath':
$filepath = $form_values['filepath'];
taxonomy_xml_invoke_import_on_filepath($filepath, $form_values);
break;
case 'service':
variable_set('taxonomy_xml_service_id', $form_values['service_id']);
// Invoke service and parse response
$services = taxonomy_xml_lookup_services(NULL, 'full');
$service = $services[$form_values['service_id']];
taxonomy_xml_invoke_service_request($service, $form_values);
break;
}
// The initial import may have queued up some further process to do.
// Check the queue and run it when this form goes.
batch_set(taxonomy_xml_add_term_to_batch_queue());
}