From a057a07f6de984a41de5cc01b2c611b56937e999 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 27 Jun 2021 00:41:00 -0400 Subject: [PATCH] APIv4 - Emit notices about deprecated join aliases --- Civi/Api4/Service/Schema/Joiner.php | 3 +++ Civi/Test/Api3TestTrait.php | 12 +----------- tests/phpunit/api/v4/Entity/ContactJoinTest.php | 17 ----------------- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/Civi/Api4/Service/Schema/Joiner.php b/Civi/Api4/Service/Schema/Joiner.php index e53c8bff51..7836cdad50 100644 --- a/Civi/Api4/Service/Schema/Joiner.php +++ b/Civi/Api4/Service/Schema/Joiner.php @@ -70,6 +70,9 @@ class Joiner { 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); diff --git a/Civi/Test/Api3TestTrait.php b/Civi/Test/Api3TestTrait.php index 8bfd5b36ec..bf5d3d83ef 100644 --- a/Civi/Test/Api3TestTrait.php +++ b/Civi/Test/Api3TestTrait.php @@ -322,7 +322,7 @@ trait Api3TestTrait { $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) { @@ -426,12 +426,6 @@ trait Api3TestTrait { 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']; @@ -598,10 +592,6 @@ trait Api3TestTrait { 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) { diff --git a/tests/phpunit/api/v4/Entity/ContactJoinTest.php b/tests/phpunit/api/v4/Entity/ContactJoinTest.php index 0c92abac54..e185e7f4fd 100644 --- a/tests/phpunit/api/v4/Entity/ContactJoinTest.php +++ b/tests/phpunit/api/v4/Entity/ContactJoinTest.php @@ -46,23 +46,6 @@ class ContactJoinTest extends UnitTestCase { 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']; -- 2.25.1