Merge branch 'content-hub' of github.com:h5p/h5p-php-library into content-hub

content-hub
Thomas Marstrander 2020-09-03 15:02:50 +02:00
commit 645058f03e
No known key found for this signature in database
GPG Key ID: 59D7F1EC8B90E9A6
2 changed files with 14 additions and 7 deletions

View File

@ -3728,11 +3728,11 @@ class H5PCore {
H5PHubEndpoints::createURL(H5PHubEndpoints::CONTENT . "/{$id}"),
NULL, TRUE, NULL, TRUE, $headers
);
if (empty($response['data'])) {
throw new Exception($this->h5pF->t('Unable to authorize with the H5P Hub. Please check your Hub registration and connection.'));
}
$hub_content = json_decode($response['data'])->data;
$hub_content->id = "$hub_content->id";
return $hub_content;
@ -3743,16 +3743,23 @@ class H5PCore {
*
* @param array $data Data from content publishing process
* @param array $files Files to upload with the content publish
* @param bigint $content_hub_id For updating existing content
* @return stdClass
*/
public function hubPublishContent($data, $files) {
public function hubPublishContent($data, $files, $content_hub_id = NULL) {
$headers = array(
'Authorization' => $this->hubGetAuthorizationHeader(),
'Accept' => 'application/json',
);
$endpoint = H5PHubEndpoints::CONTENT;
if ($content_hub_id !== NULL) {
$endpoint .= "/{$content_hub_id}";
$data['_method'] = 'PUT';
}
$response = $this->h5pF->fetchExternalData(
H5PHubEndpoints::createURL(H5PHubEndpoints::CONTENT),
H5PHubEndpoints::createURL($endpoint),
$data, TRUE, NULL, TRUE, $headers, $files
);

File diff suppressed because one or more lines are too long