Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(REF) Importer - Remove unused parameters. Simplify signature. #23401

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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