From 26a7b549497fa648e4d7c80822e552242a08b87f 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 --- CRM/Event/Page/UserDashboard.php | 12 ++++++------ .../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 +- .../phpunit/api/v4/Query/PermissionCheckTest.php | 16 ++++++++-------- tests/phpunit/api/v4/Spec/SpecFormatterTest.php | 4 ++-- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/CRM/Event/Page/UserDashboard.php b/CRM/Event/Page/UserDashboard.php index e1c0aa73c2c0..f384ae5de53a 100644 --- a/CRM/Event/Page/UserDashboard.php +++ b/CRM/Event/Page/UserDashboard.php @@ -28,9 +28,9 @@ public function listParticipations() { $event_rows = []; $participants = \Civi\Api4\Participant::get(FALSE) - ->addSelect('id', 'contact_id', 'status_id:name', 'status_id:label', 'event.id', 'event.title', 'event.start_date', 'event.end_date') + ->addSelect('id', 'contact_id', 'status_id:name', 'status_id:label', 'event_id', 'event_id.title', 'event_id.start_date', 'event_id.end_date') ->addWhere('contact_id', '=', $this->_contactId) - ->addOrderBy('event.start_date', 'DESC') + ->addOrderBy('event_id.start_date', 'DESC') ->execute() ->indexBy('id'); @@ -39,10 +39,10 @@ public function listParticipations() { $p['participant_id'] = $p['id']; $p['status'] = $p['status_id:name']; $p['participant_status'] = $p['status_id:label']; - $p['event_id'] = $p['event.id']; - $p['event_title'] = $p['event.title']; - $p['event_start_date'] = $p['event.start_date']; - $p['event_end_date'] = $p['event.end_date']; + $p['event_id'] = $p['event_id']; + $p['event_title'] = $p['event_id.title']; + $p['event_start_date'] = $p['event_id.start_date']; + $p['event_end_date'] = $p['event_id.end_date']; $event_rows[] = $p; } 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/Query/PermissionCheckTest.php b/tests/phpunit/api/v4/Query/PermissionCheckTest.php index 4a6c233c04a0..872113b008c2 100644 --- a/tests/phpunit/api/v4/Query/PermissionCheckTest.php +++ b/tests/phpunit/api/v4/Query/PermissionCheckTest.php @@ -91,13 +91,13 @@ public function testImplicitJoinPermissions() { 0) ->execute()->first(); $participant = Participant::get() - ->addSelect('contact.first_name', 'event.title') - ->addWhere('event.id', '=', $event['id']) + ->addSelect('contact_id.first_name', 'event_id.title') + ->addWhere('event_id.id', '=', $event['id']) ->execute() ->first(); - $this->assertEquals('ABC123 Event', $participant['event.title']); - $this->assertEquals($name, $participant['contact.first_name']); + $this->assertEquals('ABC123 Event', $participant['event_id.title']); + $this->assertEquals($name, $participant['contact_id.first_name']); // Remove access to view events $config->userPermissionClass->permissions = [ @@ -107,14 +107,14 @@ public function testImplicitJoinPermissions() { 'view event participants', ]; $participant = Participant::get() - ->addSelect('contact.first_name') - ->addSelect('event.title') + ->addSelect('contact_id.first_name') + ->addSelect('event_id.title') ->addWhere('id', '=', $contact['participant']['id']) ->execute() ->first(); - $this->assertTrue(empty($participant['event.title'])); - $this->assertEquals($name, $participant['contact.first_name']); + $this->assertTrue(empty($participant['event_id.title'])); + $this->assertEquals($name, $participant['contact_id.first_name']); } 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,