You are here

function taxonomy_xml_invoke_service_request in Taxonomy import/export via XML 7

Same name and namespace in other branches
  1. 6.2 taxonomy_xml.module \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 to invoke the service with.:

3 calls to taxonomy_xml_invoke_service_request()
lsid_taxonomy_service_form_submit in services/lsid.taxonomy_service.inc
What to do when loading from this service
sonz_taxonomy_service_form_submit in services/sonz.taxonomy_service.inc
What to do when loading from this service
taxonomy_xml_source_features_rebuild in ./taxonomy_xml.features.inc
Create/recreate the items based on the data array.

File

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

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'];
      $req = taxonomy_xml_sub_placeholders_into_pattern($service['pattern'], $values);

      # Was just:

      # $text = taxonomy_xml_cached_get_contents($req);

      # taxonomy_xml_invoke_import($text, $values, $req);

      // Now 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 %servicename.', array(
          '%servicename' => $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',
        'file' => drupal_get_path('module', 'taxonomy_xml') . '/taxonomy_xml.process.inc',
      );

      // 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;
    default:
      drupal_set_message(t("Taxonomy server protocol %protocol is not yet supported", array(
        '%protocol' => $service['protocol'],
      )), 'warning');
  }
}