By grepping universe we can see that params['contact_check'] only ever has one value when called
from the supported core place and the unsupported jma grant application extension place.
By clarifying that here we can do further cleanup without having to re-search universe...
* @return array
* @throws \CRM_Core_Exception
*/
* @return array
* @throws \CRM_Core_Exception
*/
- public static function legacyCreateMultiple(&$params, $ids = []) {
- $valid = $invalid = $duplicate = $saved = 0;
- $relationships = $relationshipIds = [];
+ public static function legacyCreateMultiple($params, $ids = []) {
// clarify that the only key ever pass in the ids array is 'contact'
// There is legacy handling for other keys but a universe search on
// calls to this function (not supported to be called from outside core)
// clarify that the only key ever pass in the ids array is 'contact'
// There is legacy handling for other keys but a universe search on
// calls to this function (not supported to be called from outside core)
$ids = ['contact' => $ids['contact']];
// Likewise neither place ever passed in relationshipID
$relationshipId = NULL;
$ids = ['contact' => $ids['contact']];
// Likewise neither place ever passed in relationshipID
$relationshipId = NULL;
+ // There is only ever one value passed in from the 2 places above that call
+ // this - by clarifying here like this we can cleanup within this
+ // function without having to do more universe searches.
+ $relatedContactIDs = [key($params['contact_check'])];
if (!$relationshipId) {
// creating a new relationship
if (!$relationshipId) {
// creating a new relationship
- $relationshipIds = [];
- foreach (array_keys($params['contact_check']) as $relatedContactID) {
+ foreach ($relatedContactIDs as $relatedContactID) {
// check if the relationship is valid between contacts.
// step 1: check if the relationship is valid if not valid skip and keep the count
// step 2: check the if two contacts already have a relationship if yes skip and keep the count
// check if the relationship is valid between contacts.
// step 1: check if the relationship is valid if not valid skip and keep the count
// step 2: check the if two contacts already have a relationship if yes skip and keep the count
$contactFields = self::setContactABFromIDs($params, $ids, $relatedContactID);
$errors = self::checkValidRelationship($contactFields, $ids, $relatedContactID);
if ($errors) {
$contactFields = self::setContactABFromIDs($params, $ids, $relatedContactID);
$errors = self::checkValidRelationship($contactFields, $ids, $relatedContactID);
if ($errors) {
- $invalid++;
- continue;
}
//CRM-16978:check duplicate relationship as per case id.
}
//CRM-16978:check duplicate relationship as per case id.
- $duplicate++;
- continue;
}
$singleInstanceParams = array_merge($params, $contactFields);
$relationship = self::add($singleInstanceParams);
}
$singleInstanceParams = array_merge($params, $contactFields);
$relationship = self::add($singleInstanceParams);
- $relationshipIds[] = $relationship->id;
- $relationships[$relationship->id] = $relationship;
- $valid++;
}
// editing the relationship
}
// do not add to recent items for import, CRM-4399
}
// editing the relationship
}
// do not add to recent items for import, CRM-4399
- if (!(!empty($params['skipRecentView']) || $invalid || $duplicate)) {
+ if (!(!empty($params['skipRecentView']))) {
self::addRecent($params, $relationship);
}
self::addRecent($params, $relationship);
}
- return [$valid, $duplicate];