Merge fetch libraries metadata and update content type cache into one request.
Use fetchExteralData instead of adding new functionality since we're now using post. JI-53pull/38/head
parent
f556cde385
commit
952a07456c
|
@ -569,16 +569,6 @@ interface H5PFrameworkInterface {
|
||||||
*/
|
*/
|
||||||
public function hasPermission($permission, $id = NULL);
|
public function hasPermission($permission, $id = NULL);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get content type cache from an external url.
|
|
||||||
*
|
|
||||||
* @param string $endpoint Endpoint containing content type cache
|
|
||||||
*
|
|
||||||
* @return object Json object with an array called 'libraries' containing
|
|
||||||
* all content types that should be cached
|
|
||||||
*/
|
|
||||||
public function getExternalContentTypeCache($endpoint);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces existing content type cache with the one passed in
|
* Replaces existing content type cache with the one passed in
|
||||||
*
|
*
|
||||||
|
@ -2425,9 +2415,9 @@ class H5PCore {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a list of libraries' metadata from h5p.org.
|
* Communicate with H5P.org and get content type cache. Each platform
|
||||||
* Save URL tutorial to database. Each platform implementation
|
* implementation is responsible for invoking this, eg using cron
|
||||||
* is responsible for invoking this, eg using cron
|
*
|
||||||
* @param bool $fetchingDisabled
|
* @param bool $fetchingDisabled
|
||||||
*/
|
*/
|
||||||
public function fetchLibrariesMetadata($fetchingDisabled = FALSE) {
|
public function fetchLibrariesMetadata($fetchingDisabled = FALSE) {
|
||||||
|
@ -2456,37 +2446,16 @@ class H5PCore {
|
||||||
)))
|
)))
|
||||||
);
|
);
|
||||||
|
|
||||||
// Send request
|
$result = $this->updateContentTypeCache($data);
|
||||||
$protocol = (extension_loaded('openssl') ? 'https' : 'http');
|
|
||||||
$result = $this->h5pF->fetchExternalData("{$protocol}://h5p.org/libraries-metadata.json", $data);
|
|
||||||
if (empty($result)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process results
|
// No data received
|
||||||
$json = json_decode($result);
|
if (!$result || empty($result)) {
|
||||||
if (empty($json)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle libraries metadata
|
|
||||||
if (isset($json->libraries)) {
|
|
||||||
foreach ($json->libraries as $machineName => $libInfo) {
|
|
||||||
if (isset($libInfo->tutorialUrl)) {
|
|
||||||
$this->h5pF->setLibraryTutorialUrl($machineName, $libInfo->tutorialUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle new uuid
|
// Handle new uuid
|
||||||
if ($uuid === '' && isset($json->uuid)) {
|
if ($uuid === '' && isset($result->uuid)) {
|
||||||
$this->h5pF->setOption('site_uuid', $json->uuid);
|
$this->h5pF->setOption('site_uuid', $result->uuid);
|
||||||
}
|
|
||||||
|
|
||||||
// Handle latest version of H5P
|
|
||||||
if (!empty($json->latest)) {
|
|
||||||
$this->h5pF->setOption('update_available', $json->latest->releasedAt);
|
|
||||||
$this->h5pF->setOption('update_available_path', $json->latest->path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2783,14 +2752,21 @@ class H5PCore {
|
||||||
/**
|
/**
|
||||||
* Update content type cache
|
* Update content type cache
|
||||||
*
|
*
|
||||||
* @return bool True if successfully updated
|
* @return bool|object Returns endpoint data if found, otherwise FALSE
|
||||||
*/
|
*/
|
||||||
function updateContentTypeCache() {
|
function updateContentTypeCache($postData) {
|
||||||
// Get content type cache
|
$endpoint = 'http://hubendpoints/contenttypes';
|
||||||
$endpoint = 'http://hubendpoints';
|
|
||||||
|
|
||||||
$interface = $this->h5pF;
|
$interface = $this->h5pF;
|
||||||
$data = $interface->getExternalContentTypeCache($endpoint);
|
|
||||||
|
// Set uuid
|
||||||
|
if (!$postData) {
|
||||||
|
$postData = (object) array(
|
||||||
|
'uuid' => $this->h5pF->getOption('site_uuid', '')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $interface->fetchExternalData($endpoint, $postData);
|
||||||
|
|
||||||
// No data received
|
// No data received
|
||||||
if (!$data) {
|
if (!$data) {
|
||||||
|
@ -2816,7 +2792,7 @@ class H5PCore {
|
||||||
// Inform of the changes and update timestamp
|
// Inform of the changes and update timestamp
|
||||||
$interface->setInfoMessage($interface->t('Library cache was successfully updated!'));
|
$interface->setInfoMessage($interface->t('Library cache was successfully updated!'));
|
||||||
$interface->setOption('content_type_cache_updated_at', $interface->getCurrentUserTime());
|
$interface->setOption('content_type_cache_updated_at', $interface->getCurrentUserTime());
|
||||||
return TRUE;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue