Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(Crm): save relation always set type = CUSTOMER if missing
Browse files Browse the repository at this point in the history
... only do this for ADB_Model_Contact related records

Change-Id: Iadf80c4d1b0adeeed9c94ba8bd9df8f331fb3f62
Reviewed-on: http://gerrit.tine20.com/customers/14891
Tested-by: Jenkins CI (http://ci.tine20.com/) <tine20-jenkins@metaways.de>
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
  • Loading branch information
pschuele committed Dec 4, 2019
1 parent 1356e35 commit ca3734e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
19 changes: 19 additions & 0 deletions tests/tine20/Crm/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,4 +848,23 @@ public function testCreateLeadWithoutPermissionToInternalContacts()

self::assertEquals(1, count($newLead['relations']), 'two relations expected');
}

public function testAddEventRelationToLead()
{
$lead = $this->saveLead();
$event = Calendar_Controller_Event::getInstance()->create(new Calendar_Model_Event([
'dtstart' => '2015-01-01 00:00:00',
'dtend' => '2015-01-01 01:00:00',
'summary' => 'test event',
]));
$lead['relations'][] = [
'related_record' => $event->toArray(),
'related_model' => 'Calendar_Model_Event',
'type' => '',
'related_degree' => Tinebase_Model_Relation::DEGREE_SIBLING,
];
$updatedLead = $this->_getUit()->saveLead($lead);
self::assertEquals(4, count($updatedLead['relations']), 'relation count mismatch: '
. print_r($updatedLead, true));
}
}
14 changes: 7 additions & 7 deletions tine20/Crm/Model/Lead.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ protected function _setFromJson(array &$_data)
// TODO should be removed as we already have generic relation handling
if (isset($_data['relations'])) {
foreach ((array)$_data['relations'] as $key => $relation) {
if (! isset($relation['type']) || empty($relation['type'])) {
if (empty($relation['related_model'])) {
// related_model might be missing for contact relations
$relation['related_model'] = Addressbook_Model_Contact::class;
}
if (! isset($relation['type']) || empty($relation['type']) && isset($relation['related_model'])
&& $relation['related_model'] === Addressbook_Model_Contact::class)
{
// relation type might be missing for contact relations
$relation['type'] = 'CUSTOMER';
}
Expand Down Expand Up @@ -239,13 +245,7 @@ protected function _setFromJson(array &$_data)
$relation['type'] = strtoupper($relation['type']);
switch ($relation['type']) {
case 'RESPONSIBLE':
$data['related_model'] = 'Addressbook_Model_Contact';
$data['related_backend'] = Addressbook_Backend_Factory::SQL;
break;
case 'CUSTOMER':
$data['related_model'] = 'Addressbook_Model_Contact';
$data['related_backend'] = Addressbook_Backend_Factory::SQL;
break;
case 'PARTNER':
$data['related_model'] = 'Addressbook_Model_Contact';
$data['related_backend'] = Addressbook_Backend_Factory::SQL;
Expand Down

0 comments on commit ca3734e

Please sign in to comment.