Skip to content

Commit

Permalink
APIv4 - Emit notices about deprecated join aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Jun 27, 2021
1 parent 2b145b8 commit 0408d32
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Civi/Api4/Service/Schema/Joiner.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public function autoJoin(Api4SelectQuery $query, array $joinPath, $side = 'LEFT'
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);
Expand Down
17 changes: 0 additions & 17 deletions tests/phpunit/api/v4/Entity/ContactJoinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,6 @@ public function setUpHeadless() {
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'];
Expand Down

0 comments on commit 0408d32

Please sign in to comment.