function regcode_import_stream in Registration codes 5.3
Import codes from a stream (plain list or CSV text data)
Parameters
$stream: Stream handle of the stream to import from
$action: Import action: overwrite - overwrite any existing codes with same code identifiers as the imported ones skip - skip any import of a codes, if any code with same code identifier exists clean - completely wipe the code database befor importing all codes
$code_template: Optional code data template to use as default data setting for each imported code (key/value pairs for any applicable code field, see regcode_save_code)
Return value
Whether the import operation has been successful (TRUE) or not (FALSE)
2 calls to regcode_import_stream()
- regcode_import_file in ./
regcode_api.inc.php - Import codes from a file (plain list or CSV)
- regcode_import_text in ./
regcode_api.inc.php - Import codes from a multi-line string (plain list or CSV)
File
- ./
regcode_api.inc.php, line 404 - regcode_api.inc.php contains general low-level functions for the registration-code module, for tasks like
Code
function regcode_import_stream($stream, $action = NULL, $code_template = NULL) {
if (!$stream) {
return FALSE;
}
if (!$action) {
$action = variable_get('regcode_import_action', 'skip');
}
$delimiter = variable_get('regcode_import_csv_delimiter', ',');
$enclosure = variable_get('regcode_import_csv_text_enclosure', '"');
$fieldorder = variable_get('regcode_import_csv_fieldorder', 'code');
// clean codes when needed (depending on action)
regcode_clean_codes($action);
// iterate through stream line by line
while (($row = fgetcsv($stream, 9999, $delimiter, $enclosure)) !== FALSE) {
if (empty($fieldorder)) {
$fieldorder = $row;
}
else {
if (regcode_import_code($row, $action, $fieldorder, $code_template)) {
$count++;
}
}
}
drupal_set_message(t('!count registration codes imported.', array(
'!count' => intval($count),
)));
watchdog('RegistrationCode', t('!count registration codes imported.', array(
'!count' => intval($count),
)));
return $count > 0;
}