private function fetch($action, $params) { ksort($params); // sort params so cache is reused more often even if param order is different $releaseChannel = $this->environment->getReleaseChannel(); if (!empty($releaseChannel)) { $params['release_channel'] = $releaseChannel; } $params['prefer_stable'] = (int) $this->environment->doesPreferStable(); $params['piwik'] = $this->environment->getPiwikVersion(); $params['php'] = $this->environment->getPhpVersion(); $params['mysql'] = $this->environment->getMySQLVersion(); $params['num_users'] = $this->environment->getNumUsers(); $params['num_websites'] = $this->environment->getNumWebsites(); $query = http_build_query($params); $cacheId = $this->getCacheKey($action, $query); $result = $this->cache->fetch($cacheId); if ($result !== false) { return $result; } try { $result = $this->service->fetch($action, $params); } catch (Service\Exception $e) { throw new Exception($e->getMessage(), $e->getCode()); } $this->cache->save($cacheId, $result, self::CACHE_TIMEOUT_IN_SECONDS); return $result; }
/** * Saves the given license key in case the key is actually valid (exists on the Piwik Marketplace and is not * yet expired). * * @param string $licenseKey * @return bool * * @throws Exception In case of an invalid license key * @throws Service\Exception In case of any network problems */ public function saveLicenseKey($licenseKey) { Piwik::checkUserHasSuperUserAccess(); $licenseKey = trim($licenseKey); // we are currently using the Marketplace service directly to 1) change LicenseKey and 2) not use any cache $this->marketplaceService->authenticate($licenseKey); try { $consumer = $this->marketplaceService->fetch('consumer/validate', array()); } catch (Api\Service\Exception $e) { if ($e->getCode() === Api\Service\Exception::HTTP_ERROR) { throw $e; } $consumer = array(); } if (empty($consumer['isValid'])) { throw new Exception(Piwik::translate('Marketplace_ExceptionLinceseKeyIsNotValid')); } $this->setLicenseKey($licenseKey); return true; }