You are here

function taxonomy_csv_import in Taxonomy CSV import/export 7.4

Same name and namespace in other branches
  1. 5 taxonomy_csv.module \taxonomy_csv_import()
  2. 6.5 import/taxonomy_csv.import.api.inc \taxonomy_csv_import()
  3. 6.2 import/taxonomy_csv.import.api.inc \taxonomy_csv_import()
  4. 6.3 import/taxonomy_csv.import.api.inc \taxonomy_csv_import()
  5. 6.4 import/taxonomy_csv.import.api.inc \taxonomy_csv_import()
  6. 7.5 import/taxonomy_csv.import.api.inc \taxonomy_csv_import()

Process the import of an input.

If not used in a form, don't forget to use batch_process().

Parameters

$options: An associative array of options:

  • file : object file if file is already uploaded
  • text : csv text to import
  • url : url to distant or local csv file
  • path : path to local csv file
  • import_format : see _taxonomy_csv_values (default: 'alone_terms')
  • delimiter : 1 character csv delimiter (default: ',')
  • enclosure : 0 or 1 character csv enclosure (default: none or '"')
  • check_line : boolean. check or not (default) format of lines
  • check_utf8 : boolean. check or not (default) utf8 format
  • locale_custom : string. specific locale of imported file
  • vocabulary_target: 'autocreate' (default), 'duplicate' or 'existing'
  • vocabulary_id : vocabulary id to duplicate or to import into
  • check_hierarchy: boolean. check (default) or not vocabulary hierarchy
  • set_hierarchy : if hierarchy isn't checked, set it (0, 1 or 2 (default))
  • existing_items : see _taxonomy_csv_values (default: 'update')

// Specific to relations import:

  • relations_create_subrelations: boolean.
  • relations_all_vocabularies : boolean.

// Level of result process infos.

  • check_options : boolean. check or not (default) this array of options
  • result_display : boolean. display or not (default). Only used with UI.
  • result_stats : boolean. display or not (default) stats
  • result_terms : boolean. display or not (default) list of imported terms
  • result_level : log: 'first' (default), 'warnings', 'notices' or 'infos'
  • result_type : display log 'by_message' (default) or 'by_line'

Only one option is required: file or text or url or path. Other options have default values. Warning: default values are different with UI.

Return value

Array of errors or nothing (need to execute batch process; result is logged in watchdog).

File

import/taxonomy_csv.import.api.inc, line 60
Validate import options and manage import process.

Code

function taxonomy_csv_import($options) {

  // Complete $options with default values if needed.
  // Default api and UI options are different.
  $options += _taxonomy_csv_values('list_import_default_values_api');

  // Preload text or file in order to check access to temporary folder.
  $messages = _taxonomy_csv_import_input_preload($options);
  if (count($messages)) {
    return $messages;
  }

  // Process import.
  taxonomy_csv_vocabulary_import($options);
}