Only send the necessary data when registering a site

Merge in the rest of the metadata when fetching ct cache
HFP-489
pull/38/head
thomasmars 2017-03-18 15:39:27 +01:00
parent 4098f7a0d9
commit 3611da5921
1 changed files with 26 additions and 18 deletions

View File

@ -2432,33 +2432,21 @@ class H5PCore {
// Gather data // Gather data
$uuid = $this->h5pF->getOption('site_uuid', ''); $uuid = $this->h5pF->getOption('site_uuid', '');
$platform = $this->h5pF->getPlatformInfo(); $platform = $this->h5pF->getPlatformInfo();
$data = array( $registrationData = array(
'api_version' => 2,
'uuid' => $uuid, 'uuid' => $uuid,
'platform_name' => $platform['name'], 'platform_name' => $platform['name'],
'platform_version' => $platform['version'], 'platform_version' => $platform['version'],
'h5p_version' => $platform['h5pVersion'], 'h5p_version' => $platform['h5pVersion'],
'disabled' => $fetchingDisabled ? 1 : 0, 'disabled' => $fetchingDisabled ? 1 : 0,
'local_id' => hash('crc32', $this->fullPluginPath), 'local_id' => hash('crc32', $this->fullPluginPath),
'type' => $this->h5pF->getOption('site_type', 'local'), 'type' => $this->h5pF->getOption('site_type', 'local')
'num_authors' => $this->h5pF->getNumAuthors(),
'libraries' => json_encode($this->combineArrayValues(array(
'patch' => $this->getLibrariesInstalled(),
'content' => $this->h5pF->getLibraryContentCount(),
'loaded' => $this->h5pF->getLibraryStats('library'),
'created' => $this->h5pF->getLibraryStats('content create'),
'createdUpload' => $this->h5pF->getLibraryStats('content create upload'),
'deleted' => $this->h5pF->getLibraryStats('content delete'),
'resultViews' => $this->h5pF->getLibraryStats('results content'),
'shortcodeInserts' => $this->h5pF->getLibraryStats('content shortcode insert')
)))
); );
// Register site if it is not registered // Register site if it is not registered
if (empty($uuid)) { if (empty($uuid)) {
$protocol = (extension_loaded('openssl') ? 'https' : 'http'); $protocol = (extension_loaded('openssl') ? 'https' : 'http');
$endpoint = 'api.h5p.org/v1/sites'; $endpoint = 'api.h5p.org/v1/sites';
$registration = $this->h5pF->fetchExternalData("{$protocol}://{$endpoint}", $data); $registration = $this->h5pF->fetchExternalData("{$protocol}://{$endpoint}", $registrationData);
// Failed retrieving uuid // Failed retrieving uuid
if (!$registration) { if (!$registration) {
@ -2476,7 +2464,7 @@ class H5PCore {
// Successfully retrieved new uuid // Successfully retrieved new uuid
$json = json_decode($registration); $json = json_decode($registration);
$data['uuid'] = $json->uuid; $registrationData['uuid'] = $json->uuid;
$this->h5pF->setOption('site_uuid', $json->uuid); $this->h5pF->setOption('site_uuid', $json->uuid);
$this->h5pF->setInfoMessage( $this->h5pF->setInfoMessage(
$this->h5pF->t('Your site was successfully registered with the H5P Hub.') $this->h5pF->t('Your site was successfully registered with the H5P Hub.')
@ -2486,7 +2474,25 @@ class H5PCore {
); );
} }
$result = $this->updateContentTypeCache($data); $siteData = array_merge(
$registrationData,
array(
'api_version' => 2,
'num_authors' => $this->h5pF->getNumAuthors(),
'libraries' => json_encode($this->combineArrayValues(array(
'patch' => $this->getLibrariesInstalled(),
'content' => $this->h5pF->getLibraryContentCount(),
'loaded' => $this->h5pF->getLibraryStats('library'),
'created' => $this->h5pF->getLibraryStats('content create'),
'createdUpload' => $this->h5pF->getLibraryStats('content create upload'),
'deleted' => $this->h5pF->getLibraryStats('content delete'),
'resultViews' => $this->h5pF->getLibraryStats('results content'),
'shortcodeInserts' => $this->h5pF->getLibraryStats('content shortcode insert')
)))
)
);
$result = $this->updateContentTypeCache($siteData);
// No data received // No data received
if (!$result || empty($result)) { if (!$result || empty($result)) {
@ -2507,6 +2513,8 @@ class H5PCore {
$this->h5pF->setOption('update_available', $result->packageReleased->releasedAt); $this->h5pF->setOption('update_available', $result->packageReleased->releasedAt);
$this->h5pF->setOption('update_available_path', $result->packageReleased->path); $this->h5pF->setOption('update_available_path', $result->packageReleased->path);
} }
return $result;
} }
/** /**
@ -2828,7 +2836,7 @@ class H5PCore {
$interface = $this->h5pF; $interface = $this->h5pF;
// Set uuid // Set uuid
if (!$postData) { if (!$postData || !isset($postData['uuid'])) {
$site_uuid = $this->h5pF->getOption('site_uuid', ''); $site_uuid = $this->h5pF->getOption('site_uuid', '');
// Register site with site uuid if we don't already have it // Register site with site uuid if we don't already have it