Skip to content

Commit

Permalink
Merge pull request #25600 from eileenmcnaughton/import_sql
Browse files Browse the repository at this point in the history
Fix handling of invalid sql query during import
  • Loading branch information
eileenmcnaughton authored Feb 22, 2023
2 parents 0ba86cb + b22688e commit d2980aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CRM/Import/DataSource/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ public static function formRule($fields, $files, $form) {
public function initialize(): void {
$table = CRM_Utils_SQL_TempTable::build()->setDurable();
$tableName = $table->getName();
$table->createWithQuery($this->getSubmittedValue('sqlQuery'));
try {
$table->createWithQuery($this->getSubmittedValue('sqlQuery'));
}
catch (PEAR_Exception $e) {
throw new CRM_Core_Exception($e->getMessage(), 0, ['exception' => $e]);
}

// Get the names of the fields to be imported.
$columnsResult = CRM_Core_DAO::executeQuery(
Expand Down
7 changes: 6 additions & 1 deletion CRM/Import/Form/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ protected function processDatasource(): void {
$this->flushDataSource();
$this->updateUserJobMetadata('submitted_values', $this->getSubmittedValues());
}
$this->instantiateDataSource();
try {
$this->instantiateDataSource();
}
catch (CRM_Core_Exception $e) {
CRM_Core_Error::statusBounce($e->getMessage());
}
}

/**
Expand Down

0 comments on commit d2980aa

Please sign in to comment.