From: eileen Date: Wed, 24 Jul 2019 04:52:03 +0000 (+1200) Subject: Remove instances of CRM_Core_Error::fatal from first import form X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=15f715908be62943fab5bd76402f298d52c7821c;p=civicrm-core.git Remove instances of CRM_Core_Error::fatal from first import form --- diff --git a/CRM/Contact/Import/Form/DataSource.php b/CRM/Contact/Import/Form/DataSource.php index 2a7b1839e6..61ef6ae65d 100644 --- a/CRM/Contact/Import/Form/DataSource.php +++ b/CRM/Contact/Import/Form/DataSource.php @@ -46,6 +46,8 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form { /** * Set variables up before form is built. + * + * @throws \CRM_Core_Exception */ public function preProcess() { @@ -58,7 +60,7 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form { unset($errorScope); if ($daoTestPrivilege->_lastError) { - CRM_Core_Error::fatal(ts('Database Configuration Error: Insufficient permissions. Import requires that the CiviCRM database user has permission to create temporary tables. Contact your site administrator for assistance.')); + $this->invalidConfig(ts('Database Configuration Error: Insufficient permissions. Import requires that the CiviCRM database user has permission to create temporary tables. Contact your site administrator for assistance.')); } $results = []; @@ -81,7 +83,7 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form { } closedir($handler); if (!empty($results)) { - CRM_Core_Error::fatal(ts('%1 file(s) in %2 directory are not writable. Listed file(s) might be used during the import to log the errors occurred during Import process. Contact your site administrator for assistance.', [ + $this->invalidConfig(ts('%1 file(s) in %2 directory are not writable. Listed file(s) might be used during the import to log the errors occurred during Import process. Contact your site administrator for assistance.', [ 1 => implode(', ', $results), 2 => $config->uploadDir, ])); @@ -121,7 +123,7 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form { $this->assign('dataSourceFormTemplateFile', $templateFile); } elseif ($this->_dataSource) { - throw new \CRM_Core_Exception("Invalid data source"); + $this->invalidConfig('Invalid data source'); } } @@ -269,10 +271,10 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form { $dataSourceDir = $civicrm_root . DIRECTORY_SEPARATOR . 'CRM' . DIRECTORY_SEPARATOR . 'Import' . DIRECTORY_SEPARATOR . 'DataSource' . DIRECTORY_SEPARATOR; $dataSources = []; if (!is_dir($dataSourceDir)) { - CRM_Core_Error::fatal("Import DataSource directory $dataSourceDir does not exist"); + $this->invalidConfig("Import DataSource directory $dataSourceDir does not exist"); } if (!$dataSourceHandle = opendir($dataSourceDir)) { - CRM_Core_Error::fatal("Unable to access DataSource directory $dataSourceDir"); + $this->invalidConfig("Unable to access DataSource directory $dataSourceDir"); } while (($dataSourceFile = readdir($dataSourceHandle)) !== FALSE) { @@ -363,7 +365,7 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form { $parser->set($this); } else { - CRM_Core_Error::fatal("Invalid DataSource on form post. This shouldn't happen!"); + $this->invalidConfig("Invalid DataSource on form post. This shouldn't happen!"); } } @@ -406,6 +408,21 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form { return ['status' => $statusFieldName, 'pk' => $primaryKeyName]; } + /** + * General function for handling invalid configuration. + * + * I was going to statusBounce them all but when I tested I was 'bouncing' to weird places + * whereas throwing an exception gave no behaviour change. So, I decided to centralise + * and we can 'flip the switch' later. + * + * @param $message + * + * @throws \CRM_Core_Exception + */ + protected function invalidConfig($message) { + throw new CRM_Core_Exception($message); + } + /** * Return a descriptive name for the page, used in wizard header *