Commit 348d5e2a authored by jaapjansma's avatar jaapjansma

refactored data processor bao

parent 749da260
This diff is collapsed.
......@@ -14,7 +14,7 @@ class CRM_Dataprocessor_BAO_DataProcessorField extends CRM_Dataprocessor_DAO_Dat
$sql = "SELECT COUNT(*) FROM `civicrm_data_processor_field` WHERE `name` = %1 AND `data_processor_id` = %2";
$sqlParams[1] = array($name, 'String');
$sqlParams[2] = array($data_processor_id, 'String');
if (isset($id)) {
if ($id) {
$sql .= " AND `id` != %3";
$sqlParams[3] = array($id, 'Integer');
}
......
......@@ -14,7 +14,7 @@ class CRM_Dataprocessor_BAO_DataProcessorFilter extends CRM_Dataprocessor_DAO_Da
$sql = "SELECT COUNT(*) FROM `civicrm_data_processor_filter` WHERE `name` = %1 AND `data_processor_id` = %2";
$sqlParams[1] = array($name, 'String');
$sqlParams[2] = array($data_processor_id, 'String');
if (isset($id)) {
if ($id) {
$sql .= " AND `id` != %3";
$sqlParams[3] = array($id, 'Integer');
}
......
......@@ -14,7 +14,7 @@ class CRM_Dataprocessor_BAO_DataProcessorSource extends CRM_Dataprocessor_DAO_Da
$sql = "SELECT COUNT(*) FROM `civicrm_data_processor_source` WHERE `name` = %1 AND `data_processor_id` = %2";
$sqlParams[1] = array($name, 'String');
$sqlParams[2] = array($data_processor_id, 'String');
if (isset($id)) {
if ($id) {
$sql .= " AND `id` != %3";
$sqlParams[3] = array($id, 'Integer');
}
......
This diff is collapsed.
......@@ -11,6 +11,13 @@ class CRM_Dataprocessor_Form_DataProcessor extends CRM_Core_Form {
private $dataProcessorId;
private $dataProcessor;
/**
* @var \Civi\DataProcessor\ProcessorType\AbstractProcessorType
*/
private $dataProcessorClass;
private $currentUrl;
/**
......@@ -26,12 +33,12 @@ class CRM_Dataprocessor_Form_DataProcessor extends CRM_Core_Form {
$session = CRM_Core_Session::singleton();
switch($this->_action) {
case CRM_Core_Action::DISABLE:
CRM_Dataprocessor_BAO_DataProcessor::disable($this->dataProcessorId);
civicrm_api3('DataProcessor', 'create', array('id' => $this->dataProcessorId, 'is_active' => 0));
$session->setStatus('Data Processor disabled', 'Disable', 'success');
CRM_Utils_System::redirect($session->readUserContext());
break;
case CRM_Core_Action::ENABLE:
CRM_Dataprocessor_BAO_DataProcessor::enable($this->dataProcessorId);
civicrm_api3('DataProcessor', 'create', array('id' => $this->dataProcessorId, 'is_active' => 1));
$session->setStatus('Data Processor enabled', 'Enable', 'success');
CRM_Utils_System::redirect($session->readUserContext());
break;
......@@ -41,11 +48,14 @@ class CRM_Dataprocessor_Form_DataProcessor extends CRM_Core_Form {
CRM_Utils_System::redirect($session->readUserContext());
break;
case CRM_Core_Action::EXPORT:
$this->assign('export', json_encode(CRM_Dataprocessor_BAO_DataProcessor::export($this->dataProcessorId), JSON_PRETTY_PRINT));
$this->assign('export', json_encode(CRM_Dataprocessor_Utils_Importer::export($this->dataProcessorId), JSON_PRETTY_PRINT));
break;
}
if ($this->dataProcessorId) {
$this->dataProcessor = civicrm_api3('DataProcessor', 'getsingle', array('id' => $this->dataProcessorId));
$this->dataProcessorClass = CRM_Dataprocessor_BAO_DataProcessor::dataProcessorToClass($this->dataProcessor);
$this->assign('dataProcessor', $this->dataProcessor);
$this->addSources();
$this->addFields();
$this->addFilters();
......@@ -95,14 +105,14 @@ class CRM_Dataprocessor_Form_DataProcessor extends CRM_Core_Form {
}
protected function addAggregateFields() {
$fields = array();
$aggregationFields = CRM_Dataprocessor_BAO_DataProcessor::getAvailableAggregationFields($this->dataProcessorId);
$aggregationFieldsFormatted = array();
foreach($aggregationFields as $field) {
$aggregationFieldsFormatted[$field->fieldSpecification->alias] = $field->dataSource->getSourceTitle()." :: ".$field->fieldSpecification->title;
foreach($this->dataProcessorClass->getDataSources() as $dataSource) {
foreach($dataSource->getAvailableAggregationFields() as $field) {
$aggregationFieldsFormatted[$field->fieldSpecification->alias] = $field->dataSource->getSourceTitle()." :: ".$field->fieldSpecification->title;
}
}
$dataProcessor = CRM_Dataprocessor_BAO_DataProcessor::getValues(array('id' => $this->dataProcessorId));
$aggregation = $dataProcessor[$this->dataProcessorId]['aggregation'];
$aggregation = $this->dataProcessor['aggregation'];
$fields = array();
foreach($aggregation as $alias) {
$fields[$alias] = $aggregationFieldsFormatted[$alias];
}
......@@ -176,7 +186,7 @@ class CRM_Dataprocessor_Form_DataProcessor extends CRM_Core_Form {
public function postProcess() {
$session = CRM_Core_Session::singleton();
if ($this->_action == CRM_Core_Action::DELETE) {
CRM_Dataprocessor_BAO_DataProcessor::deleteWithId($this->dataProcessorId);
civicrm_api3('DataProcessor', 'delete', array('id' => $this->dataProcessorId));
$session->setStatus(E::ts('Data Processor removed'), E::ts('Removed'), 'success');
$redirectUrl = $session->popUserContext();
CRM_Utils_System::redirect($redirectUrl);
......@@ -191,7 +201,7 @@ class CRM_Dataprocessor_Form_DataProcessor extends CRM_Core_Form {
$params['id'] = $this->dataProcessorId;
}
$result = CRM_Dataprocessor_BAO_DataProcessor::add($params);
$result = civicrm_api3('DataProcessor', 'create', $params);
$redirectUrl = CRM_Utils_System::url('civicrm/dataprocessor/form/edit', array('reset' => 1, 'action' => 'update', 'id' => $result['id']));
CRM_Utils_System::redirect($redirectUrl);
}
......@@ -227,18 +237,17 @@ class CRM_Dataprocessor_Form_DataProcessor extends CRM_Core_Form {
* @access protected
*/
protected function setUpdateDefaults(&$defaults) {
$dataProcessor = CRM_Dataprocessor_BAO_DataProcessor::getValues(array('id' => $this->dataProcessorId));
if (!empty($dataProcessor) && !empty($this->dataProcessorId)) {
$defaults['title'] = $dataProcessor[$this->dataProcessorId]['title'];
if (isset($dataProcessor[$this->dataProcessorId]['name'])) {
$defaults['name'] = $dataProcessor[$this->dataProcessorId]['name'];
if (!empty($this->dataProcessor) && !empty($this->dataProcessorId)) {
$defaults['title'] = $this->dataProcessor['title'];
if (isset($this->dataProcessor['name'])) {
$defaults['name'] = $this->dataProcessor['name'];
}
if (isset($dataProcessor[$this->dataProcessorId]['description'])) {
$defaults['description'] = $dataProcessor[$this->dataProcessorId]['description'];
if (isset($this->dataProcessor['description'])) {
$defaults['description'] = $this->dataProcessor['description'];
} else {
$defaults['description'] = '';
}
$defaults['is_active'] = $dataProcessor[$this->dataProcessorId]['is_active'];
$defaults['is_active'] = $this->dataProcessor['is_active'];
}
}
......@@ -258,9 +267,9 @@ class CRM_Dataprocessor_Form_DataProcessor extends CRM_Core_Form {
$id = $fields['id'];
}
if (empty($fields['name'])) {
$fields['name'] = CRM_Dataprocessor_BAO_DataProcessor::buildNameFromTitle($fields['title']);
$fields['name'] = CRM_Dataprocessor_BAO_DataProcessor::checkName($fields['title'], $id);
}
if (!CRM_Dataprocessor_BAO_DataProcessor::isNameValid($fields['name'], $id)) {
if (!CRM_Dataprocessor_BAO_DataProcessorSource::isNameValid($fields['name'], $id)) {
$errors['name'] = E::ts('There is already a data processor with this name');
return $errors;
}
......
......@@ -29,7 +29,7 @@ class CRM_Dataprocessor_Form_Import extends CRM_Core_Form {
public function postProcess() {
$values = $this->exportValues();
$importCode = json_decode($values['code'], true);
$importResult = CRM_Dataprocessor_Utils_Importer::import($importCode, '');
$importResult = CRM_Dataprocessor_Utils_Importer::import($importCode, '', true);
CRM_Core_Session::setStatus(E::ts('Imported data processor'), '', 'success');
......
<?php
use CRM_Dataprocessor_ExtensionUtil as E;
/**
* Form controller class
*
* @see https://wiki.civicrm.org/confluence/display/CRMDOC/QuickForm+Reference
*/
class CRM_Dataprocessor_Form_Join_Simple extends CRM_Core_Form {
private $dataProcessorId;
private $source_id;
/**
* Function to perform processing before displaying form (overrides parent function)
*
* @access public
*/
function preProcess() {
$this->dataProcessorId = CRM_Utils_Request::retrieve('data_processor_id', 'Integer');
$this->assign('data_processor_id', $this->dataProcessorId);
$this->source_id = CRM_Utils_Request::retrieve('source_id', 'Integer', CRM_Core_DAO::$_nullObject, TRUE);
$this->assign('source_id', $this->source_id);
$source = CRM_Dataprocessor_BAO_Source::getValues(array('id' => $this->source_id));
$this->assign('source', $source[$this->source_id]);
$title = E::ts('Data Processor Source Join Conifuration');
CRM_Utils_System::setTitle($title);
}
public function buildQuickForm() {
$this->add('hidden', 'data_processor_id');
$this->add('hidden', 'source_id');
$fields = $this->buildFieldList();
$this->add('select', 'left_field', ts('Select field'), $fields, true, array(
'style' => 'min-width:250px',
'class' => 'crm-select2 huge',
'placeholder' => E::ts('- select -'),
));
$this->add('select', 'right_field', ts('Select field'), $fields, true, array(
'style' => 'min-width:250px',
'class' => 'crm-select2 huge',
'placeholder' => E::ts('- select -'),
));
if ($this->_action == CRM_Core_Action::ADD) {
$this->addButtons(array(
array('type' => 'next', 'name' => E::ts('Next'), 'isDefault' => TRUE,),
array('type' => 'cancel', 'name' => E::ts('Cancel'))));
} elseif ($this->_action == CRM_Core_Action::DELETE) {
$this->addButtons(array(
array('type' => 'next', 'name' => E::ts('Delete'), 'isDefault' => TRUE,),
array('type' => 'cancel', 'name' => E::ts('Cancel'))));
} else {
$this->addButtons(array(
array('type' => 'next', 'name' => E::ts('Save'), 'isDefault' => TRUE,),
array('type' => 'cancel', 'name' => E::ts('Cancel'))));
}
parent::buildQuickForm();
}
function setDefaultValues() {
$defaults = [];
$defaults['data_processor_id'] = $this->dataProcessorId;
$defaults['source_id'] = $this->source_id;
$source = CRM_Dataprocessor_BAO_Source::getValues(array('id' => $this->source_id));
if (isset($source[$this->source_id]['join_configuration']['left_prefix'])) {
$defaults['left_field'] = $source[$this->source_id]['join_configuration']['left_prefix'].".".$source[$this->source_id]['join_configuration']['left_field'];
}
if (isset($source[$this->source_id]['join_configuration']['right_prefix'])) {
$defaults['right_field'] = $source[$this->source_id]['join_configuration']['right_prefix'].".".$source[$this->source_id]['join_configuration']['right_field'];
}
return $defaults;
}
public function postProcess() {
$session = CRM_Core_Session::singleton();
$values = $this->exportValues();
list($left_prefix, $left_field) = explode(".",$values['left_field'], 2);
list($right_prefix, $right_field) = explode(".",$values['right_field'], 2);
$params['join_configuration'] = array(
'left_prefix' => $left_prefix,
'left_field' => $left_field,
'right_prefix' => $right_prefix,
'right_field' => $right_field
);
if ($this->dataProcessorId) {
$params['data_processor_id'] = $this->dataProcessorId;
}
if ($this->source_id) {
$params['id'] = $this->source_id;
}
CRM_Dataprocessor_BAO_Source::add($params);
CRM_Utils_System::redirect($session->readUserContext());
parent::postProcess();
}
function buildFieldList() {
$factory = dataprocessor_get_factory();
$fields = array();
$dataProcessor = CRM_Dataprocessor_BAO_DataProcessor::getDataProcessorById($this->dataProcessorId);
$sources = CRM_Dataprocessor_BAO_Source::getValues(array('data_processor_id' => $this->dataProcessorId));
foreach($sources as $source) {
$sourceClass = $factory->getDataSourceByName($source['type']);
$sourceClass->setDataProcessor($dataProcessor);
$sourceClass->initialize($source['configuration'], $source['name']);
$sourceFields = $sourceClass->getAvailableFields()->getFields();
foreach($sourceFields as $sourceField) {
$fields[$source['name'] . '.' . $sourceField->name] = $source['title'] . ' :: ' . $sourceField->title;
}
if ($source['id'] == $this->source_id) {
break;
}
}
asort($fields);
return $fields;
}
}
\ No newline at end of file
......@@ -15,38 +15,24 @@ class CRM_Dataprocessor_Form_ManageDataProcessors extends CRM_Core_Form {
$this->setTitle(E::ts('Manage Data Processors'));
$whereClauses = array("1");
$apiParams = array();
if (isset($formValues['title']) && !empty($formValues['title'])) {
$whereClauses[] = "`title` LIKE '%". CRM_Utils_Type::escape($formValues['title'], 'String')."%'";
$apiParams['title']['LIKE'] = $formValues['title'];
}
if (isset($formValues['description']) && !empty($formValues['description'])) {
$whereClauses[] = "`description` LIKE '%". CRM_Utils_Type::escape($formValues['description'], 'String')."%'";
$apiParams['description']['LIKE'] = $formValues['description'];
}
if (isset($formValues['is_active']) && $formValues['is_active'] == '0') {
$whereClauses[] = "`is_active` = 0";
$apiParams['is_active'] = 0;
} elseif (isset($formValues['is_active']) && $formValues['is_active'] == '1') {
$whereClauses[] = "`is_active` = 1";
$apiParams['is_active'] = 1;
}
$apiParams['options']['limit'] = 0;
$dataProcessors = civicrm_api3('DataProcessor', 'get', $apiParams);
$dataProcessors = $dataProcessors['values'];
$whereStatement = implode(" AND ", $whereClauses);
$sql = "SELECT * FROM civicrm_data_processor WHERE {$whereStatement} ORDER BY is_active, title";
$dataProcessors = array();
$dao = CRM_Core_DAO::executeQuery($sql, array(), false, 'CRM_Dataprocessor_DAO_DataProcessor');
while($dao->fetch()) {
$row = array();
CRM_Dataprocessor_DAO_DataProcessor::storeValues($dao, $row);
switch ($row['status']) {
case CRM_Dataprocessor_DAO_DataProcessor::STATUS_IN_CODE:
$row['status_label'] = E::ts('In code');
break;
case CRM_Dataprocessor_DAO_DataProcessor::STATUS_OVERRIDDEN:
$row['status_label'] = E::ts('Overridden');
break;
case CRM_Dataprocessor_DAO_DataProcessor::STATUS_IN_DATABASE:
$row['status_label'] = E::ts('In database');
break;
}
$dataProcessors[] = $row;
foreach($dataProcessors as $idx => $dataProcessor) {
$dataProcessors[$idx]['status_label'] = CRM_Dataprocessor_Status::statusToLabel($dataProcessor['status']);
}
$this->assign('data_processors', $dataProcessors);
......
......@@ -9,19 +9,19 @@ use CRM_Dataprocessor_ExtensionUtil as E;
abstract class CRM_Dataprocessor_Form_Output_AbstractUIOutputForm extends CRM_Core_Form_Search {
/**
* @var \Civi\DataProcessor\ProcessorType\AbstractProcessorType;
* @var array
*/
protected $dataProcessor;
/**
* @var int
* @var \Civi\DataProcessor\ProcessorType\AbstractProcessorType;
*/
protected $dataProcessorId;
protected $dataProcessorClass;
/**
* @var array
* @var int
*/
protected $dataProcessorBAO;
protected $dataProcessorId;
/**
* @var \CRM_Dataprocessor_BAO_Output
......@@ -74,11 +74,10 @@ abstract class CRM_Dataprocessor_Form_Output_AbstractUIOutputForm extends CRM_Co
if (!$dao->fetch()) {
throw new \Exception('Could not find Data Processor "' . $dataProcessorName.'"');
}
$this->dataProcessor = CRM_Dataprocessor_BAO_DataProcessor::getDataProcessorById($dao->data_processor_id);
$this->dataProcessorId = $dao->data_processor_id;
$dataProcessorBAO = CRM_Dataprocessor_BAO_DataProcessor::getValues(array('id' => $this->dataProcessorId));
$this->dataProcessorBAO = $dataProcessorBAO[$this->dataProcessorId];
$this->dataProcessor = civicrm_api3('DataProcessor', 'getsingle', array('id' => $dao->data_processor_id));
$this->dataProcessorClass = \CRM_Dataprocessor_BAO_DataProcessor::dataProcessorToClass($this->dataProcessor);
$this->dataProcessorId = $dao->data_processor_id;
$output = CRM_Dataprocessor_BAO_Output::getValues(['id' => $dao->output_id]);
$this->dataProcessorOutput = $output[$dao->output_id];
......@@ -96,8 +95,8 @@ abstract class CRM_Dataprocessor_Form_Output_AbstractUIOutputForm extends CRM_Co
* @return bool
*/
protected function hasRequiredFilters() {
if ($this->dataProcessor->getFilterHandlers()) {
foreach ($this->dataProcessor->getFilterHandlers() as $filter) {
if ($this->dataProcessorClass->getFilterHandlers()) {
foreach ($this->dataProcessorClass->getFilterHandlers() as $filter) {
if ($filter->isRequired()) {
return true;
}
......@@ -113,8 +112,8 @@ abstract class CRM_Dataprocessor_Form_Output_AbstractUIOutputForm extends CRM_Co
*/
protected function validateFilters() {
$errors = array();
if ($this->dataProcessor->getFilterHandlers()) {
foreach ($this->dataProcessor->getFilterHandlers() as $filter) {
if ($this->dataProcessorClass->getFilterHandlers()) {
foreach ($this->dataProcessorClass->getFilterHandlers() as $filter) {
$errors = array_merge($errors, $filter->validateSubmittedFilterParams($this->_formValues));
}
}
......@@ -139,8 +138,8 @@ abstract class CRM_Dataprocessor_Form_Output_AbstractUIOutputForm extends CRM_Co
*/
protected function buildCriteriaForm() {
$filterElements = array();
if ($this->dataProcessor->getFilterHandlers()) {
foreach ($this->dataProcessor->getFilterHandlers() as $filterHandler) {
if ($this->dataProcessorClass->getFilterHandlers()) {
foreach ($this->dataProcessorClass->getFilterHandlers() as $filterHandler) {
$fieldSpec = $filterHandler->getFieldSpecification();
if (!$fieldSpec) {
continue;
......
......@@ -11,10 +11,12 @@ class CRM_Dataprocessor_Form_Source extends CRM_Core_Form {
private $dataProcessorId;
private $dataProcessor;
/**
* @var Civi\DataProcessor\ProcessorType\AbstractProcessorType
*/
private $dataProcessor;
private $dataProcessorClass;
private $id;
......@@ -54,7 +56,8 @@ class CRM_Dataprocessor_Form_Source extends CRM_Core_Form {
$this->dataProcessorId = CRM_Utils_Request::retrieve('data_processor_id', 'Integer');
$this->assign('data_processor_id', $this->dataProcessorId);
if ($this->dataProcessorId) {
$this->dataProcessor = CRM_Dataprocessor_BAO_DataProcessor::getDataProcessorById($this->dataProcessorId);
$this->dataProcessor = civicrm_api3('DataProcessor', 'getsingle', array('id' => $this->dataProcessorId));
$this->dataProcessorClass = CRM_Dataprocessor_BAO_DataProcessor::dataProcessorToClass($this->dataProcessor);
}
$this->id = CRM_Utils_Request::retrieve('id', 'Integer');
......@@ -143,8 +146,7 @@ class CRM_Dataprocessor_Form_Source extends CRM_Core_Form {
));
if ($this->joinClass && $this->joinClass->hasConfiguration()) {
$joinableToSources = array();
$dataProcessor = CRM_Dataprocessor_BAO_DataProcessor::getDataProcessorById($this->dataProcessorId);
foreach($dataProcessor->getDataSources() as $source) {
foreach($this->dataProcessorClass->getDataSources() as $source) {
if ($this->sourceClass && $this->sourceClass->getSourceName() == $source->getSourceName()) {
break;
}
......@@ -225,24 +227,6 @@ class CRM_Dataprocessor_Form_Source extends CRM_Core_Form {
}
$result = civicrm_api3('DataProcessorSource', 'create', $params);
if (!$this->isFirstDataSource && $this->_action == CRM_Core_Action::ADD) {
$joinClass = $factory->getJoinByName($values['join_type']);
if ($joinClass->getConfigurationUrl()) {
$joinUrl = CRM_Utils_System::url($joinClass->getConfigurationUrl(), [
'reset' => 1,
'action' => 'add',
'source_id' => $result['id'],
'data_processor_id' => $this->dataProcessorId
]);
$session->pushUserContext($backUrl);
$redirectUrl = $joinUrl;
} else {
$session->pushUserContext($backUrl);
}
} elseif ($this->_action == CRM_Core_Action::ADD) {
$session->pushUserContext($backUrl);
}
CRM_Utils_System::redirect($redirectUrl);
parent::postProcess();
}
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
use CRM_Dataprocessor_ExtensionUtil as E;
class CRM_Dataprocessor_Status {
const STATUS_IN_DATABASE = 1;
const STATUS_IN_CODE = 2;
const STATUS_OVERRIDDEN = 3;
/**
* Returns a textual representation of the status
*
* @param $status
* @return string
*/
public static function statusToLabel($status) {
switch ($status) {
case CRM_Dataprocessor_Status::STATUS_IN_CODE:
return E::ts('In code');
break;
case CRM_Dataprocessor_Status::STATUS_OVERRIDDEN:
return E::ts('Overridden');
break;
case CRM_Dataprocessor_Status::STATUS_IN_DATABASE:
return E::ts('In database');
break;
}
return E::ts('Unknown');
}
}
\ No newline at end of file
......@@ -16,9 +16,10 @@ class CRM_Dataprocessor_Utils_DataSourceFields {
* @throws \Exception
*/
public static function getAvailableFieldsInDataSources($dataProcessorId) {
$dataProcessor = CRM_Dataprocessor_BAO_DataProcessor::getDataProcessorById($dataProcessorId);
$dataProcessor = civicrm_api3('DataProcessor', 'getsingle', array('id' => $dataProcessorId));
$dataProcessorClass = \CRM_Dataprocessor_BAO_DataProcessor::dataProcessorToClass($dataProcessor);
$fieldSelect = array();
foreach($dataProcessor->getDataSources() as $dataSource) {
foreach($dataProcessorClass->getDataSources() as $dataSource) {
$fieldSelect = array_merge($fieldSelect, self::getAvailableFieldsInDataSource($dataSource, $dataSource->getSourceTitle().' :: ', $dataSource->getSourceName().'::'));
}
return $fieldSelect;
......
......@@ -6,28 +6,103 @@
class CRM_Dataprocessor_Utils_Importer {
public static function import($data, $filename) {
$data_processor_id = CRM_Dataprocessor_BAO_DataProcessor::getId($data['name']);
$status = CRM_Dataprocessor_BAO_DataProcessor::getStatus($data['name']);
/**
* Exports a data processor
*
* Returns the array with the whole configuration.
*
* @param $data_processor_id
* @return array
* @throws \Exception
*/
public static function export($data_processor_id) {
$dataProcessor = civicrm_api3('DataProcessor', 'getsingle', array('id' => $data_processor_id));
unset($dataProcessor['id']);
unset($dataProcessor['status']);
unset($dataProcessor['source_file']);
$sources = civicrm_api3('DataProcessorSource', 'get', array('data_processor_id' => $data_processor_id, 'options' => array('limit' => 0)));
$dataProcessor['data_sources'] = array();
foreach($sources['values'] as $i => $datasource) {
unset($datasource['id']);
unset($datasource['data_processor_id']);
$dataProcessor['data_sources'][] = $datasource;
}
$filters = civicrm_api3('DataProcessorFilter', 'get', array('data_processor_id' => $data_processor_id, 'options' => array('limit' => 0)));
$dataProcessor['filters'] = array();
foreach($filters['values'] as $i => $filter) {
unset($filter['id']);
unset($filter['data_processor_id']);
$dataProcessor['filters'][] = $filter;
}
$fields = civicrm_api3('DataProcessorField', 'get', array('data_processor_id' => $data_processor_id, 'options' => array('limit' => 0)));
$dataProcessor['fields'] = array();
foreach($fields['values'] as $i => $field) {
unset($field['id']);
unset($field['data_processor_id']);
$dataProcessor['fields'][] = $field;
}
$outputs = $outputs = civicrm_api3('DataProcessorOutput', 'get', array('data_processor_id' => $data_processor_id, 'options' => array('limit' => 0)));
$dataProcessor['outputs'] = array();
foreach($outputs['values'] as $i => $output) {
unset($output['id']);
unset($output['data_processor_id']);
$dataProcessor['outputs'][] = $output;
}
$eventData['data_processor'] = &$dataProcessor;
$event = \Civi\Core\Event\GenericHookEvent::create($eventData);
\Civi::dispatcher()->dispatch('hook_civicrm_dataprocessor_export', $event);
return $dataProcessor;
}
public static function import($data, $filename, $overWriteInDatabase=false) {
$new_status = null;
$new_id = null;
CRM_Dataprocessor_BAO_DataProcessor::setDataProcessorToImportingState($data['name']);
$data_processor_id = null;
$status = null;
try {
$dataProcessor = civicrm_api3('DataProcessor', 'getsingle', ['name' => $data['name']]);
$data_processor_id = $dataProcessor['id'];
$status = $dataProcessor['status'] ? $dataProcessor['status'] : CRM_Dataprocessor_Status::STATUS_IN_DATABASE;
} catch (Exception $e) {
// Do nothing
}
switch ($status) {
case CRM_Dataprocessor_DAO_DataProcessor::STATUS_IN_DATABASE:
case CRM_Dataprocessor_Status::STATUS_IN_DATABASE:
// Update to overriden