From 5dd6344629d7287ee52da5cb0fa5decccbd99d4f Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Wed, 7 Dec 2016 09:13:21 +0100 Subject: [PATCH] Delete cached discovery file if settings are changed Signed-off-by: Lukas Reschke --- lib/Controller/SettingsController.php | 30 ++++++++++----------------- lib/WOPI/DiscoveryManager.php | 6 ++++-- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 60d5edc2..b8122658 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -11,45 +11,38 @@ namespace OCA\Richdocuments\Controller; +use OCA\Richdocuments\WOPI\DiscoveryManager; use \OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; +use OCP\Files\IAppData; use \OCP\IRequest; use \OCP\IL10N; - use OCA\Richdocuments\AppConfig; -use OCA\Richdocuments\Filter; class SettingsController extends Controller{ /** @var IL10N */ private $l10n; /** @var AppConfig */ private $appConfig; + /** @var DiscoveryManager */ + private $discoveryManager; /** * @param string $appName * @param IRequest $request * @param IL10N $l10n * @param AppConfig $appConfig - * @param string $userId + * @param DiscoveryManager $discoveryManager */ public function __construct($appName, IRequest $request, IL10N $l10n, AppConfig $appConfig, - $userId) { + DiscoveryManager $discoveryManager) { parent::__construct($appName, $request); $this->l10n = $l10n; $this->appConfig = $appConfig; - } - - /** - * @NoAdminRequired - */ - public function getSupportedMimes(){ - return array( - 'status' => 'success', - 'mimes' => Filter::getAll() - ); + $this->discoveryManager = $discoveryManager; } /** @@ -65,7 +58,7 @@ class SettingsController extends Controller{ $this->appConfig->setAppValue('wopi_url', $wopi_url); $colon = strpos($wopi_url, ':', 0); - if (\OC::$server->getRequest()->getServerProtocol() !== substr($wopi_url, 0, $colon)){ + if ($this->request->getServerProtocol() !== substr($wopi_url, 0, $colon)){ $message = $this->l10n->t('Saved with error: Collabora Online should use the same protocol as the server installation.'); } } @@ -74,13 +67,12 @@ class SettingsController extends Controller{ $this->appConfig->setAppValue('doc_format', $doc_format); } - $richMemCache = \OC::$server->getMemCacheFactory()->create('richdocuments'); - $richMemCache->clear('discovery.xml'); + $this->discoveryManager->refretch(); - $response = array( + $response = [ 'status' => 'success', 'data' => array('message' => (string) $message) - ); + ]; return new JSONResponse($response); } diff --git a/lib/WOPI/DiscoveryManager.php b/lib/WOPI/DiscoveryManager.php index b3d18fed..c3997fe7 100644 --- a/lib/WOPI/DiscoveryManager.php +++ b/lib/WOPI/DiscoveryManager.php @@ -61,7 +61,6 @@ class DiscoveryManager { $this->appData = $appData->newFolder('richdocuments'); } $this->config = $config; - $this->l10n = $l10n; $this->timeFactory = $timeFactory; } @@ -74,7 +73,6 @@ class DiscoveryManager { return $decodedFile['data']; } } catch (NotFoundException $e) { - $file = $this->appData->newFile('discovery.xml'); } $remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url'); @@ -96,4 +94,8 @@ class DiscoveryManager { ); return $responseBody; } + + public function refretch() { + $this->appData->getFile('discovery.xml')->delete(); + } }