Completed
Push — master ( addcdd...ca9298 )
by Lukas
02:21
created

SettingsController::getSupportedMimes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * ownCloud - Richdocuments App
4
 *
5
 * @author Victor Dubiniuk
6
 * @copyright 2014 Victor Dubiniuk [email protected]
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later.
10
 */
11
12
namespace OCA\Richdocuments\Controller;
13
14
use OCA\Richdocuments\WOPI\DiscoveryManager;
15
use \OCP\AppFramework\Controller;
16
use OCP\AppFramework\Http\JSONResponse;
17
use OCP\Files\IAppData;
18
use \OCP\IRequest;
19
use \OCP\IL10N;
20
use OCA\Richdocuments\AppConfig;
21
22
class SettingsController extends Controller{
23
	/** @var IL10N */
24
	private $l10n;
25
	/** @var AppConfig */
26
	private $appConfig;
27
	/** @var DiscoveryManager  */
28
	private $discoveryManager;
29
30
	/**
31
	 * @param string $appName
32
	 * @param IRequest $request
33
	 * @param IL10N $l10n
34
	 * @param AppConfig $appConfig
35
	 * @param DiscoveryManager $discoveryManager
36
	 */
37
	public function __construct($appName,
38
								IRequest $request,
39
								IL10N $l10n,
40
								AppConfig $appConfig,
41
								DiscoveryManager $discoveryManager) {
42
		parent::__construct($appName, $request);
43
		$this->l10n = $l10n;
44
		$this->appConfig = $appConfig;
45
		$this->discoveryManager = $discoveryManager;
46
	}
47
48
	/**
49
	 * @param string $wopi_url
50
	 * @param string $doc_format
51
	 * @return JSONResponse
52
	 */
53
	public function setSettings($wopi_url,
54
								$doc_format){
55
		$message = $this->l10n->t('Saved');
56
57
		if ($wopi_url !== null){
58
			$this->appConfig->setAppValue('wopi_url', $wopi_url);
59
60
			$colon = strpos($wopi_url, ':', 0);
61
			if ($this->request->getServerProtocol() !== substr($wopi_url, 0, $colon)){
62
				$message = $this->l10n->t('Saved with error: Collabora Online should use the same protocol as the server installation.');
63
			}
64
		}
65
66
		if ($doc_format !== null) {
67
			$this->appConfig->setAppValue('doc_format', $doc_format);
68
		}
69
70
		$this->discoveryManager->refretch();
71
72
		$response = [
73
			'status' => 'success',
74
			'data' => array('message' => (string) $message)
75
		];
76
77
		return new JSONResponse($response);
78
	}
79
}
80