Skip to content

Commit

Permalink
APIv4 - Use non-deprecated join syntax internally
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Jun 28, 2021
1 parent c0f9cc6 commit 90addff
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Civi/Api4/Service/Schema/Joinable/CustomGroupJoinable.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public function getEntityFields() {
$entityFields = (array) \Civi::cache('metadata')->get($cacheKey);
if (!$entityFields) {
$fields = CustomField::get(FALSE)
->setSelect(['custom_group.name', 'custom_group.extends', 'custom_group.table_name', 'custom_group.title', '*'])
->addWhere('custom_group.table_name', '=', $this->getTargetTable())
->setSelect(['custom_group_id.name', 'custom_group_id.extends', 'custom_group_id.table_name', 'custom_group_id.title', '*'])
->addWhere('custom_group_id.table_name', '=', $this->getTargetTable())
->execute();
foreach ($fields as $field) {
$entityFields[] = \Civi\Api4\Service\Spec\SpecFormatter::arrayToField($field, self::getEntityFromExtends($field['custom_group.extends']));
$entityFields[] = \Civi\Api4\Service\Spec\SpecFormatter::arrayToField($field, self::getEntityFromExtends($field['custom_group_id.extends']));
}
\Civi::cache('metadata')->set($cacheKey, $entityFields);
}
Expand Down
8 changes: 4 additions & 4 deletions Civi/Api4/Service/Spec/SpecFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ public static function arrayToField(array $data, $entity) {
if (!empty($data['custom_group_id'])) {
$field = new CustomFieldSpec($data['name'], $entity, $dataTypeName);
if (strpos($entity, 'Custom_') !== 0) {
$field->setName($data['custom_group.name'] . '.' . $data['name']);
$field->setName($data['custom_group_id.name'] . '.' . $data['name']);
}
else {
$field->setTableName($data['custom_group.table_name']);
$field->setTableName($data['custom_group_id.table_name']);
}
$field->setColumnName($data['column_name']);
$field->setCustomFieldId($data['id'] ?? NULL);
$field->setCustomGroupName($data['custom_group.name']);
$field->setCustomGroupName($data['custom_group_id.name']);
$field->setTitle($data['label']);
$field->setLabel($data['custom_group.title'] . ': ' . $data['label']);
$field->setLabel($data['custom_group_id.title'] . ': ' . $data['label']);
$field->setHelpPre($data['help_pre'] ?? NULL);
$field->setHelpPost($data['help_post'] ?? NULL);
if (self::customFieldHasOptions($data)) {
Expand Down
10 changes: 5 additions & 5 deletions Civi/Api4/Service/Spec/SpecGatherer.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ private function addCustomFields($entity, RequestSpec $specification, $values =
$extends = $customInfo['extends'];
}
$customFields = CustomField::get(FALSE)
->addWhere('custom_group.extends', 'IN', $extends)
->addWhere('custom_group.is_multiple', '=', '0')
->setSelect(['custom_group.name', 'custom_group.title', '*'])
->addWhere('custom_group_id.extends', 'IN', $extends)
->addWhere('custom_group_id.is_multiple', '=', '0')
->setSelect(['custom_group_id.name', 'custom_group_id.title', '*'])
->execute();

foreach ($customFields as $fieldArray) {
Expand All @@ -145,8 +145,8 @@ private function addCustomFields($entity, RequestSpec $specification, $values =
*/
private function getCustomGroupFields($customGroup, RequestSpec $specification) {
$customFields = CustomField::get(FALSE)
->addWhere('custom_group.name', '=', $customGroup)
->setSelect(['custom_group.name', 'custom_group.table_name', 'custom_group.title', '*'])
->addWhere('custom_group_id.name', '=', $customGroup)
->setSelect(['custom_group_id.name', 'custom_group_id.table_name', 'custom_group_id.title', '*'])
->execute();

foreach ($customFields as $fieldArray) {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ACLPermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ public function testContactGetViaJoin($version) {
$tag2 = $this->tagCreate(['name' => uniqid('other'), 'created_id' => $other])['id'];
$this->setPermissions(['access CiviCRM']);
$this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereHookAllResults']);
$createdFirstName = $version === 4 ? 'created.first_name' : 'created_id.first_name';
$createdFirstName = 'created_id.first_name';
$result = $this->callAPISuccess('Tag', 'get', [
'check_permissions' => 1,
'return' => ['id', $createdFirstName],
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/api/v4/Spec/SpecFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public function testCustomFieldWillBeReturned() {

$data = [
'custom_group_id' => $customGroupId,
'custom_group.name' => 'my_group',
'custom_group.title' => 'My Group',
'custom_group_id.name' => 'my_group',
'custom_group_id.title' => 'My Group',
'id' => $customFieldId,
'name' => $name,
'label' => $name,
Expand Down

0 comments on commit 90addff

Please sign in to comment.