You are here

function taxonomy_xml_add_term_to_batch_queue in Taxonomy import/export via XML 6.2

Same name and namespace in other branches
  1. 6 taxonomy_xml.module \taxonomy_xml_add_term_to_batch_queue()
  2. 7 taxonomy_xml.process.inc \taxonomy_xml_add_term_to_batch_queue()

Manage batch queues by dividing them into recursive 'rounds'.

This is required because the current implementation of batch processing isn't actually as atomic as it looks, and it's easy to hit max_allowed_packets just by adding things to the queue.

Given a placeholder term item, make a note that it should be retrieved and analysed when possible.

Parameters

$term a template term object, must include at least a URI that: indicates where the rest of the information should be sourced from.

If no $term is given, this function RETURNS the remaining queue so far, in the form of a batch configuration object that can be batch_set().

Retrieving the queue empties the static list held here, so it can only be done once.

The returned queue will include a rider at the end of the operations that will trigger a recursion if it finds that new terms have been added to this list in the most recent round.

4 calls to taxonomy_xml_add_term_to_batch_queue()
taxonomy_xml_add_all_children_to_queue in ./taxonomy_xml.module
Queue up an import action.
taxonomy_xml_batch_requeue_more in ./taxonomy_xml.module
Batch callback action that should happen at the end of each round of processing.
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_rdf_parse in ./rdf_format.inc
Read in RDF taxonomies and vocabularies. Create vocabs and terms as needed.

File

./taxonomy_xml.module, line 2041
This module makes it possible to import and export taxonomies as XML documents.

Code

function taxonomy_xml_add_term_to_batch_queue($term = NULL) {
  if ($term) {
    $_SESSION['taxonomy_xml_batch_queue'][$term->guid] = array(
      'taxonomy_xml_import_from_url',
      array(
        $term,
      ),
    );
    watchdog('taxonomy_xml', "Batch Queued %term for import later...", array(
      '%term' => $term->guid,
    ), WATCHDOG_DEBUG);

    // To avoid overruns, ensure that batches are not too big
    if (count($_SESSION['taxonomy_xml_batch_queue']) >= TAXONOMY_XML_MAX_BATCH_SIZE) {
      batch_set(taxonomy_xml_add_term_to_batch_queue());
    }
  }
  else {

    // Called with no arg,
    // this means we want to return the queue so far, and flush it from here.
    if (!empty($_SESSION['taxonomy_xml_batch_queue'])) {

      // Prepare a batch config
      $batch_settings = array(
        'finished' => 'taxonomy_xml_batch_import_finished',
        'title' => t('Processing all queued import requests.'),
        'init_message' => t('Starting Batch Taxonomy Import.'),
        'progress_message' => t('Processed @current out of @total. (May require further recursion)', array()),
        'error_message' => t('Batch Taxonomy Import has encountered an error.'),
      );

      // Queue up our ops, and flush them from here.
      $batch_settings['operations'] = $_SESSION['taxonomy_xml_batch_queue'];
      unset($_SESSION['taxonomy_xml_batch_queue']);
      drupal_set_message(t("Retrieving the next batch queue. %operations_count operations in this batch . ", array(
        '%operations_count' => count($batch_settings['operations']),
      )));

      // The last thing each round should do is queue up the next round. Add this callback to the operations.
      $batch_settings['operations']['final'] = array(
        'taxonomy_xml_batch_requeue_more',
        array(),
      );
      return $batch_settings;
    }
    else {

      // If the queue is empty, return NULL so the caller won't get confused by an empty batch
      return NULL;
    }
  }
}