Skip to content

Commit

Permalink
Merge pull request #23401 from eileenmcnaughton/import_data_source
Browse files Browse the repository at this point in the history
(REF) Importer - Remove unused parameters. Simplify signature.
  • Loading branch information
colemanw authored May 10, 2022
2 parents 440baea + 1a783cd commit 3fbdad5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
7 changes: 2 additions & 5 deletions CRM/Contact/Import/Form/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,11 @@ public function postProcess() {
*
* This gives the datasource a chance to do any table creation etc.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
private function instantiateDataSource(): void {
$dataSource = $this->getDataSourceObject();
// Get the PEAR::DB object
$dao = new CRM_Core_DAO();
$db = $dao->getDatabaseConnection();
$dataSource->postProcess($this->_params, $db, $this);
$this->getDataSourceObject()->initialize();
}

/**
Expand Down
10 changes: 10 additions & 0 deletions CRM/Import/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ abstract public function getInfo();
*/
abstract public function buildQuickForm(&$form);

/**
* Initialize the datasource, based on the submitted values stored in the user job.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function initialize(): void {

}

/**
* Determine if the current user has access to this data source.
*
Expand Down
9 changes: 2 additions & 7 deletions CRM/Import/DataSource/CSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,12 @@ public function buildQuickForm(&$form) {
}

/**
* 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
* @throws \API_Exception
*/
public function postProcess(&$params, &$db, &$form) {
public function initialize(): void {
$result = self::_CsvToTable(
$this->getSubmittedValue('uploadFile')['name'],
$this->getSubmittedValue('skipColumnHeader'),
Expand Down
9 changes: 2 additions & 7 deletions CRM/Import/DataSource/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,12 @@ public static function formRule($fields, $files, $form) {
}

/**
* 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
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function postProcess(&$params, &$db, &$form) {
public function initialize(): void {
$table = CRM_Utils_SQL_TempTable::build()->setDurable();
$tableName = $table->getName();
$table->createWithQuery($this->getSubmittedValue('sqlQuery'));
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function getMapFieldFormObject(array $submittedValues = []): CRM_Contact_
/* @var CRM_Contact_Import_Form_MapField $form */
$form = $this->getFormObject('CRM_Contact_Import_Form_MapField', $submittedValues);
$form->set('user_job_id', $userJobID);
$dataSource->postProcess($submittedValues, $null, $form);
$dataSource->initialize();

$contactFields = CRM_Contact_BAO_Contact::importableFields();
$fields = [];
Expand Down

0 comments on commit 3fbdad5

Please sign in to comment.