You are here

function taxonomy_xml_invoke_import in Taxonomy import/export via XML 6.2

Same name and namespace in other branches
  1. 5.2 taxonomy_xml.module \taxonomy_xml_invoke_import()
  2. 5 taxonomy_xml.module \taxonomy_xml_invoke_import()
  3. 6 taxonomy_xml.module \taxonomy_xml_invoke_import()
  4. 7 taxonomy_xml.module \taxonomy_xml_invoke_import()

Do the actual importing from the given string, pased on the parameters passed from the form.

Return value

NULL. Writes success summary to the screen

See also

taxonomy_xml_formats()

taxonomy_xml_HOOK_parse()

3 calls to taxonomy_xml_invoke_import()
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_invoke_import_on_filepath in ./taxonomy_xml.module
Load a vocabulary from the given local filepath and import it
taxonomy_xml_invoke_import_on_url in ./taxonomy_xml.module
Load a vocabulary from the given URL and import it

File

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

Code

function taxonomy_xml_invoke_import($text, $form_values, $url = NULL) {
  $vid = $form_values['vid'];
  if ($vid == TAXONOMY_XML_CREATE_NEW) {

    // Requested to create new vocab.
    $newname = !empty($form_values['file']) ? basename($form_values['file']->filename) : basename($url);
    $vocabulary = _taxonomy_xml_get_vocabulary_placeholder($newname);
    $vid = $vocabulary->vid;
    variable_set('taxonomy_xml_vid', $vid);
  }

  // Sitemenu implodes when I try to do bulk updates? Or is it pathauto
  // @todo figure this out
  // module_disable(array('sitemenu','pathauto'));
  // Conditionally include and invoke the appropriate format library
  $format = $form_values['format'];
  module_load_include('inc', 'taxonomy_xml', $format . '_format');
  taxonomy_xml_include_module_hooks();
  $funcname = "taxonomy_xml_{$format}_parse";
  if (function_exists($funcname)) {

    // All the action is here:
    $modified_terms = $funcname($text, $vid, $url);

    // Func may have modified vocab or vid during its import. reload (just for these messages).
    $vocabulary = taxonomy_vocabulary_load($vid);
    if (empty($vocabulary)) {
      drupal_set_message("Failed to create or update vocabulary. Invalid ID", 'error');
      return FALSE;
    }
    if (!empty($modified_terms)) {
      if (is_array($modified_terms)) {
        $term_list = array();
        foreach ($modified_terms as $list_term) {
          $term_list[] = l($list_term->name, 'admin/content/taxonomy/edit/term/' . $list_term->tid);
        }
        drupal_set_message(t('Updated %count term(s)', array(
          '%count' => count($modified_terms),
        )) . ' <i>' . implode(', ', $term_list) . '.</i> ');
        drupal_set_message(t("\n          Imported vocabulary %vocab_name.\n          You may now need to <a href='!settings_link'>Review the vocabulary settings</a>\n          or <a href='!list_link'>List the terms</a>", array(
          '%vocab_name' => $vocabulary->name,
          '!settings_link' => url('admin/content/taxonomy/edit/vocabulary/' . $vid),
          '!list_link' => url('admin/content/taxonomy/' . $vid),
        )));
      }
      else {

        // returned something that was not an array.
        // maybe it was just 'OK'
      }
      return TRUE;
    }
    else {
      drupal_set_message(t("Failed to import any new terms. This may be due to syntax or formattings errors in the import file.", array()), 'error');
      return FALSE;
    }
  }
  else {
    drupal_set_message("Unavailable format. {$funcname} was not found in formatting library {$format}_format .", 'error');
    return FALSE;
  }
}