}
/**
- * Process the form submission.
- *
- * @param array $params
- * @param string $db
- * @param \CRM_Core_Form $form
+ * Initialize the datasource, based on the submitted values stored in the user job.
*
+ * @throws \API_Exception
* @throws \CRM_Core_Exception
*/
- public function postProcess(&$params, &$db, &$form) {
- $file = $params['uploadFile']['name'];
+ public function initialize(): void {
$result = self::_CsvToTable(
- $file,
- CRM_Utils_Array::value('skipColumnHeader', $params, FALSE),
- CRM_Utils_Array::value('import_table_name', $params),
- CRM_Utils_Array::value('fieldSeparator', $params, ',')
+ $this->getSubmittedValue('uploadFile')['name'],
+ $this->getSubmittedValue('skipColumnHeader'),
+ $this->getSubmittedValue('fieldSeparator') ?? ','
);
+ $this->addTrackingFieldsToTable($result['import_table_name']);
- $form->set('originalColHeader', CRM_Utils_Array::value('column_headers', $result));
- $form->set('importTableName', $result['import_table_name']);
- $this->dataSourceMetadata = [
+ $this->updateUserJobMetadata('DataSource', [
'table_name' => $result['import_table_name'],
- 'column_headers' => $result['column_headers'] ?? NULL,
- ];
+ 'column_headers' => $this->getSubmittedValue('skipColumnHeader') ? $result['column_headers'] : [],
+ 'number_of_columns' => $result['number_of_columns'],
+ ]);
}
/**
* File name to load.
* @param bool $headers
* Whether the first row contains headers.
- * @param string $tableName
- * Name of table from which data imported.
* @param string $fieldSeparator
* Character that separates the various columns in the file.
*
private static function _CsvToTable(
$file,
$headers = FALSE,
- $tableName = NULL,
$fieldSeparator = ','
) {
$result = [];
}
}
- if ($tableName) {
- CRM_Core_DAO::executeQuery("DROP TABLE IF EXISTS $tableName");
- }
$table = CRM_Utils_SQL_TempTable::build()->setDurable();
$tableName = $table->getName();
CRM_Core_DAO::executeQuery("DROP TABLE IF EXISTS $tableName");
//get the import tmp table name.
$result['import_table_name'] = $tableName;
+ $result['number_of_columns'] = $numColumns;
return $result;
}