Fix cleanup after reverting revert

content-hub
Frode Petterson 2020-11-04 10:42:52 +01:00
parent aa5abe786e
commit 160b86e9ae
1 changed files with 0 additions and 157 deletions

View File

@ -4108,163 +4108,6 @@ class H5PCore {
return false; return false;
} }
/**
* Publish content on the H5P Hub.
*
* @param array $data Data from content publishing process
* @param array $files Files to upload with the content publish
* @return stdClass
*/
public function hubPublishContent($data, $files) {
$headers = array(
'Authorization' => $this->hubGetAuthorizationHeader(),
'Accept' => 'application/json',
);
$response = $this->h5pF->fetchExternalData(
H5PHubEndpoints::createURL(H5PHubEndpoints::CONTENT),
$data, TRUE, NULL, TRUE, $headers, $files
);
if (empty($response['data'])) {
throw new Exception($this->h5pF->t('Unable to authorize with the H5P Hub. Please check your Hub registration and connection.'));
}
$result = json_decode($response['data']);
if (isset($result->success) && $result->success === TRUE) {
return $result;
}
elseif (!empty($result->errors)) {
// Relay any error messages
$e = new Exception($this->h5pF->t('Validation failed.'));
$e->errors = $result->errors;
throw $e;
}
}
/**
* Creates the authorization header needed to access the private parts of
* the H5P Hub.
*
* @return string
*/
public function hubGetAuthorizationHeader() {
$site_uuid = $this->h5pF->getOption('site_uuid', '');
$hub_secret = $this->h5pF->getOption('hub_secret', '');
if (empty($site_uuid)) {
throw new Exception($this->h5pF->t('Missing Site UUID. Please check your Hub registration.'));
}
if (empty($hub_secret)) {
throw new Exception($this->h5pF->t('Missing Hub Secret. Please check your Hub registration.'));
}
return 'Basic ' . base64_encode("$site_uuid:$hub_secret");
}
/**
* Unpublish content from content hub
*
* @param integer $hubId Content hub id
* @param string $token CSRF token
*
* @return bool True if successful
*/
public function hubUnpublishContent($hubId, $token) {
if (!self::validToken('content_hub_token', $token)) {
$msg = $this->h5pF->t('Could not unpublish content because token was invalid. Please try again.');
$this->h5pF->setErrorMessage($msg);
return false;
}
$headers = array(
'Authorization' => $this->hubGetAuthorizationHeader(),
'Accept' => 'application/json',
);
$url = H5PHubEndpoints::createURL(H5PHubEndpoints::CONTENT);
$response = $this->h5pF->fetchExternalData("{$url}/{$hubId}", array(
'published' => '0',
), true, null, true, $headers, array(), 'PUT');
// Remove shared status if successful
if (!empty($response) && $response['status'] === 200) {
$msg = $this->h5pF->t('Content successfully unpublished');
$this->h5pF->setInfoMessage($msg);
return true;
}
$msg = $this->h5pF->t('Content unpublish failed');
$this->h5pF->setErrorMessage($msg);
return false;
}
/**
* Sync content with content hub
*
* @param integer $hubId Content hub id
* @param string $token CSRF token
* @param string $exportPath Export path where .h5p for content can be found
*
* @return bool
*/
public function hubSyncContent($hubId, $token, $exportPath) {
if (!self::validToken('content_hub_token', $token)) {
$msg = $this->h5pF->t('Could not sync content because token was invalid. Please try again.');
$this->h5pF->setErrorMessage($msg);
return false;
}
$headers = array(
'Authorization' => $this->hubGetAuthorizationHeader(),
'Accept' => 'application/json',
);
$url = H5PHubEndpoints::createURL(H5PHubEndpoints::CONTENT);
$response = $this->h5pF->fetchExternalData("{$url}/{$hubId}", array(
'download_url' => $exportPath,
), true, null, true, $headers, array(), 'PUT');
if (!empty($response) && $response['status'] === 200) {
$msg = $this->h5pF->t('Content sync queued');
$this->h5pF->setInfoMessage($msg);
return true;
}
$msg = $this->h5pF->t('Content sync failed');
$this->h5pF->setErrorMessage($msg);
return false;
}
/**
* Fetch account info for our site from the content hub
*
* @return array|bool|string False if account is not setup, otherwise data
*/
public function hubAccountInfo() {
$siteUuid = $this->h5pF->getOption('site_uuid', null);
$secret = $this->h5pF->getOption('hub_secret', null);
if (empty($siteUuid) || empty($secret)) {
return false;
}
$headers = array(
'Authorization' => $this->hubGetAuthorizationHeader(),
'Accept' => 'application/json',
);
$url = H5PHubEndpoints::createURL(H5PHubEndpoints::REGISTER);
$accountInfo = $this->h5pF->fetchExternalData("{$url}/{$siteUuid}",
null, true, null, true, $headers, array(), 'GET');
if ($accountInfo['status'] !== 200) {
return false;
}
return json_decode($accountInfo['data'])->data;
}
} }
/** /**