$this->assign('showOnlyDataSourceFormPane', TRUE);
}
- if (strpos($this->_dataSource, 'CRM_Import_DataSource_') === 0) {
+ $dataSources = $this->_getDataSources();
+ if ($this->_dataSource && isset($dataSources[$this->_dataSource])) {
$this->_dataSourceIsValid = TRUE;
$this->assign('showDataSourceFormPane', TRUE);
$dataSourcePath = explode('_', $this->_dataSource);
$templateFile = "CRM/Contact/Import/Form/" . $dataSourcePath[3] . ".tpl";
$this->assign('dataSourceFormTemplateFile', $templateFile);
}
+ elseif ($this->_dataSource) {
+ throw new \CRM_Core_Exception("Invalid data source");
+ }
}
/**
* @throws Exception
*/
private function _getDataSources() {
+ // Hmm... file-system scanners don't really belong in forms...
+ if (isset(Civi::$statics[__CLASS__]['datasources'])) {
+ return Civi::$statics[__CLASS__]['datasources'];
+ }
+
// Open the data source dir and scan it for class files
$config = CRM_Core_Config::singleton();
$dataSourceDir = $config->importDataSourceDir;
require_once $dataSourceDir . DIRECTORY_SEPARATOR . $dataSourceFile;
$object = new $dataSourceClass();
$info = $object->getInfo();
- $dataSources[$dataSourceClass] = $info['title'];
+ if ($object->checkPermission()) {
+ $dataSources[$dataSourceClass] = $info['title'];
+ }
}
}
closedir($dataSourceHandle);
+
+ Civi::$statics[__CLASS__]['datasources'] = $dataSources;
return $dataSources;
}