Completed
Push — master ( 88a935...aa89c9 )
by Lukas
04:24 queued 01:12
created

SettingsController::getSettings()   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 \OCP\AppFramework\Controller;
15
use OCP\AppFramework\Http\JSONResponse;
16
use \OCP\IRequest;
17
use \OCP\IL10N;
18
19
use OCA\Richdocuments\AppConfig;
20
use OCA\Richdocuments\Filter;
21
22
class SettingsController extends Controller{
23
	/** @var IL10N */
24
	private $l10n;
25
	/** @var AppConfig */
26
	private $appConfig;
27
28
	/**
29
	 * @param string $appName
30
	 * @param IRequest $request
31
	 * @param IL10N $l10n
32
	 * @param AppConfig $appConfig
33
	 * @param string $userId
34
	 */
35
	public function __construct($appName,
36
								IRequest $request,
37
								IL10N $l10n,
38
								AppConfig $appConfig,
39
								$userId) {
40
		parent::__construct($appName, $request);
41
		$this->l10n = $l10n;
42
		$this->appConfig = $appConfig;
43
	}
44
45
	/**
46
	 * @NoAdminRequired
47
	 */
48
	public function getSupportedMimes(){
49
		return array(
50
			'status' => 'success',
51
			'mimes' => Filter::getAll()
52
		);
53
	}
54
55
	/**
56
	 * @param string $wopi_url
57
	 * @param string $doc_format
58
	 * @return JSONResponse
59
	 */
60
	public function setSettings($wopi_url,
61
								$doc_format){
62
		$message = $this->l10n->t('Saved');
63
64
		if ($wopi_url !== null){
65
			$this->appConfig->setAppValue('wopi_url', $wopi_url);
66
67
			$colon = strpos($wopi_url, ':', 0);
68
			if (\OC::$server->getRequest()->getServerProtocol() !== substr($wopi_url, 0, $colon)){
69
				$message = $this->l10n->t('Saved with error: Collabora Online should use the same protocol as the server installation.');
70
			}
71
		}
72
73
		if ($doc_format !== null) {
74
			$this->appConfig->setAppValue('doc_format', $doc_format);
75
		}
76
77
		$richMemCache = \OC::$server->getMemCacheFactory()->create('richdocuments');
78
		$richMemCache->clear('discovery.xml');
79
80
		$response = array(
81
			'status' => 'success',
82
			'data' => array('message' => (string) $message)
83
		);
84
85
		return new JSONResponse($response);
86
	}
87
}
88