diff --git a/CRM/Civiquickbooks/Contact.php b/CRM/Civiquickbooks/Contact.php index f903cc5..43c9e77 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; @@ -222,7 +226,7 @@ public function push($params) { // 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'] ]),