You are here

function url_taxonomy_service_form_submit in Taxonomy import/export via XML 7

What to do when loading from this service

File

services/url.taxonomy_service.inc, line 70
declare how to import a taxonomy from remote url.

Code

function url_taxonomy_service_form_submit($form, &$form_state) {
  $service_id = $form_state['values']['service_id'];
  $parameters = $form_state['values'];
  $parameters['format'] = $parameters[$service_id]['format'];
  $url = $parameters[$service_id]['url'];

  // Invoke service and parse response
  // 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 for %url.', array(
      '%url' => $url,
    )),
    '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(
      $url,
      $parameters,
    ),
  );

  // #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(
      $url,
      $parameters,
    ),
  );

  // 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);
  watchdog('taxonomy_xml', 'Queued retrieval of remote URL. It will happen in stages to avoid timeout <a href="!url">!url</a>', array(
    '!url' => $url,
  ), WATCHDOG_DEBUG);
}