From 20b8a0df468fdfe5cfb95120e1b7baf6f26d0ea7 Mon Sep 17 00:00:00 2001 From: Clyde Cox Date: Tue, 2 Oct 2018 16:22:46 -0400 Subject: [PATCH 1/2] Update to support offsets in search() Vtiger does not support the offset keyword in it's queries. It instead supports limit [offset],[limit]. So the search() function has been modified to rewrite the query to the proper format for Vtiger so that the offset functions properly when sending a query to Vtiger. Also, my php-fs-fixer added commas to the end of some of the arrays automatically, sorry about that. --- src/Vtiger.php | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/src/Vtiger.php b/src/Vtiger.php index b623f0e..ce19fbe 100644 --- a/src/Vtiger.php +++ b/src/Vtiger.php @@ -59,7 +59,7 @@ public function __construct() 2 => new VtigerErrorElement('Success property not set on VTiger response', 2), 3 => new VtigerErrorElement('Error property not set on VTiger response when success is false', 3), 4 => new VtigerErrorElement('There are no search fields in the array', 4), - 5 => new VtigerErrorElement('Could not complete login request within ' . $this->maxRetries . ' tries', 5), + 5 => new VtigerErrorElement('Could not complete login request within ' . $this->maxRetries . ' tries', 5), 6 => new VtigerErrorElement( 'Could not complete get token request within ' . $this->maxRetries . ' tries', 6 @@ -153,8 +153,8 @@ protected function login($sessionData) 'form_params' => [ 'operation' => 'login', 'username' => $this->username, - 'accessKey' => $generatedKey - ] + 'accessKey' => $generatedKey, + ], ]); } catch (GuzzleException $e) { throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage()); @@ -231,8 +231,8 @@ protected function getToken() $response = $this->guzzleClient->request('GET', $this->url, [ 'query' => [ 'operation' => 'getchallenge', - 'username' => $this->username - ] + 'username' => $this->username, + ], ]); } catch (GuzzleException $e) { throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage()); @@ -279,8 +279,8 @@ protected function close($sessionId) [ 'query' => [ 'operation' => 'logout', - 'sessionName' => $sessionId - ] + 'sessionName' => $sessionId, + ], ] ); } catch (GuzzleException $e) { @@ -308,8 +308,8 @@ public function query($query) 'query' => [ 'operation' => 'query', 'sessionName' => $sessionId, - 'query' => $query - ] + 'query' => $query, + ], ]); } catch (GuzzleException $e) { throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage()); @@ -332,6 +332,18 @@ public function search($query, $quote = true) $queryString = preg_replace('/\?/', $binding, $queryString, 1); } } + + //In the event there is a offset, append it to the front of the limit + //Vtiger does not support the offset keyword + $matchOffset = []; + $matchLimit = []; + if (preg_match('/(\s[o][f][f][s][e][t]) (\d*)/', $queryString, $matchOffset) && preg_match('/(\s[l][i][m][i][t]) (\d*)/', $queryString, $matchLimit)) { + $queryString = preg_replace('/(\s[o][f][f][s][e][t]) (\d*)/', '', $queryString); + $queryString = preg_replace('/(\s[l][i][m][i][t]) (\d*)/', '', $queryString); + $queryString = $queryString . ' limit ' . $matchOffset[2] . ',' . $matchLimit[2]; + } + + //Remove the backticks and add simicolon $queryString = str_replace('`', '', $queryString) . ';'; return $this->query($queryString); @@ -356,8 +368,8 @@ public function retrieve($id) 'query' => [ 'operation' => 'retrieve', 'sessionName' => $sessionId, - 'id' => $id - ] + 'id' => $id, + ], ]); } catch (GuzzleException $e) { throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage()); @@ -398,8 +410,8 @@ public function create($elem, $data) 'operation' => 'create', 'sessionName' => $sessionId, 'element' => $data, - 'elementType' => $elem - ] + 'elementType' => $elem, + ], ]); } catch (GuzzleException $e) { throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage()); @@ -431,7 +443,7 @@ public function update($object) 'operation' => 'update', 'sessionName' => $sessionId, 'element' => json_encode($object), - ] + ], ]); } catch (GuzzleException $e) { throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage()); @@ -461,8 +473,8 @@ public function delete($id) 'query' => [ 'operation' => 'delete', 'sessionName' => $sessionId, - 'id' => $id - ] + 'id' => $id, + ], ]); } catch (GuzzleException $e) { throw VtigerError::init($this->vTigerErrors, 7, $e->getMessage()); @@ -494,8 +506,8 @@ public function describe($elementType) 'query' => [ 'operation' => 'describe', 'sessionName' => $sessionId, - 'elementType' => $elementType - ] + 'elementType' => $elementType, + ], ] ); } catch (GuzzleException $e) { @@ -572,7 +584,7 @@ protected function _checkResponseStatusCode($response) * @param \stdClass $processedData * * @throws VtigerError - */ + */i protected function _processResponseError($processedData) { if (!isset($processedData->error)) { From 640d34d0b17cca1ccc59154618fc65e2695eeeb8 Mon Sep 17 00:00:00 2001 From: Clyde Cox Date: Tue, 13 Nov 2018 15:21:12 -0500 Subject: [PATCH 2/2] Update Vtiger.php Remove extra i --- src/Vtiger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Vtiger.php b/src/Vtiger.php index ce19fbe..905673d 100644 --- a/src/Vtiger.php +++ b/src/Vtiger.php @@ -584,7 +584,7 @@ protected function _checkResponseStatusCode($response) * @param \stdClass $processedData * * @throws VtigerError - */i + */ protected function _processResponseError($processedData) { if (!isset($processedData->error)) {