Fix errors introduced by the guzzle 6 update fixes #362
This commit is contained in:
parent
9adf934e32
commit
ab490bd156
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\BadResponseException;
|
use GuzzleHttp\Exception\BadResponseException;
|
||||||
use GuzzleHttp\Exception\ParseException;
|
|
||||||
|
|
||||||
class Api
|
class Api
|
||||||
{
|
{
|
||||||
@ -32,9 +31,7 @@ class Api
|
|||||||
{
|
{
|
||||||
$options = [
|
$options = [
|
||||||
'base_uri' => $this->base_url . 'rest/api/',
|
'base_uri' => $this->base_url . 'rest/api/',
|
||||||
'defaults' => [
|
'auth' => [$this->user, $this->pass]
|
||||||
'auth' => [$this->user, $this->pass]
|
|
||||||
]
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return new Client($options);
|
return new Client($options);
|
||||||
@ -63,15 +60,13 @@ class Api
|
|||||||
}
|
}
|
||||||
|
|
||||||
$message = $label .
|
$message = $label .
|
||||||
' [url] ' . $request->getUrl() .
|
' [url] ' . $request->getUri() .
|
||||||
' [status code] ' . $response->getStatusCode() .
|
' [status code] ' . $response->getStatusCode() .
|
||||||
' [message] ';
|
' [message] ';
|
||||||
|
|
||||||
try {
|
$body = $response->getBody();
|
||||||
$message .= $response->json()['message'];
|
$json = json_decode($body, true);
|
||||||
} catch (ParseException $e) {
|
$message .= ($json != null && array_key_exists('message', $json)) ? $json['message'] : $body;
|
||||||
$message .= (string) $response->getBody();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($level == '4' && strpos($message, "page with this title already exists") !== false) {
|
if ($level == '4' && strpos($message, "page with this title already exists") !== false) {
|
||||||
return new DuplicateTitleException($message, 0, $e->getPrevious());
|
return new DuplicateTitleException($message, 0, $e->getPrevious());
|
||||||
@ -85,7 +80,7 @@ class Api
|
|||||||
$url = "content/$id?expand=ancestors,version,body.storage";
|
$url = "content/$id?expand=ancestors,version,body.storage";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = $this->getClient()->get($url)->json();
|
$result = json_decode($this->getClient()->get($url)->getBody(), true);
|
||||||
} catch (BadResponseException $e) {
|
} catch (BadResponseException $e) {
|
||||||
throw $this->handleError($e);
|
throw $this->handleError($e);
|
||||||
}
|
}
|
||||||
@ -126,7 +121,7 @@ class Api
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
$hierarchy = $this->getClient()->get($url)->json();
|
$hierarchy = json_decode($this->getClient()->get($url)->getBody(), true);
|
||||||
} catch (BadResponseException $e) {
|
} catch (BadResponseException $e) {
|
||||||
throw $this->handleError($e);
|
throw $this->handleError($e);
|
||||||
}
|
}
|
||||||
@ -175,7 +170,7 @@ class Api
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->getClient()->post('content', ['json' => $body])->json();
|
$response = json_decode($this->getClient()->post('content', ['json' => $body])->getBody(), true);
|
||||||
} catch (BadResponseException $e) {
|
} catch (BadResponseException $e) {
|
||||||
throw $this->handleError($e);
|
throw $this->handleError($e);
|
||||||
}
|
}
|
||||||
@ -205,7 +200,7 @@ class Api
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->getClient()->put("content/$page_id", ['json' => $body])->json();
|
$this->getClient()->put("content/$page_id", ['json' => $body]);
|
||||||
} catch (BadResponseException $e) {
|
} catch (BadResponseException $e) {
|
||||||
throw $this->handleError($e);
|
throw $this->handleError($e);
|
||||||
}
|
}
|
||||||
@ -220,7 +215,7 @@ class Api
|
|||||||
public function deletePage($page_id)
|
public function deletePage($page_id)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->getClient()->delete('content/' . $page_id)->json();
|
return json_decode($this->getClient()->delete('content/' . $page_id)->getBody(), true);
|
||||||
} catch (BadResponseException $e) {
|
} catch (BadResponseException $e) {
|
||||||
throw $this->handleError($e);
|
throw $this->handleError($e);
|
||||||
}
|
}
|
||||||
@ -235,7 +230,7 @@ class Api
|
|||||||
// Check if an attachment with
|
// Check if an attachment with
|
||||||
// this name is uploaded
|
// this name is uploaded
|
||||||
try {
|
try {
|
||||||
$result = $this->getClient()->get("content/$id/child/attachment?filename=$attachment[filename]")->json();
|
$result = json_decode($this->getClient()->get("content/$id/child/attachment?filename=$attachment[filename]")->getBody(), true);
|
||||||
} catch (BadResponseException $e) {
|
} catch (BadResponseException $e) {
|
||||||
throw $this->handleError($e);
|
throw $this->handleError($e);
|
||||||
}
|
}
|
||||||
@ -252,7 +247,7 @@ class Api
|
|||||||
$this->getClient()->post(
|
$this->getClient()->post(
|
||||||
$url,
|
$url,
|
||||||
[
|
[
|
||||||
'body' => ['file' => fopen($attachment['file']->getPath(), 'r')],
|
'multipart' => [['name' => 'file', 'contents' => fopen($attachment['file']->getPath(), 'r')]],
|
||||||
'headers' => ['X-Atlassian-Token' => 'nocheck'],
|
'headers' => ['X-Atlassian-Token' => 'nocheck'],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user