if ($joinEntity && !$query->checkEntityAccess($joinEntity)) {
throw new UnauthorizedException('Cannot join to ' . $joinEntity);
}
+ if ($link->isDeprecated()) {
+ \CRM_Core_Error::deprecatedWarning("Deprecated join alias '$alias' used in APIv4 get. Should be changed to '{$alias}_id'");
+ }
$bao = $joinEntity ? CoreUtil::getBAOFromApiName($joinEntity) : NULL;
$conditions = $link->getConditionsForJoin($baseTableAlias);
$v4Params['language'] = $language;
}
$toRemove = ['option.', 'return', 'api.', 'format.'];
- $chains = $joins = $custom = [];
+ $chains = $custom = [];
foreach ($v3Params as $key => $val) {
foreach ($toRemove as $remove) {
if (strpos($key, $remove) === 0) {
if ($v4Entity != 'Setting' && !in_array('id', $v4Params['select'])) {
$v4Params['select'][] = 'id';
}
- // Convert join syntax
- foreach ($v4Params['select'] as $idx => $select) {
- if (strstr($select, '_id.')) {
- $joins[$select] = $v4Params['select'][$idx] = str_replace('_id.', '.', $select);
- }
- }
}
if ($options['limit'] && $v4Entity != 'Setting') {
$v4Params['limit'] = $options['limit'];
foreach ($chains as $key => $params) {
$result[$index][$key] = $this->runApi4LegacyChain($key, $params, $v4Entity, $row, $sequential);
}
- // Convert join format
- foreach ($joins as $api3Key => $api4Key) {
- $result[$index][$api3Key] = $result[$index][$api4Key] ?? NULL;
- }
// Resolve custom field names
foreach ($custom as $group => $fields) {
foreach ($fields as $field => $v3FieldName) {
return parent::setUpHeadless();
}
- public function testContactJoinDeprecated() {
- $contact = $this->getReference('test_contact_1');
- $entitiesToTest = ['Address', 'OpenID', 'IM', 'Website', 'Email', 'Phone'];
-
- foreach ($entitiesToTest as $entity) {
- $results = civicrm_api4($entity, 'get', [
- 'where' => [['contact_id', '=', $contact['id']]],
- // Deprecated syntax (new syntax is `contact_id.*` not `contact.*`)
- 'select' => ['contact.*_name', 'contact.id'],
- ]);
- foreach ($results as $result) {
- $this->assertEquals($contact['id'], $result['contact.id']);
- $this->assertEquals($contact['display_name'], $result['contact.display_name']);
- }
- }
- }
-
public function testContactJoin() {
$contact = $this->getReference('test_contact_1');
$entitiesToTest = ['Address', 'OpenID', 'IM', 'Website', 'Email', 'Phone'];