fetchUrl = $config_factory->get('update.settings')->get('fetch.url'); $this->httpClient = $http_client; $this->updateSettings = $config_factory->get('update.settings'); $this->withHttpFallback = $settings->get('update_fetch_with_http_fallback', FALSE); } /** * {@inheritdoc} */ public function fetchProjectData(array $project, $site_key = '') { $url = $this->buildFetchUrl($project, $site_key); return $this->doRequest($url, ['headers' => ['Accept' => 'text/xml']], $this->withHttpFallback); } /** * Applies a GET request with a possible HTTP fallback. * * This method falls back to HTTP in case there was some certificate * problem. * * @param string $url * The URL. * @param array $options * The guzzle client options. * @param bool $with_http_fallback * Should the function fall back to HTTP. * * @return string * The body of the HTTP(S) request, or an empty string on failure. */ protected function doRequest(string $url, array $options, bool $with_http_fallback): string { $data = ''; try { $data = (string) $this->httpClient ->get($url, ['headers' => ['Accept' => 'text/xml']]) ->getBody(); } catch (ClientExceptionInterface $exception) { Error::logException($this->logger, $exception); if ($with_http_fallback && !str_contains($url, "http://")) { $url = str_replace('https://', 'http://', $url); return $this->doRequest($url, $options, FALSE); } } return $data; } /** * {@inheritdoc} */ public function buildFetchUrl(array $project, $site_key = '') { $name = $project['name']; $url = $this->getFetchBaseUrl($project); $url .= '/' . $name . '/current'; // Only append usage information if we have a site key and the project is // installed. We do not want to record usage statistics for uninstalled // projects. if (!empty($site_key) && !str_contains($project['project_type'], 'disabled')) { // Append the site key. $url .= str_contains($url, '?') ? '&' : '?'; $url .= 'site_key='; $url .= rawurlencode($site_key); // Append the version. if (!empty($project['info']['version'])) { $url .= '&version='; $url .= rawurlencode($project['info']['version']); } // Append the list of modules or themes installed. $list = array_keys($project['includes']); $url .= '&list='; $url .= rawurlencode(implode(',', $list)); } return $url; } /** * {@inheritdoc} */ public function getFetchBaseUrl($project) { if (isset($project['info']['project status url'])) { $url = $project['info']['project status url']; } else { $url = $this->fetchUrl; if (empty($url)) { $url = static::UPDATE_DEFAULT_URL; } } return $url; } }