From 9c635e259f77d3aa4d50af035f7ba691edf14ae8 Mon Sep 17 00:00:00 2001 From: Christopher Pratt Date: Fri, 15 Jun 2018 12:59:10 +0000 Subject: [PATCH] Added some extra bits to the gitignore to do with composer and fixed a problem with the processing of the request data stripping the orginal request varible --- .gitignore | 4 +++- src/Vtiger.php | 16 +++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 723ef36..8925195 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -.idea \ No newline at end of file +.idea +vendor +composer.lock \ No newline at end of file diff --git a/src/Vtiger.php b/src/Vtiger.php index d7c546e..5025115 100644 --- a/src/Vtiger.php +++ b/src/Vtiger.php @@ -130,6 +130,7 @@ protected function login($sessionData) $tryCounter = 1; do { // login using username and accesskey + /** @var ResponseInterface $response */ $response = $this->client->request('POST', $this->url, [ 'form_params' => [ 'operation' => 'login', @@ -138,6 +139,8 @@ protected function login($sessionData) ] ]); + /** @var ResponseInterface $unprocessedResponse */ + $unprocessedResponse = $response; // decode the response $loginResult = json_decode($response->getBody()->getContents()); $tryCounter++; @@ -148,7 +151,7 @@ protected function login($sessionData) } // If api login failed - if ($response->getStatusCode() !== 200 || !$loginResult->success) { + if ($unprocessedResponse->getStatusCode() !== 200 || !$loginResult->success) { if (!$loginResult->success) { if ($loginResult->error->code == "INVALID_USER_CREDENTIALS" || $loginResult->error->code == "INVALID_SESSIONID") { if ($this->sessionDriver == 'file') { @@ -159,10 +162,10 @@ protected function login($sessionData) Redis::del('clystnet_vtiger'); } } else { - $this->_processResult($response); + $this->_processResult($unprocessedResponse); } } else { - $this->_checkResponseStatusCode($response); + $this->_checkResponseStatusCode($unprocessedResponse); } } else { // login ok so get sessionid and update our session @@ -233,7 +236,10 @@ protected function getToken() 'username' => $this->username ] ]); + + $unprocessedResponse = $response; $processedResponse = json_decode($response->getBody()->getContents()); + $tryCounter++; } while (!isset($processedResponse->success) && $tryCounter <= $this->maxRetries); if ($tryCounter >= $this->maxRetries) { @@ -241,7 +247,7 @@ protected function getToken() } // decode the response - $challenge = $this->_processResult($response); + $challenge = $this->_processResult($unprocessedResponse); // Everything ok so create a token from response $output = array( @@ -516,7 +522,7 @@ protected function _checkResponseStatusCode($response) { if ($response->getStatusCode() !== 200) { - throw new VtigerError("API request did not complete correctley - Response code: ".$response->getStatusCode(), 1); + throw new VtigerError("API request did not complete correctly - Response code: ".$response->getStatusCode(), 1); } }