Commit 348d5e2a authored by jaapjansma's avatar jaapjansma
Browse files

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');
}
......
<?php
use CRM_Dataprocessor_ExtensionUtil as E;
/**
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2019
*
* Generated from /buildkit/build/search/sites/default/files/civicrm/ext/dataprocessor/xml/schema/CRM/Dataprocessor/DataProcessor.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:28cee8d17fc4e4fca4b21a0b4dbf17ff)
*/
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
* Database access object for the DataProcessor entity.
*/
class CRM_Dataprocessor_DAO_DataProcessor extends CRM_Core_DAO {
const STATUS_IN_DATABASE = 1;
const STATUS_IN_CODE = 2;
const STATUS_OVERRIDDEN = 3;
/**
* Static instance to hold the table name.
*
* @var string
*/
static $_tableName = 'civicrm_data_processor';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var bool
*/
static $_log = FALSE;
/**
* static instance to hold the field values
* Unique DataProcessor ID
*
* @var array
* @static
* @var int unsigned
*/
static $_fields = null;
static $_export = null;
public $id;
/**
* empty definition for virtual function
* @var string
*/
static function getTableName() {
return 'civicrm_data_processor';
public $name;
/**
* @var string
*/
public $title;
/**
* @var string
*/
public $type;
/**
* @var text
*/
public $configuration;
/**
* @var text
*/
public $aggregation;
/**
* @var boolean
*/
public $is_active;
/**
* @var text
*/
public $description;
/**
* @var string
*/
public $storage_type;
/**
* @var text
*/
public $storage_configuration;
/**
* @var int unsigned
*/
public $status;
/**
* @var string
*/
public $source_file;
/**
* Class constructor.
*/
public function __construct() {
$this->__table = 'civicrm_data_processor';
parent::__construct();
}
/**
* returns all the column names of this table
* Returns all the column names of this table
*
* @access public
* @return array
*/
public static function &fields() {
if (!(self::$_fields)) {
self::$_fields = array(
'id' => array(
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = [
'id' => [
'name' => 'id',
'title' => E::ts('ID'),
'type' => CRM_Utils_Type::T_INT,
'required' => true
) ,
'type' => array(
'name' => 'type',
'title' => E::ts('Type'),
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 80,
'required' => true,
),
'name' => array(
'description' => CRM_Dataprocessor_ExtensionUtil::ts('Unique DataProcessor ID'),
'required' => TRUE,
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
],
'name' => [
'name' => 'name',
'title' => E::ts('Name'),
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 128,
'required' => true
),
'title' => array(
'title' => CRM_Dataprocessor_ExtensionUtil::ts('Name'),
'required' => FALSE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
],
'title' => [
'name' => 'title',
'title' => E::ts('Title'),
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 128,
'required' => true
),
'is_active' => array(
'name' => 'is_active',
'title' => E::ts('Is active'),
'type' => CRM_Utils_Type::T_INT,
),
'description' => array(
'name' => 'description',
'title' => E::ts('Description'),
'title' => CRM_Dataprocessor_ExtensionUtil::ts('Title'),
'required' => TRUE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
],
'type' => [
'name' => 'type',
'type' => CRM_Utils_Type::T_STRING,
),
'configuration' => array(
'title' => CRM_Dataprocessor_ExtensionUtil::ts('Type'),
'required' => TRUE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
],
'configuration' => [
'name' => 'configuration',
'title' => E::ts('Configuration'),
'type' => CRM_Utils_Type::T_TEXT,
),
'aggregation' => array(
'title' => CRM_Dataprocessor_ExtensionUtil::ts('Configuration'),
'required' => FALSE,
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
'serialize' => self::SERIALIZE_JSON,
],
'aggregation' => [
'name' => 'aggregation',
'title' => E::ts('Aggregation'),
'type' => CRM_Utils_Type::T_TEXT,
),
'storage_type' => array(
'title' => CRM_Dataprocessor_ExtensionUtil::ts('Aggregation Fields'),
'required' => FALSE,
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
'serialize' => self::SERIALIZE_JSON,
],
'is_active' => [
'name' => 'is_active',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => CRM_Dataprocessor_ExtensionUtil::ts('Is active'),
'required' => TRUE,
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
],
'description' => [
'name' => 'description',
'type' => CRM_Utils_Type::T_TEXT,
'title' => CRM_Dataprocessor_ExtensionUtil::ts('Description'),
'required' => FALSE,
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
],
'storage_type' => [
'name' => 'storage_type',
'title' => E::ts('Storage Type'),
'type' => CRM_Utils_Type::T_STRING,
'maxlength' => 80,
'required' => true,
),
'storage_configuration' => array(
'title' => CRM_Dataprocessor_ExtensionUtil::ts('Storage Type'),
'required' => FALSE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
],
'storage_configuration' => [
'name' => 'storage_configuration',
'title' => E::ts('Storage Configuration'),
'type' => CRM_Utils_Type::T_TEXT,
),
'status' => array(
'title' => CRM_Dataprocessor_ExtensionUtil::ts('Storage Configuration'),
'required' => FALSE,
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
'serialize' => self::SERIALIZE_JSON,
],
'status' => [
'name' => 'status',
'type' => CRM_Utils_Type::T_INT,
),
'source_file' => array(
'title' => CRM_Dataprocessor_ExtensionUtil::ts('Status'),
'required' => FALSE,
'default' => '0',
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
],
'source_file' => [
'name' => 'source_file',
'title' => E::ts('Source file'),
'type' => CRM_Utils_Type::T_STRING,
'title' => CRM_Dataprocessor_ExtensionUtil::ts('Source File'),
'required' => FALSE,
'maxlength' => 255,
'required' => false,
),
);
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_data_processor',
'entity' => 'DataProcessor',
'bao' => 'CRM_Dataprocessor_DAO_DataProcessor',
'localizable' => 0,
],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return self::$_fields;
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Returns an array containing, for each field, the array key used for that
* field in self::$_fields.
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @access public
* @return array
* Array(string $name => string $uniqueName).
*/
public static function &fieldKeys() {
if (!(self::$_fieldKeys)) {
self::$_fieldKeys = array(
'id' => 'id',
'type' => 'type',
'name' => 'name',
'title' => 'title',
'is_active' => 'is_active',
'description' => 'description',
'configuration' => 'configuration',
'storage_type' => 'storage_type',
'storage_configuration' => 'storage_configuration',
'status' => 'status',
'source_file' => 'source_file',
);
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return self::$_fieldKeys;
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
public static function getTableName() {
return self::$_tableName;
}
/**
* Returns if this table needs to be logged
*
* @return bool
*/
public function getLog() {
return self::$_log;
}
}
\ No newline at end of file
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
public static function &import($prefix = FALSE) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'data_processor', $prefix, []);
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
public static function &export($prefix = FALSE) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'data_processor', $prefix, []);
return $r;
}
/**
* Returns the list of indices
*
* @param bool $localize
*
* @return array
*/
public static function indices($localize = TRUE) {
$indices = [];
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}
......@@ -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]);