function taxonomy_xml_csvancestry_parse in Taxonomy import/export via XML 7
Same name and namespace in other branches
- 6.2 csvancestry_format.inc \taxonomy_xml_csvancestry_parse()
Scan the input CSV file and create a taxonomy structure out of it.
See the sample files for the expected format of the CSV
File
- formats/
csvancestry_format.inc, line 37
Code
function taxonomy_xml_csvancestry_parse(&$data, $vid) {
$output = '';
// Unset the global variables before we use them:
unset($GLOBALS['$_taxonomy_xml_terms']);
$terms = array();
$new_terms = array();
$skipped_terms = array();
$vocabulary = array();
if ($vid) {
$vocabulary = taxonomy_vocabulary_load($vid);
}
else {
drupal_set_message(t('No vocab to import into. Either make one or choose one.'));
return;
}
$rows = explode("\n", $data);
#drupal_set_message(t('%rowcount rows of data', array('%rowcount' => count($rows))));
// Unlike all other formats, each line and term is complete.
// It's required that parents are created before children.
// We don't need to mess around with parsing, just create the term.
$terms = array();
// Prepare a batch config
$batch_settings = array(
'title' => t('Processing all queued import requests.'),
'file' => drupal_get_path('module', 'taxonomy_xml') . '/csvancestry_format.inc',
'operations' => array(),
'finished' => 'cvsancestry_import_finished',
);
foreach ($rows as $row) {
$row_data = csv_string_to_array($row);
// Queue the import of this line
$batch_settings['operations'][] = array(
'cvsancestry_import_row',
array(
$vid,
$row_data,
),
);
}
batch_set($batch_settings);
drupal_set_message(t('Queued %rowcount rows of data', array(
'%rowcount' => count($rows),
)));
return "OK, processing is being done in batch...";
}