From e61bcd9741ccce1d7013e3d08255aee7a0276fdf Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 7 Dec 2023 17:00:00 -0500 Subject: [PATCH] Fix is_new sql in MembershipStatus --- .../Spec/Provider/MembershipStatusGetSpecProvider.php | 11 +++++++++-- tests/phpunit/api/v4/Entity/MembershipTest.php | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ext/civi_member/Civi/Api4/Service/Spec/Provider/MembershipStatusGetSpecProvider.php b/ext/civi_member/Civi/Api4/Service/Spec/Provider/MembershipStatusGetSpecProvider.php index 83f52d42fa..666103020d 100644 --- a/ext/civi_member/Civi/Api4/Service/Spec/Provider/MembershipStatusGetSpecProvider.php +++ b/ext/civi_member/Civi/Api4/Service/Spec/Provider/MembershipStatusGetSpecProvider.php @@ -53,13 +53,20 @@ class MembershipStatusGetSpecProvider extends AutoService implements Generic\Spe /** * Determine if the membership status is the status used for new memberships. * - * @param array $id + * @param array $fieldSpec * @param \Civi\Api4\Query\Api4SelectQuery $query * return string + * + * @return string + * @throws \CRM_Core_Exception + * @noinspection PhpUnusedParameterInspection */ public static function isNewMembership(array $fieldSpec, Api4SelectQuery $query): string { $newID = \CRM_Member_BAO_MembershipStatus::getNewMembershipTypeID(); - return "IF ({id} = $newID, 1, 0)"; + if ($newID) { + return "IF ({$fieldSpec['sql_name']} = $newID, 1, 0)"; + } + return '0'; } } diff --git a/tests/phpunit/api/v4/Entity/MembershipTest.php b/tests/phpunit/api/v4/Entity/MembershipTest.php index 48caa0298a..f9f64bfb6a 100644 --- a/tests/phpunit/api/v4/Entity/MembershipTest.php +++ b/tests/phpunit/api/v4/Entity/MembershipTest.php @@ -99,7 +99,8 @@ class MembershipTest extends Api4TestBase implements TransactionalInterface { 'financial_type_id' => 2, 'is_active' => 1, 'sequential' => 1, - 'visibility' => 'Public']); + 'visibility' => 'Public', + ]); $this->createTestEntity('Contact', ['first_name', 'Bob', 'contact_type' => 'Individual'], 1); $this->createTestEntity('Contact', ['first_name', 'Bob too', 'contact_type' => 'Individual'], 2); $this->createTestEntity('Membership', [ @@ -115,9 +116,8 @@ class MembershipTest extends Api4TestBase implements TransactionalInterface { 'status_id:name' => 'Current', ], 2); $memberships = Membership::get()->addSelect('status_id.is_new')->execute(); - $this->assertTrue($memberships[0]['is_new']); - $this->assertFalse($memberships[1]['is_new']); + $this->assertTrue($memberships[0]['status_id.is_new']); + $this->assertFalse($memberships[1]['status_id.is_new']); } - } -- 2.25.1