Hi

I am trying to use taxonomy api to import terms.

I am using

$csv_lines = 'Europe, France, Paris';
$result = taxonomy_csv_vocabulary_import(
array(
'source_choice' => 'text',
'text' => $csv_lines,
'import_format' => 'tree_structure',
'existing_items' => 'update_replace',
));
First

I receive an error Warning: is_dir(): Unable to find the wrapper "public" - did you forget to enable it when you configured PHP? in file_prepare_directory() (line 402 of C:\xampp\htdocs\drupaltrial\includes\file.inc).

So how can i solve this problem.

Second i want to import in an existing vocabulary. How can i define vid in this code?

Comments

Daniel_KM’s picture

Hi,

Thanks to try 7.x release.

Example doesn't contain all variables. You can add vocabulary id as indicated line 135 (XXXX here) :

$csv_lines = 'Europe, France, Paris';
$result = taxonomy_csv_vocabulary_import(
  array(
    'source_choice' => 'text',
    'text' => $csv_lines,
    'import_format' => 'tree_structure',
    'existing_items' => 'update_replace',
    'vocabulary_target' => 'existing',
    'vocabulary_id' => XXXX,
));

For xampp or php error, i can't answer today, because Windows is not installed on my computer. I'll try wednesday.

Sincerely,

Daniel Berthereau
Knowledge manager

zulfierken’s picture

Hi I tried again wit your code and i have an error:
Fatal error: Call to undefined function taxonomy_get_vocabularies() in C:\xampp\htdocs\drupaltrial\sites\all\modules\taxonomy_csv\taxonomy_csv.api.inc on line 377
And also the public error continue to show.

I checked my taxonomy module and it is running fine. I tried to import with your import form it worked fine. Then why didnt the code work?

$taxonomy_csv_path = drupal_get_path('module', 'taxonomy_csv');
require_once("$taxonomy_csv_path/taxonomy_csv.api.inc");
$csv_lines = 'Europe, France, Paris';
$result = taxonomy_csv_vocabulary_import(
array(
'source_choice' => 'text',
'text' => $csv_lines,
'import_format' => 'tree_structure',
'existing_items' => 'update_replace',
'vocabulary_target' => 'existing',
'vocabulary_id' => 2,
));
This is what i put in my module and call it once the module run :(

Daniel_KM’s picture

Hi,

Apparently, Drupal module "Taxonomy" is not included, because taxonomy_get_vocabularies() is a function of this core module. Perhaps it's not enabled. So you should enable it in module pane.

Another way to do it cleaner is to to add dependencies in your my_module.info file :

dependencies[] = taxonomy
dependencies[] = taxonomy_csv (7.x-4.11)

The "(7.x-4.11)" is not needed, but next release 7.x-5 will change structure of module and eventually break compatibility.

If you don't want to enable module or to add dependencies, for example if you directly copy taxonomy_csv.api.inc in your module, you need to invoke taxonomy core module as taxonomy_csv module :

// Invoke taxonomy core api.
$taxonomy_path = drupal_get_path('module', 'taxonomy');
require_once("$taxonomy_path/taxonomy.module"); 
require_once("$taxonomy_path/taxonomy.api.php"); 
require_once("$taxonomy_path/taxonomy.admin.inc"); 

Sincerely,

Daniel Berthereau
Knowledge manager

Daniel_KM’s picture

Status: Active » Closed (fixed)

See my updated answer above.