function taxonomy_csv_line_import in Taxonomy CSV import/export 7.5
Same name and namespace in other branches
- 6.5 import/taxonomy_csv.import.line.api.inc \taxonomy_csv_line_import()
- 6.2 import/taxonomy_csv.import.line.api.inc \taxonomy_csv_line_import()
- 6.3 import/taxonomy_csv.import.line.api.inc \taxonomy_csv_line_import()
- 6.4 import/taxonomy_csv.import.line.api.inc \taxonomy_csv_line_import()
- 7.4 import/taxonomy_csv.import.line.api.inc \taxonomy_csv_line_import()
Process the import of items.
Parameters
$line: Array which contains items of a cleaned and checked csv line.
$options: An associative array of import options:
- import_format : format of the csv line (see taxonomy.api.inc)
- keep_order : boolean. keep order of imported terms or not (default)
- vocabulary : vocabulary object where to import terms into
- update_or_ignore: indicates what will become existing terms, if any.
$previous_items: (Optional) Cleaned and checked previous imported line names and tids array. Needed with some contents as one term array structure.
$terms_count: (Optional integer) Total of imported terms (duplicate included) is needed to set weight of terms and to keep order of items, if wished.
Return value
Result array:
- 'name' => array of imported terms names,
- 'tid' => array of imported terms tids,
- 'msg' => array of message codes,
- 'terms_count' => number of imported terms.
2 calls to taxonomy_csv_line_import()
- taxonomy_csv_line_import_fields in import/
taxonomy_csv.import.line.api.inc - Import a fields line.
- taxonomy_csv_line_import_process in import/
taxonomy_csv.import.api.inc - Import a line that contains a term and other items matching the options.
File
- import/
taxonomy_csv.import.line.api.inc, line 33 - Process import of a csv line, i.e. of a term or a list of terms.
Code
function taxonomy_csv_line_import($line, $options, $previous_items = array(), $terms_count = 0) {
// Define default values.
$result = array(
'name' => array(),
'tid' => array(),
'msg' => array(),
'terms_count' => $terms_count,
);
// Only count check because function variables are already checked.
if (count($line)) {
switch ($options['import_format']) {
case TAXONOMY_CSV_FORMAT_FLAT:
$result = taxonomy_csv_line_import_flat($line, $options, $terms_count);
break;
case TAXONOMY_CSV_FORMAT_STRUCTURE:
case TAXONOMY_CSV_FORMAT_TREE:
// Internally, tree import format use ignore_previous and not update.
if ($options['update_or_ignore'] == TAXONOMY_CSV_EXISTING_UPDATE) {
$options['update_or_ignore'] = TAXONOMY_CSV_EXISTING_IGNORE_PREVIOUS;
}
$result = taxonomy_csv_line_import_structure($line, $options, $previous_items, $terms_count);
break;
case TAXONOMY_CSV_FORMAT_POLYHIERARCHY:
// Internally, polyhierarchy import format doesn't support Ignore.
$options['update_or_ignore'] = TAXONOMY_CSV_EXISTING_UPDATE;
$result = taxonomy_csv_line_import_structure($line, $options, $previous_items, $terms_count);
break;
case TAXONOMY_CSV_FORMAT_TID:
case TAXONOMY_CSV_FORMAT_TID_FLAT:
$result = taxonomy_csv_line_import_tid($line, $options, $terms_count);
break;
case TAXONOMY_CSV_FORMAT_TID_TREE:
// Internally, tree import format use ignore_previous and not update.
if ($options['update_or_ignore'] == TAXONOMY_CSV_EXISTING_UPDATE) {
$options['update_or_ignore'] = TAXONOMY_CSV_EXISTING_IGNORE_PREVIOUS;
}
$result = taxonomy_csv_line_import_tid($line, $options, $previous_items, $terms_count);
break;
case TAXONOMY_CSV_FORMAT_TID_POLYHIERARCHY:
// Internally, polyhierarchy import format doesn't support Ignore.
$options['update_or_ignore'] = TAXONOMY_CSV_EXISTING_UPDATE;
$result = taxonomy_csv_line_import_tid($line, $options, $previous_items, $terms_count);
break;
case TAXONOMY_CSV_FORMAT_FIELDS:
$result = taxonomy_csv_line_import_fields($line, $options, $previous_items, $terms_count);
break;
case TAXONOMY_CSV_FORMAT_TRANSLATE:
if (!module_exists('i18n_taxonomy')) {
$result['msg'][] = 360;
// Translation error.
break;
}
switch ($options['vocabulary']->i18n_mode) {
case I18N_MODE_LOCALIZE:
$result = taxonomy_csv_line_import_localize($line, $options, $terms_count);
break;
case I18N_MODE_TRANSLATE:
case I18N_MODE_MULTIPLE:
$result = taxonomy_csv_line_import_translate($line, $options, $terms_count);
break;
default:
$result['msg'][] = 361;
}
break;
default:
$result['msg'][] = 306;
}
}
else {
$result['msg'][] = 685;
// No term to process.
}
return $result;
}