From f3ab3c134fcd019c747ab8add8949935262eb27d Mon Sep 17 00:00:00 2001 From: "DESKTOP-9DOKON5\\Adam" Date: Mon, 9 Apr 2018 11:06:49 +0100 Subject: [PATCH] put fix in place to catch no response from CRM Put in for loop so if the CRM doesn't respong to the operation, it tries 10 times and if that fails, return false --- src/Vtiger.php | 106 ++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 49 deletions(-) diff --git a/src/Vtiger.php b/src/Vtiger.php index ccf9839..05d5a8c 100644 --- a/src/Vtiger.php +++ b/src/Vtiger.php @@ -131,21 +131,23 @@ public function query($query) return $sessionid->message; } - // send a request using a database query to get back any user with the email from the form POST request - $response = $this->client->request('GET', $this->url, [ - 'query' => [ - 'operation' => 'query', - 'sessionName' => $sessionid, - 'query' => $query - ] - ]); - - // decode the response - $data = json_decode($response->getBody()->getContents()); + for($i = 0; (!isset($data->success) && $i < 10); $i++) { + // send a request using a database query to get back any user with the email from the form POST request + $response = $this->client->request('GET', $this->url, [ + 'query' => [ + 'operation' => 'query', + 'sessionName' => $sessionid, + 'query' => $query + ] + ]); + + // decode the response + $data = json_decode($response->getBody()->getContents()); + } self::close($sessionid); - return $data; + return (isset($data->success)) ? $data : false; } public function retrieve($id) @@ -156,21 +158,23 @@ public function retrieve($id) return $sessionid->message; } - // send a request using a database query to get back any user with the email from the form POST request - $response = $this->client->request('GET', $this->url, [ - 'query' => [ - 'operation' => 'retrieve', - 'sessionName' => $sessionid, - 'id' => $id - ] - ]); - - // decode the response - $data = json_decode($response->getBody()->getContents()); + for($i = 0; (!isset($data->success) && $i < 10); $i++) { + // send a request using a database query to get back any user with the email from the form POST request + $response = $this->client->request('GET', $this->url, [ + 'query' => [ + 'operation' => 'retrieve', + 'sessionName' => $sessionid, + 'id' => $id + ] + ]); + + // decode the response + $data = json_decode($response->getBody()->getContents()); + } self::close($sessionid); - return $data; + return (isset($data->success)) ? $data : false; } public function create($elem, $data) @@ -181,22 +185,24 @@ public function create($elem, $data) return $sessionid->message; } - // send a request using a database query to get back any user with the email from the form POST request - $response = $this->client->request('POST', $this->url, [ - 'form_params' => [ - 'operation' => 'create', - 'sessionName' => $sessionid, - 'element' => $data, - 'elementType' => $elem - ] - ]); - - // decode the response - $data = json_decode($response->getBody()->getContents()); + for($i = 0; (!isset($data->success) && $i < 10); $i++) { + // send a request using a database query to get back any user with the email from the form POST request + $response = $this->client->request('POST', $this->url, [ + 'form_params' => [ + 'operation' => 'create', + 'sessionName' => $sessionid, + 'element' => $data, + 'elementType' => $elem + ] + ]); + + // decode the response + $data = json_decode($response->getBody()->getContents()); + } self::close($sessionid); - return $data; + return (isset($data->success)) ? $data : false; } public function update($object) @@ -207,20 +213,22 @@ public function update($object) return $sessionid->message; } - // send a request using a database query to get back any user with the email from the form POST request - $response = $this->client->request('POST', $this->url, [ - 'form_params' => [ - 'operation' => 'update', - 'sessionName' => $sessionid, - 'element' => json_encode($object), - ] - ]); - - // decode the response - $data = json_decode($response->getBody()->getContents()); + for($i = 0; (!isset($data->success) && $i < 10); $i++) { + // send a request using a database query to get back any user with the email from the form POST request + $response = $this->client->request('POST', $this->url, [ + 'form_params' => [ + 'operation' => 'update', + 'sessionName' => $sessionid, + 'element' => json_encode($object), + ] + ]); + + // decode the response + $data = json_decode($response->getBody()->getContents()); + } self::close($sessionid); - return $data; + return (isset($data->success)) ? $data : false; } } \ No newline at end of file