/**
* Set variables up before form is built.
+ *
+ * @throws \CRM_Core_Exception
*/
public function preProcess() {
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 = [];
}
closedir($handler);
if (!empty($results)) {
- CRM_Core_Error::fatal(ts('<b>%1</b> 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('<b>%1</b> 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,
]));
$this->assign('dataSourceFormTemplateFile', $templateFile);
}
elseif ($this->_dataSource) {
- throw new \CRM_Core_Exception("Invalid data source");
+ $this->invalidConfig('Invalid data source');
}
}
$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) {
$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!");
}
}
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
*