function taxonomy_xml_invoke_service_request in Taxonomy import/export via XML 6.2
Same name and namespace in other branches
- 7 taxonomy_xml.process.inc \taxonomy_xml_invoke_service_request()
Make a request on a remote taxonomy server and process the response
Remote services may be slow or unavailable, so we need to allow for that.
Parameters
$service an array describing properties of the chosen service:
$values as submitted from a form, settings (such as an: item ID) to invoke the service with.
2 calls to taxonomy_xml_invoke_service_request()
- taxonomy_xml_fetch_and_import in ./
taxonomy_xml.module - Fetches the data according to the given method, then invokes the import on that data.
- taxonomy_xml_source_features_rebuild in ./
taxonomy_xml.features.inc - Create/recreate the items based on the data array.
File
- ./
taxonomy_xml.module, line 2283 - This module makes it possible to import and export taxonomies as XML documents.
Code
function taxonomy_xml_invoke_service_request($service, $values) {
switch ($service['protocol']) {
case 'URI':
// Before running, need to make sure the preferences on the form
// are in line with those set for the service -
// ie, the format is selected right. Maybe more later?
$values['format'] = $service['format'];
variable_set('taxonomy_xml_format', $values['format']);
$req = taxonomy_xml_sub_placeholders_into_pattern($service['pattern'], $values);
// Need to break it into steps, to try and keep the times manageable.
// Prepare a batch config
$batch_settings = array(
'title' => t('Invoking a request on taxonomy server %name.', array(
'%name' => $service['name'],
)),
'operations' => array(),
// The last operation will be to see if any more jobs were queued in the meantime.
// unlimited batch recursion.
'finished' => 'taxonomy_xml_batch_import_finished',
);
// Break down the steps.
// #1, Fetch a reponse from the URL
$batch_settings['operations'][] = array(
'taxonomy_xml_cached_get_contents',
array(
$req,
),
);
// #2 That would have cached the response, so next time we open that file will be quicker
$batch_settings['operations'][] = array(
'taxonomy_xml_invoke_import_on_url',
array(
$req,
$values,
),
);
// Ensure that any pending jobs in the queue get found and done.
$batch_settings['operations']['final'] = array(
'taxonomy_xml_batch_requeue_more',
array(),
);
batch_set($batch_settings);
break;
case 'FILE':
taxonomy_xml_invoke_import_on_filepath($service['filepath'], $values);
break;
default:
drupal_set_message(t("Taxonomy server protocol %protocol is not yet supported", array(
'%protocol' => $service['protocol'],
)), 'warning');
}
}