function taxonomy_csv_term_import in Taxonomy CSV import/export 6.2
Same name and namespace in other branches
- 6.5 import/taxonomy_csv.import.line.api.inc \taxonomy_csv_term_import()
- 6.3 import/taxonomy_csv.import.line.api.inc \taxonomy_csv_term_import()
- 6.4 import/taxonomy_csv.import.line.api.inc \taxonomy_csv_term_import()
- 7.5 import/taxonomy_csv.import.line.api.inc \taxonomy_csv_term_import()
- 7.4 import/taxonomy_csv.import.line.api.inc \taxonomy_csv_term_import()
Update or create a term with the given name in the given vocabulary and given parent.
Parameters
$term: A term object to import. Term contains:
- 'name' => term name string,
and eventually, matching options:
- 'tid' => term id,
- 'vid' => the vocabulary id where to import,
- 'description' => description string,
- 'weight' => weight integer,
- 'parents' => array of first level parent tids,
// Specific thesaurus fields.
- 'synonyms' => array of synonyms terms names strings,
- 'relations' => array of related tids,
$existing_items: (Optional) Type of import on existing terms. Default to ignore and create.
$all_vocabularies: (Optional) Boolean. Search in all vocabularies or only in $term->vid vocabulary (default), which need to be set. Used with relations import.
$parent_tid: (Optional) The direct parent term id where to restrict search. Used for structure import. Default to NULL (no parent restriction).
$import_format: (Optional) Name of import format. Needed only with formats with specific fields.
Return value
array 'name' => term name, 'tid' => term id, 'msg' => messages array.
3 calls to taxonomy_csv_term_import()
- taxonomy_csv_line_import in import/
taxonomy_csv.import.line.api.inc - Process the import of items.
- taxonomy_csv_line_import_geotaxonomy in formats/
geotaxonomy.format.inc - Import a line of items.
- taxonomy_csv_line_import_taxonomy_manager in formats/
taxonomy_manager.format.inc - Import a line of items.
File
- import/
taxonomy_csv.import.line.api.inc, line 525 - Process import of a csv line, i.e. of a term or a list of terms.
Code
function taxonomy_csv_term_import($term, $existing_items = TAXONOMY_CSV_EXISTING_IGNORE_CREATE, $all_vocabularies = FALSE, $parent_tid = NULL, $import_format = '') {
$messages = array();
if ($term) {
switch ($existing_items) {
case TAXONOMY_CSV_EXISTING_UPDATE:
// When no difference between update/merge and update/replace.
case TAXONOMY_CSV_EXISTING_UPDATE_MERGE:
$existing_term = taxonomy_csv_term_find($term, $all_vocabularies, $parent_tid);
if ($existing_term) {
// Unpdate only fields that are set. Other fields are not changed.
foreach ((array) $term as $key => $value) {
// Array fields : merge existing and new items.
if (is_array($value)) {
$term->{$key} = array_unique(array_merge($existing_term->{$key}, $term->{$key}));
}
// Else simply use new key: no merge is possible and useful for has been
// string, numeric or boolean fields.
// Description was an exception in previous version, but this
// exception is removed for simplicity and real use of this module.
// A option may be had if needed.
}
// Existing fields of existing term should be kept even if they have
// not been set in new term.
$term = (object) array_merge((array) $existing_term, (array) $term);
}
break;
case TAXONOMY_CSV_EXISTING_IGNORE_PREVIOUS:
// Doesn't ignore, but use previous parents.
case TAXONOMY_CSV_EXISTING_UPDATE_REPLACE:
$existing_term = taxonomy_csv_term_find($term, $all_vocabularies, $parent_tid);
if ($existing_term) {
// All fields are replaced by new ones. Other existing fields of
// existing term should be kept even if they are not set in new term.
$term = (object) array_merge((array) $existing_term, (array) $term);
}
break;
case TAXONOMY_CSV_EXISTING_IGNORE:
// When no difference between ignore/create and ignore/all.
case TAXONOMY_CSV_EXISTING_IGNORE_CREATE:
break;
case TAXONOMY_CSV_EXISTING_IGNORE_ALL:
// Ignore even existing terms in additional columns.
// @todo IGNORE_ALL
break;
case TAXONOMY_CSV_EXISTING_IGNORE_QUICK:
// Don't check existing terms. That's very similar to ignore all.
break;
}
// Save regularly formatted term.
// Return either SAVED_NEW, SAVED_UPDATED or FALSE (no change).
$result = taxonomy_csv_term_save($term);
// If there are specific fields, save them.
$funcname = "taxonomy_csv_term_import_{$import_format}";
if (taxonomy_csv_format_check($import_format, $funcname)) {
$result_temp = $funcname($term);
}
$messages[] = $result == SAVED_NEW ? 691 : 692;
// Saved or updated.
}
else {
$messages[] = 391;
// Error: not a term.
}
return array(
'name' => $term->name,
'tid' => $term->tid,
'msg' => $messages,
);
}