diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-03-26 14:51:33 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-03-28 13:59:22 +0100 |
commit | 65202d2a18aca3b253ce5f3c7c9af17ee6d12e52 (patch) | |
tree | 04453d95db5dc3df386188cd85032052fded6db9 /settings/controller | |
parent | d3752ca1e925c3aed46c13f7ea26c8f540db05e0 (diff) | |
download | nextcloud-server-65202d2a18aca3b253ce5f3c7c9af17ee6d12e52.tar.gz nextcloud-server-65202d2a18aca3b253ce5f3c7c9af17ee6d12e52.zip |
Add check for activated local memcache
Also used the opportunity to refactor it into an AppFramework controller so that we can unit test it.
Fixes https://github.com/owncloud/core/issues/14956
Diffstat (limited to 'settings/controller')
-rw-r--r-- | settings/controller/checksetupcontroller.php | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/settings/controller/checksetupcontroller.php b/settings/controller/checksetupcontroller.php new file mode 100644 index 00000000000..ae3f1b99c52 --- /dev/null +++ b/settings/controller/checksetupcontroller.php @@ -0,0 +1,99 @@ +<?php +/** + * @author Lukas Reschke <lukas@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OC\Settings\Controller; + +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\DataResponse; +use OCP\Http\Client\IClientService; +use OCP\IConfig; +use OCP\IRequest; +use OC_Util; + +/** + * @package OC\Settings\Controller + */ +class CheckSetupController extends Controller { + /** @var IConfig */ + private $config; + /** @var IClientService */ + private $clientService; + /** @var \OC_Util */ + private $util; + + /** + * @param string $AppName + * @param IRequest $request + * @param IConfig $config + * @param IClientService $clientService + * @param \OC_Util $util + */ + public function __construct($AppName, + IRequest $request, + IConfig $config, + IClientService $clientService, + \OC_Util $util) { + parent::__construct($AppName, $request); + $this->config = $config; + $this->clientService = $clientService; + $this->util = $util; + } + + /** + * Checks if the ownCloud server can connect to the internet using HTTPS and HTTP + * @return bool + */ + private function isInternetConnectionWorking() { + if ($this->config->getSystemValue('has_internet_connection', true) === false) { + return false; + } + + try { + $client = $this->clientService->newClient(); + $client->get('https://www.owncloud.org/'); + $client->get('http://www.owncloud.org/'); + return true; + } catch (\Exception $e) { + return false; + } + } + + /** + * Checks whether a local memcache is installed or not + * @return bool + */ + private function isMemcacheConfigured() { + return $this->config->getSystemValue('memcache.local', null) !== null; + } + + /** + * @return DataResponse + */ + public function check() { + return new DataResponse( + [ + 'serverHasInternetConnection' => $this->isInternetConnectionWorking(), + 'dataDirectoryProtected' => $this->util->isHtaccessWorking($this->config), + 'isMemcacheConfigured' => $this->isMemcacheConfigured(), + ] + ); + } +} |