Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
put fix in place to catch no response from CRM
Browse files Browse the repository at this point in the history
Put in for loop so if the CRM doesn't respong to the operation, it tries 10 times and if that fails, return false
  • Loading branch information
adam-godfrey committed Apr 9, 2018
1 parent 6c9b7f6 commit f3ab3c1
Showing 1 changed file with 57 additions and 49 deletions.
106 changes: 57 additions & 49 deletions src/Vtiger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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;
}
}

0 comments on commit f3ab3c1

Please sign in to comment.