From 90addff7eeb0e5f24230d74f2bb042efd72cf421 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 28 Jun 2021 12:37:06 -0400 Subject: [PATCH] APIv4 - Use non-deprecated join syntax internally --- .../Service/Schema/Joinable/CustomGroupJoinable.php | 6 +++--- Civi/Api4/Service/Spec/SpecFormatter.php | 8 ++++---- Civi/Api4/Service/Spec/SpecGatherer.php | 10 +++++----- tests/phpunit/api/v3/ACLPermissionTest.php | 2 +- tests/phpunit/api/v4/Spec/SpecFormatterTest.php | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Civi/Api4/Service/Schema/Joinable/CustomGroupJoinable.php b/Civi/Api4/Service/Schema/Joinable/CustomGroupJoinable.php index 3b764c150d81..4bff31bf69ca 100644 --- a/Civi/Api4/Service/Schema/Joinable/CustomGroupJoinable.php +++ b/Civi/Api4/Service/Schema/Joinable/CustomGroupJoinable.php @@ -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); } diff --git a/Civi/Api4/Service/Spec/SpecFormatter.php b/Civi/Api4/Service/Spec/SpecFormatter.php index ca67cb9db6dc..6eae4b396d4f 100644 --- a/Civi/Api4/Service/Spec/SpecFormatter.php +++ b/Civi/Api4/Service/Spec/SpecFormatter.php @@ -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)) { diff --git a/Civi/Api4/Service/Spec/SpecGatherer.php b/Civi/Api4/Service/Spec/SpecGatherer.php index bfa22bb133b3..f9369d75abc4 100644 --- a/Civi/Api4/Service/Spec/SpecGatherer.php +++ b/Civi/Api4/Service/Spec/SpecGatherer.php @@ -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) { @@ -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) { diff --git a/tests/phpunit/api/v3/ACLPermissionTest.php b/tests/phpunit/api/v3/ACLPermissionTest.php index d9a969993eb2..67877a67b712 100644 --- a/tests/phpunit/api/v3/ACLPermissionTest.php +++ b/tests/phpunit/api/v3/ACLPermissionTest.php @@ -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], diff --git a/tests/phpunit/api/v4/Spec/SpecFormatterTest.php b/tests/phpunit/api/v4/Spec/SpecFormatterTest.php index 30c5bde34637..b6557571cbe8 100644 --- a/tests/phpunit/api/v4/Spec/SpecFormatterTest.php +++ b/tests/phpunit/api/v4/Spec/SpecFormatterTest.php @@ -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,