Commit 27f44980 authored by jaapjansma's avatar jaapjansma
Browse files

fixed issue with create/update relationship

parent a56a19aa
...@@ -54,7 +54,7 @@ class FindIndividualByNameAndEmail extends AbstractAction { ...@@ -54,7 +54,7 @@ class FindIndividualByNameAndEmail extends AbstractAction {
WHERE contact.is_deleted = 0 AND contact.is_deceased = 0 AND contact.contact_type = 'Individual' WHERE contact.is_deleted = 0 AND contact.is_deceased = 0 AND contact.contact_type = 'Individual'
AND contact.first_name = %2 AND contact.last_name = %3 AND contact.first_name = %2 AND contact.last_name = %3
ORDER BY weight ORDER BY weight ASC
"; ";
$sqlParams[1] = array($parameters->getParameter('email'), 'String'); $sqlParams[1] = array($parameters->getParameter('email'), 'String');
......
...@@ -76,19 +76,21 @@ class CreateOrUpdateRelationship extends CreateRelationship { ...@@ -76,19 +76,21 @@ class CreateOrUpdateRelationship extends CreateRelationship {
* @throws \Exception * @throws \Exception
*/ */
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) { protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
$relationship_type_id = $this->relationshipTypeIds[$this->configuration->getParameter('relationship_type_id')];
$relationship_id = false; $relationship_id = false;
$alsoUpdateInactiveOne = false; $alsoUpdateInactiveOne = false;
if ($this->configuration->doesParameterExists('also_update_inactive') && $this->configuration->getParameter('also_update_inactive')) { if ($this->configuration->doesParameterExists('also_update_inactive') && $this->configuration->getParameter('also_update_inactive')) {
$alsoUpdateInactiveOne = true; $alsoUpdateInactiveOne = true;
} }
$relationship_id = $this->findExistingRelationshipId($parameters->getParameter('contact_id_a'), $parameters->getParameter('contact_id_b'), $this->relationshipTypes[$parameters->getParameter('relationship_type_id')], $alsoUpdateInactiveOne); $relationship_id = $this->findExistingRelationshipId($parameters->getParameter('contact_id_a'), $parameters->getParameter('contact_id_b'), $relationship_type_id, $alsoUpdateInactiveOne);
if ($relationship_id) { if ($relationship_id) {
$relationshipParams['id'] = $relationship_id; $relationshipParams['id'] = $relationship_id;
} }
// Get the contact and the event. // Get the contact and the event.
$relationshipParams['contact_id_a'] = $parameters->getParameter('contact_id_a'); $relationshipParams['contact_id_a'] = $parameters->getParameter('contact_id_a');
$relationshipParams['contact_id_b'] = $parameters->getParameter('contact_id_b'); $relationshipParams['contact_id_b'] = $parameters->getParameter('contact_id_b');
$relationshipParams['relationship_type_id'] = $this->relationshipTypeIds[$this->configuration->getParameter('relationship_type_id')]; $relationshipParams['relationship_type_id'] = $relationship_type_id;
$relationshipParams['is_active'] = '1'; $relationshipParams['is_active'] = '1';
if ($this->configuration->getParameter('set_start_date') && !$relationship_id) { if ($this->configuration->getParameter('set_start_date') && !$relationship_id) {
$today = new \DateTime(); $today = new \DateTime();
...@@ -97,7 +99,6 @@ class CreateOrUpdateRelationship extends CreateRelationship { ...@@ -97,7 +99,6 @@ class CreateOrUpdateRelationship extends CreateRelationship {
if ($relationship_id) { if ($relationship_id) {
$relationshipParams['end_date'] = 'null'; $relationshipParams['end_date'] = 'null';
} }
$relationshipParams['custom'] = array(); $relationshipParams['custom'] = array();
foreach($this->getParameterSpecification() as $spec) { foreach($this->getParameterSpecification() as $spec) {
if (stripos($spec->getName(), 'custom_')!==0) { if (stripos($spec->getName(), 'custom_')!==0) {
...@@ -119,6 +120,7 @@ class CreateOrUpdateRelationship extends CreateRelationship { ...@@ -119,6 +120,7 @@ class CreateOrUpdateRelationship extends CreateRelationship {
$output->setParameter('id', $relationship->id); $output->setParameter('id', $relationship->id);
} catch (\Exception $e) { } catch (\Exception $e) {
// Do nothing. // Do nothing.
echo $e;
} }
} }
......
...@@ -163,7 +163,7 @@ class GetRelationship extends AbstractAction { ...@@ -163,7 +163,7 @@ class GetRelationship extends AbstractAction {
$relationshipFindParams['is_active'] = '0'; $relationshipFindParams['is_active'] = '0';
try { try {
$relationship = civicrm_api3('Relationship', 'getsingle', $relationshipFindParams); $relationship = civicrm_api3('Relationship', 'getsingle', $relationshipFindParams);
$relationship; return $relationship;
} catch (\Exception $e) { } catch (\Exception $e) {
// Do nothing // Do nothing
} }
......
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