Commit 8269ccf4 authored by ErikHommel's avatar ErikHommel
Browse files

fixes issues 4513 en 4532

parent 86c0986e
......@@ -32,8 +32,9 @@ class CRM_Acqconfigitems_ConfigItems {
}
$this->_resourcesPath = $resourcesPath;
$this->setContactTypes();
//$this->setRelationshipTypes();
$this->setRelationshipTypes();
$this->setOptionGroups();
$this->setGroups();
//$this->setTags();
// customData as last one because it might need one of the previous ones (option group, relationship types, activity types)
$this->setCustomData();
......@@ -73,6 +74,26 @@ class CRM_Acqconfigitems_ConfigItems {
}
}
/**
* Method to create groups
*
* @throws API_Exception when resource file not found
* @access protected
*/
protected function setGroups() {
$jsonFile = $this->_resourcesPath . 'groups.json';
if (!file_exists($jsonFile)) {
throw new API_Exception(E::ts('Could not load groups configuration file for extension,
contact your system administrator!'), 9929);
}
$groupsJson = file_get_contents($jsonFile);
$groups = json_decode($groupsJson, TRUE);
foreach ($groups as $name => $groupParams) {
$group = new CRM_Acqconfigitems_Group();
$group->create($groupParams);
}
}
/**
* Method to create contact types
*
......@@ -207,11 +228,10 @@ class CRM_Acqconfigitems_ConfigItems {
$customFieldData['custom_group_id'] = $created['id'];
$customField = new CRM_Acqconfigitems_CustomField();
try {
$customField->create($customFieldData);
$customField->create($customFieldData);
}
catch (Exception $exception) {
}
}
// remove custom fields that are still on install but no longer in config
CRM_Acqconfigitems_CustomField::removeUnwantedCustomFields($created['id'], $customGroupData);
......
......@@ -63,12 +63,15 @@ class CRM_Acqconfigitems_CustomDataQuery {
case "insert":
$this->buildInsertQuery();
break;
case "update":
$this->buildUpdateQuery();
break;
case "delete":
$this->buildDeleteQuery();
break;
case "select":
$this->buildSelectQuery();
break;
......@@ -87,10 +90,10 @@ class CRM_Acqconfigitems_CustomDataQuery {
foreach ($this->_sourceParams['custom_fields'] as $column => $value) {
$queryColumns[] = $column;
$index++;
$queryValues[] = "%".$index;
$queryValues[] = "%" . $index;
}
$columns = implode(",", $queryColumns);
$values = implode("," , $queryValues);
$values = implode(",", $queryValues);
$this->_query = "INSERT INTO {$this->_sourceParams['table_name']} ({$columns}) VALUES({$values})";
}
......@@ -104,7 +107,7 @@ class CRM_Acqconfigitems_CustomDataQuery {
$index = 1;
foreach ($this->_sourceParams['custom_fields'] as $column => $value) {
$index++;
$querySets[] = $column." = %".$index;
$querySets[] = $column . " = %" . $index;
}
$sets = implode(",", $querySets);
$this->_query = "UPDATE {$this->_sourceParams['table_name']} SET {$sets} WHERE entity_id = %1";
......@@ -116,7 +119,7 @@ class CRM_Acqconfigitems_CustomDataQuery {
* @access private
*/
private function buildDeleteQuery() {
$this->_query = "DELETE FROM ".$this->_sourceParams['table_name'] . " WHERE entity_id = ". $this->_sourceParams['entity_id'];
$this->_query = "DELETE FROM " . $this->_sourceParams['table_name'] . " WHERE entity_id = " . $this->_sourceParams['entity_id'];
}
/**
......@@ -130,8 +133,8 @@ class CRM_Acqconfigitems_CustomDataQuery {
foreach ($this->_sourceParams['custom_fields'] as $column => $value) {
$querySelectFields[] = $column;
}
$this->_query = "SELECT ".implode(",", $querySelectFields)." FROM ".$this->_sourceParams['table_name']
." WHERE entity_id = %1";
$this->_query = "SELECT " . implode(",", $querySelectFields) . " FROM " . $this->_sourceParams['table_name']
. " WHERE entity_id = %1";
}
/**
......@@ -175,7 +178,8 @@ class CRM_Acqconfigitems_CustomDataQuery {
$this->_sourceParams['query_action'] = strtolower($this->_sourceParams['query_action']);
if (!in_array($this->_sourceParams['query_action'], $this->_validQueryActions)) {
throw new API_Exception(E::ts('Invalid query_action ') . $this->_sourceParams['query_action']
. E::ts(' in params, could not build query for custom data in ') .__METHOD__, 9920);
. E::ts(' in params, could not build query for custom data in ') . __METHOD__, 9920);
}
}
}
......@@ -29,7 +29,7 @@ class CRM_Acqconfigitems_CustomField {
if (!isset($params['name']) || empty($params['name']) || !isset($params['custom_group_id'])
|| empty($params['custom_group_id'])) {
throw new API_Exception(ts(E::ts('When trying to create a Custom Field name and custom_group_id are
mandatory parameters and can not be empty in ') .__METHOD__), 9913);
mandatory parameters and can not be empty in ') . __METHOD__), 9913);
}
$this->_apiParams = $params;
if (isset($this->_apiParams['option_group'])) {
......@@ -37,7 +37,8 @@ class CRM_Acqconfigitems_CustomField {
$found = $optionGroup->getWithName($this->_apiParams['option_group']);
if (!empty($found)) {
$this->_apiParams['option_group_id'] = $found['id'];
} else {
}
else {
$created = $optionGroup->create(['name' => $this->_apiParams['option_group']]);
$this->_apiParams['option_group_id'] = $created['id'];
}
......@@ -69,7 +70,8 @@ class CRM_Acqconfigitems_CustomField {
if (isset($params['option_group'])) {
$this->fixOptionGroups($customField['values'], $params['option_group']);
}
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
throw new API_Exception(E::ts('Could not create or update custom field with name ') . $this->_apiParams['name']
. E::ts(' in custom group ') . $this->_apiParams['custom_group_id'] . E::ts(' in ') . __METHOD__
. E::ts(', error from API CustomField Create: ') . $ex->getMessage(), 9914);
......@@ -80,13 +82,14 @@ class CRM_Acqconfigitems_CustomField {
* Method to get custom field with name and custom group id
*
* @param string $name
* @param integer $customGroupId
* @param int $customGroupId
* @return array|bool
*/
public function getWithNameCustomGroupId($name, $customGroupId) {
try {
return civicrm_api3('CustomField', 'getsingle', ['name' => $name, 'custom_group_id' => $customGroupId]);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
return FALSE;
}
}
......@@ -119,7 +122,7 @@ class CRM_Acqconfigitems_CustomField {
*
* @param int $customGroupId
* @param array $configCustomGroupData
* @return boolean
* @return bool
* @access public
* @static
*/
......@@ -136,7 +139,8 @@ class CRM_Acqconfigitems_CustomField {
civicrm_api3('CustomField', 'Delete', ['id' => $existingId]);
}
}
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
return FALSE;
}
return TRUE;
......@@ -152,8 +156,10 @@ class CRM_Acqconfigitems_CustomField {
try {
$customFields = civicrm_api3('CustomField', 'Get', ['custom_group_id' => $customGroupId]);
return $customFields['values'];
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
return [];
}
}
}
\ No newline at end of file
}
......@@ -300,22 +300,26 @@ class CRM_Acqconfigitems_CustomGroup {
if (is_array($this->_apiParams['extends_entity_column_value'])) {
foreach ($this->_apiParams['extends_entity_column_value'] as $extendsValue) {
try {
$this->_apiParams['extends_entity_column_value'][] = (int)civicrm_api3('OptionValue', 'getvalue', [
$this->_apiParams['extends_entity_column_value'][] = (int) civicrm_api3('OptionValue', 'getvalue', [
'option_group_id' => 'campaign_type',
'name' => $extendsValue,
'return' => 'value',
]);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
}
}
} else {
}
else {
try {
$this->_apiParams['extends_entity_column_value'] = (int)civicrm_api3('OptionValue', 'getvalue', [
$this->_apiParams['extends_entity_column_value'] = (int) civicrm_api3('OptionValue', 'getvalue', [
'option_group_id' => 'campaign_type',
'name' => $this->_apiParams['extends_entity_column_value'],
'return' => 'value',
]);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
}
}
}
......
......@@ -18,7 +18,7 @@ class CRM_Acqconfigitems_Group {
public function __construct() {
$this->_apiParams = [];
}
/**
* Method to validate params for create
*
......@@ -48,7 +48,8 @@ class CRM_Acqconfigitems_Group {
$this->sanitizeParams();
try {
civicrm_api3('Group', 'create', $this->_apiParams);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
throw new API_Exception(E::ts('Could not create or update group type with name ')
. $this->_apiParams['name'] . E::ts(' in ') . __METHOD__ . E::ts(', error from API Group Create: ') . $ex->getMessage(), 9910);
}
......@@ -64,7 +65,8 @@ class CRM_Acqconfigitems_Group {
public function getWithName($groupName) {
try {
return civicrm_api3('Group', 'getsingle', ['name' => $groupName]);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
return FALSE;
}
}
......@@ -94,4 +96,5 @@ class CRM_Acqconfigitems_Group {
unset($this->_apiParams['parent']);
}
}
}
\ No newline at end of file
}
......@@ -35,7 +35,6 @@ class CRM_Acqconfigitems_OptionGroup {
* Method to create or update option group
*
* @param $params
* @return array
* @throws API_Exception when error in API Option Group Create
*/
public function create($params) {
......@@ -54,7 +53,8 @@ class CRM_Acqconfigitems_OptionGroup {
if (isset($params['option_values'])) {
$this->processOptionValues($optionGroup['id'], $params['option_values']);
}
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
throw new API_Exception(E::ts('Could not create or update option_group with name ')
. $this->_apiParams['name'] . E::ts(' in ') . __METHOD__ . E::ts(', error from API OptionGroup Create: ') . $ex->getMessage(), 9901);
}
......@@ -78,13 +78,14 @@ class CRM_Acqconfigitems_OptionGroup {
* Function to get the option group with name
*
* @param string $name
* @return array|boolean
* @return array|bool
*/
public function getWithName($name) {
$params = ['name' => $name];
try {
return civicrm_api3('OptionGroup', 'getsingle', $params);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
return [];
}
}
......@@ -112,7 +113,8 @@ class CRM_Acqconfigitems_OptionGroup {
1 => [0, 'Integer'],
2 => [$optionGroupId, 'Integer'],
]);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
}
}
}
......@@ -140,7 +142,8 @@ class CRM_Acqconfigitems_OptionGroup {
1 => [1, 'Integer'],
2 => [$optionGroupId, 'Integer'],
]);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
}
}
}
......@@ -163,8 +166,10 @@ class CRM_Acqconfigitems_OptionGroup {
}
// delete option group
civicrm_api3('OptionGroup', 'delete', ['id' => $optionGroupId]);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
}
}
}
}
\ No newline at end of file
}
......@@ -20,7 +20,7 @@ class CRM_Acqconfigitems_RelationshipType {
*/
protected function validateCreateParams($params) {
if (!isset($params['name_a_b']) || empty($params['name_a_b'])) {
throw new API_Exception(E::ts('Missing mandatory param name in ').__METHOD__, 9907);
throw new API_Exception(E::ts('Missing mandatory param name in ') . __METHOD__, 9907);
}
$this->_apiParams = $params;
}
......@@ -45,9 +45,10 @@ class CRM_Acqconfigitems_RelationshipType {
try {
civicrm_api3('RelationshipType', 'Create', $this->_apiParams);
//$this->updateNavigationMenuUrl();
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
throw new API_Exception(E::ts('Could not create or update relationship type with name ') . $this->_apiParams['label_a_b']
.E::ts(' in ').__METHOD__ . E::ts(', error from API RelationshipType Create: ') . $ex->getMessage(), 9908);
. E::ts(' in ') . __METHOD__ . E::ts(', error from API RelationshipType Create: ') . $ex->getMessage(), 9908);
}
}
......@@ -62,7 +63,8 @@ class CRM_Acqconfigitems_RelationshipType {
public function getWithName($relationshipTypeName) {
try {
return civicrm_api3('RelationshipType', 'Getsingle', ['name_a_b' => $relationshipTypeName]);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
return FALSE;
}
}
......@@ -83,7 +85,8 @@ class CRM_Acqconfigitems_RelationshipType {
1 => [0, 'Integer'],
2 => [$relationshipTypeId, 'Integer'],
]);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
}
}
}
......@@ -104,7 +107,8 @@ class CRM_Acqconfigitems_RelationshipType {
1 => [1, 'Integer'],
2 => [$relationshipTypeId, 'Integer'],
]);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
}
}
}
......@@ -121,8 +125,10 @@ class CRM_Acqconfigitems_RelationshipType {
// get relationship type with name
$relationshipTypeId = civicrm_api3('RelationshipType', 'getvalue', ['name_a_b' => $relationshipTypeName, 'return' => 'id']);
civicrm_api3('RelationshipType', 'delete', ['id' => $relationshipTypeId]);
} catch (CiviCRM_API3_Exception $ex) {
}
catch (CiviCRM_API3_Exception $ex) {
}
}
}
}
\ No newline at end of file
}
......@@ -25,4 +25,5 @@ class CRM_Acqconfigitems_Utils {
}
return implode(' ', $nameParts);
}
}
\ No newline at end of file
}
{
"acq_pers": {
"name": "acq_pers",
"title": "Pers",
"is_active":1,
"is_reserved":1,
"group_type":"2",
"description":"Groep voor pers"
},
"acq_account_managers": {
"name": "acq_account_managers",
"title": "Account Managers",
"is_active":1,
"is_reserved":1,
"group_type":"2",
"description":"Groep voor interne accountmanagers"
},
"acq_leveranciers": {
"name": "acq_leveranciers",
"title": "Leveranciers",
"is_active":1,
"is_reserved":1,
"group_type":"2",
"description":"Groep voor leveranciers"
}
}
\ No newline at end of file
{
"contactpersoon":
{
"name_a_b": "is_contactpersoon_voor",
"label_a_b":"is contactpersoon voor",
"name_b_a": "heeft_als_contactpersoon",
"label_b_a":"heeft als contactpersoon",
"contact_type_a": "Individual",
"contact_type_b": "Organization",
"is_active": 1
},
"dochteronderneming":
{
"name_a_b": "is_dochteronderneming_van",
"label_a_b":"is dochteronderneming van",
"name_b_a": "heeft_als_dochteronderneming",
"label_b_":"heeft als dochteronderneming",
"contact_type_b": "Organization",
"contact_type_a": "Organization",
"is_active": 1
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment