OCA\Richdocuments\Controller\DocumentController::getDiscovery PHP Method

getDiscovery() private method

Return the content of discovery.xml - either from cache, or download it.
private getDiscovery ( )
    private function getDiscovery()
    {
        \OC::$server->getLogger()->debug('getDiscovery(): Getting discovery.xml from the cache.');
        $wopiRemote = $this->appConfig->getAppValue('wopi_url');
        // Provides access to information about the capabilities of a WOPI client
        // and the mechanisms for invoking those abilities through URIs.
        $wopiDiscovery = $wopiRemote . '/hosting/discovery';
        // Read the memcached value (if the memcache is installed)
        $discovery = $this->cache->get('discovery.xml');
        if (is_null($discovery)) {
            $contact_admin = $this->l10n->t('Please contact the "%s" administrator.', array($wopiRemote));
            try {
                $wopiClient = \OC::$server->getHTTPClientService()->newClient();
                $discovery = $wopiClient->get($wopiDiscovery)->getBody();
            } catch (\Exception $e) {
                $error_message = $e->getMessage();
                if (preg_match('/^cURL error ([0-9]*):/', $error_message, $matches)) {
                    $admin_check = $this->l10n->t('Please ask your administrator to check the Collabora Online server setting. The exact error message was: ') . $error_message;
                    $curl_error = $matches[1];
                    switch ($curl_error) {
                        case '1':
                            throw new ResponseException($this->l10n->t('Collabora Online: The protocol specified in "%s" is not allowed.', array($wopiRemote)), $admin_check);
                        case '3':
                            throw new ResponseException($this->l10n->t('Collabora Online: Malformed URL "%s".', array($wopiRemote)), $admin_check);
                        case '6':
                            throw new ResponseException($this->l10n->t('Collabora Online: Cannot resolve the host "%s".', array($wopiRemote)), $admin_check);
                        case '7':
                            throw new ResponseException($this->l10n->t('Collabora Online: Cannot connect to the host "%s".', array($wopiRemote)), $admin_check);
                        case '60':
                            throw new ResponseException($this->l10n->t('Collabora Online: SSL certificate is not installed.'), $this->l10n->t('Please ask your administrator to add ca-chain.cert.pem to the ca-bundle.crt, for example "cat /etc/loolwsd/ca-chain.cert.pem >> <server-installation>/resources/config/ca-bundle.crt" . The exact error message was: ') . $error_message);
                    }
                }
                throw new ResponseException($this->l10n->t('Collabora Online unknown error: ') . $error_message, $contact_admin);
            }
            if (!$discovery) {
                throw new ResponseException($this->l10n->t('Collabora Online: Unable to read discovery.xml from "%s".', array($wopiRemote)), $contact_admin);
            }
            \OC::$server->getLogger()->debug('Storing the discovery.xml to the cache.');
            $this->cache->set('discovery.xml', $discovery, 3600);
        }
        return $discovery;
    }