From e3ee5cd7968d5b4134e731f6c4a8292c738e0915 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Mon, 16 Oct 2023 17:10:30 +1100 Subject: [PATCH] CIVIQBO-105 fix contact fetching for AccountSync API4 --- CRM/Civiquickbooks/Contact.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/CRM/Civiquickbooks/Contact.php b/CRM/Civiquickbooks/Contact.php index f903cc5..06e6143 100644 --- a/CRM/Civiquickbooks/Contact.php +++ b/CRM/Civiquickbooks/Contact.php @@ -172,7 +172,6 @@ public function pull($params) { */ public function push($params) { $abort_loop = FALSE; - $params['limit'] = $params['limit'] ?? PHP_INT_MAX; try { $accountContacts = AccountContact::get(FALSE) @@ -189,14 +188,19 @@ public function push($params) { // If we specified a CiviCRM contact ID just push that contact. if (!empty($params['contact_id'])) { $accountContacts - ->addWhere('contact_id', '=', $params['contact_id']) - ->addWhere('accounts_needs_update', '=', FALSE); + ->addWhere('contact_id', '=', $params['contact_id']); } else { $accountContacts ->addWhere('contact_id', 'IS NOT NULL') ->addWhere('accounts_needs_update', '=', TRUE); } + + if(!empty($params['limit'])) { + $accountContacts + ->setLimit($params['limit']); + } + $records = $accountContacts->execute()->getArrayCopy(); $errors = []; @@ -209,7 +213,7 @@ public function push($params) { throw new CRM_Core_Exception('Could not get DataService Object: ' . $e->getMessage()); } - foreach (array_slice($records, 0, $params['limit']) as $account_contact) { + foreach ($records as $account_contact) { if($abort_loop) break; @@ -220,9 +224,7 @@ public function push($params) { try { $id = isset($account_contact['accounts_contact_id']) ? $account_contact['accounts_contact_id'] : NULL; - // NOTE if we store the json string in the response directly using Accountsync API, it will serialized it for us automatically. - // And when we get it out using api, it will deserialize automatically for us. - $accounts_data = isset($account_contact['accounts_contact_id']) ? $account_contact['accounts_data'] : NULL; + $accounts_data = isset($account_contact['accounts_data']) ? json_decode($account_contact['accounts_data'], TRUE) : []; $QBOContact = $this->mapToCustomer( civicrm_api3('contact', 'getsingle', [ 'id' => $account_contact['contact_id'] ]),