I'm working on a configuration script to automatically enable the taxonomy_xml module and import an xml file to populate the taxonomy. I'm trying to use the drupal_execute() function as follows:

$form_id = 'taxonomy_xml_import_form';
$field_values = array(
'vid' => '0',
'xml' => '/var/www/html/files/taxonomy_genre.xml',
'duplicate' => 0,
);

drupal_execute($form_id, $field_values);

However, it does not seem to work...nor does it produce an error. Note that xml is a form element of type file which the 'taxonomy_xml_import_form' normally uploads and parses. I suspect the issue is around this item. Has anyone run into this...?

Thank you for any ideas.

Comments

rmanola’s picture

I'm having the exact same problem...

function biblioref_populate_vocab($name) {
	$vid = db_fetch_object(db_query("SELECT vid FROM {vocabulary} WHERE name = '%s'", $name.'_taxonomy'));

	$form_id = 'taxonomy_xml_import_form';
	$field_values = array(
		'vid' => $vid,
		'xml' => drupal_get_path('module', 'biblioref').'/sample_vocab.xml',
		);
		
	drupal_execute($form_id, $field_values);
}

I'm getting a: "Vocabulary import failed: file was not uploaded."

It seems that the file field is not receiving the value that is passed.

Any help would be very appreciated.

rmanola’s picture

I found a workaround for our case, if the file we want to be imported is already in the server, we don't need to use "taxomomy_xml_import_form", you just have to call the function that actually parses the XML, you can do this:

        $end = drupal_get_path('module', 'module_name').'/sample_vocab.xml';
        // or in your case: $end = /var/www/html/files/taxonomy_genre.xm;l

        $file_temp = file_get_contents($end);

       module_invoke('taxonomy_xml', 'parse', $file_temp, 0);

This piece of code should create your vocabs.