Separate statistics reporting from 'Use H5P Hub' option

JI-114
pull/10/merge
Frode Petterson 2017-04-10 14:09:02 +02:00
parent c4f2b26116
commit c475db843d
1 changed files with 27 additions and 18 deletions

View File

@ -2476,22 +2476,27 @@ class H5PCore {
); );
} }
$siteData = array_merge( if ($this->h5pF->getOption('h5p_send_usage_statistics', TRUE)) {
$registrationData, $siteData = array_merge(
array( $registrationData,
'num_authors' => $this->h5pF->getNumAuthors(), array(
'libraries' => json_encode($this->combineArrayValues(array( 'num_authors' => $this->h5pF->getNumAuthors(),
'patch' => $this->getLibrariesInstalled(), 'libraries' => json_encode($this->combineArrayValues(array(
'content' => $this->h5pF->getLibraryContentCount(), 'patch' => $this->getLibrariesInstalled(),
'loaded' => $this->h5pF->getLibraryStats('library'), 'content' => $this->h5pF->getLibraryContentCount(),
'created' => $this->h5pF->getLibraryStats('content create'), 'loaded' => $this->h5pF->getLibraryStats('library'),
'createdUpload' => $this->h5pF->getLibraryStats('content create upload'), 'created' => $this->h5pF->getLibraryStats('content create'),
'deleted' => $this->h5pF->getLibraryStats('content delete'), 'createdUpload' => $this->h5pF->getLibraryStats('content create upload'),
'resultViews' => $this->h5pF->getLibraryStats('results content'), 'deleted' => $this->h5pF->getLibraryStats('content delete'),
'shortcodeInserts' => $this->h5pF->getLibraryStats('content shortcode insert') 'resultViews' => $this->h5pF->getLibraryStats('results content'),
))) 'shortcodeInserts' => $this->h5pF->getLibraryStats('content shortcode insert')
) )))
); )
);
}
else {
$siteData = $registrationData;
}
$result = $this->updateContentTypeCache($siteData); $result = $this->updateContentTypeCache($siteData);
@ -2851,10 +2856,14 @@ class H5PCore {
$endpoint = H5PHubEndpoints::CONTENT_TYPES; $endpoint = H5PHubEndpoints::CONTENT_TYPES;
$data = $interface->fetchExternalData("{$protocol}://{$endpoint}", $postData); $data = $interface->fetchExternalData("{$protocol}://{$endpoint}", $postData);
if (! $this->h5pF->getOption('h5p_hub_is_enabled', TRUE)) {
return TRUE;
}
// No data received // No data received
if (!$data) { if (!$data) {
$interface->setErrorMessage( $interface->setErrorMessage(
$interface->t('Could not connect to the H5P Content Type Hub. Please try again later.') $interface->t("Couldn't communicate with the H5P Hub. Please try again later.")
); );
return FALSE; return FALSE;
} }
@ -2864,7 +2873,7 @@ class H5PCore {
// No libraries received // No libraries received
if (!isset($json->contentTypes) || empty($json->contentTypes)) { if (!isset($json->contentTypes) || empty($json->contentTypes)) {
$interface->setErrorMessage( $interface->setErrorMessage(
$interface->t('No libraries was received from the Content Type Hub. Please try again later.') $interface->t('No content types were received from the H5P Hub. Please try again later.')
); );
return FALSE; return FALSE;
} }