function taxonomy_csv_vocabulary_import in Taxonomy CSV import/export 6.5
Same name and namespace in other branches
- 6.2 import/taxonomy_csv.import.api.inc \taxonomy_csv_vocabulary_import()
- 6.3 import/taxonomy_csv.import.api.inc \taxonomy_csv_vocabulary_import()
- 6.4 import/taxonomy_csv.import.api.inc \taxonomy_csv_vocabulary_import()
- 7.5 import/taxonomy_csv.import.api.inc \taxonomy_csv_vocabulary_import()
- 7.4 import/taxonomy_csv.import.api.inc \taxonomy_csv_vocabulary_import()
Prepare the batch to import the vocabulary. If not used in a form, don't forget to use batch_process().
Parameters
$options: Array. Same as taxonomy_csv_import. See above.
Return value
Array of errors or nothing (batch process to execute).
2 calls to taxonomy_csv_vocabulary_import()
- taxonomy_csv_form_import_submit in import/
taxonomy_csv.import.admin.inc - Handles CSV import form submission and launch batch set.
- taxonomy_csv_import in import/
taxonomy_csv.import.api.inc - Process the import of an input.
File
- import/
taxonomy_csv.import.api.inc, line 256 - Validate import options and manage import process.
Code
function taxonomy_csv_vocabulary_import($options) {
// Check options and return array of messages in case of errors.
if ($options['check_options']) {
$module_dir = drupal_get_path('module', 'taxonomy_csv');
require_once "{$module_dir}/import/taxonomy_csv.import.admin.inc";
$result = _taxonomy_csv_import_check_options($options);
if (count($result)) {
return $result;
}
}
// Complete $options.
// Switch soft tab delimiter with a true one if needed.
if (drupal_strlen($options['delimiter']) > 1) {
$result = _taxonomy_csv_import_soft_tab($options['file'], $options['delimiter']);
$options['delimiter'] = "\t";
}
// Calculates number of lines to be imported. File is already checked.
$options['total_lines'] = count(file($options['file']->filepath));
// Prepare vocabularies.
$name = _taxonomy_csv_import_vocabulary_prepare($options);
// Set locale if needed.
// See http://drupal.org/node/872366
$options['locale_previous'] = setlocale(LC_CTYPE, 0);
if ($options['locale_custom']) {
setlocale(LC_CTYPE, $options['locale_custom']);
}
// Prepare import batch.
// Use a one step batch in order to avoid memory crash in case of big import.
$batch = array(
'title' => $options['source_choice'] == 'text' ? t('Importing !total_lines lines from text...', array(
'!total_lines' => $options['total_lines'],
)) : t('Importing !total_lines lines from CSV file "%filename"...', array(
'%filename' => $name,
'!total_lines' => $options['total_lines'],
)),
'init_message' => t('Starting uploading of datas...'),
'progress_message' => '',
'error_message' => t('An error occurred during the import.'),
'finished' => '_taxonomy_csv_vocabulary_import_finished',
'file' => drupal_get_path('module', 'taxonomy_csv') . '/import/taxonomy_csv.import.api.inc',
'progressive' => TRUE,
'operations' => array(
0 => array(
'_taxonomy_csv_vocabulary_import_process',
array(
$options,
),
),
),
);
batch_set($batch);
}