1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OCA\Chat\Controller; |
4
|
|
|
|
5
|
|
|
use \OCA\Chat\Db\ConfigMapper; |
6
|
|
|
use \OCA\Chat\IBackendManager; |
7
|
|
|
use \OCP\AppFramework\Controller; |
8
|
|
|
use \OCP\AppFramework\Http\JSONResponse; |
9
|
|
|
use \OCP\AppFramework\Http; |
10
|
|
|
use \OCP\IRequest; |
11
|
|
|
use \OCA\Chat\BackendNotFoundException; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class ConfigController extends Controller { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var \OCA\Chat\Db\ConfigMapper |
18
|
|
|
*/ |
19
|
|
|
private $configMapper; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \OCA\Chat\BackendManager |
23
|
|
|
*/ |
24
|
|
|
private $backendManager; |
25
|
|
|
|
26
|
|
|
public function __construct($appName, IRequest $request, ConfigMapper $configMapper, IBackendManager $backendManager){ |
27
|
|
|
parent::__construct($appName, $request); |
28
|
|
|
$this->configMapper = $configMapper; |
29
|
|
|
$this->backendManager = $backendManager; |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @NoAdminRequired |
34
|
|
|
* @param $backends |
35
|
|
|
* @return JSONResponse |
36
|
|
|
*/ |
37
|
|
|
public function set($backends){ |
38
|
|
|
foreach($backends as $backend){ |
39
|
|
|
foreach($backend['config'] as $key=>$value){ |
40
|
|
|
$this->configMapper->set($backend['id'], $key, $value); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
$res = new JSONResponse(); |
44
|
|
|
$res->setStatus(Http::STATUS_OK); |
45
|
|
|
return $res; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $id |
50
|
|
|
* @return JSONResponse |
51
|
|
|
*/ |
52
|
|
|
public function enableBackend($id){ |
53
|
|
|
try { |
54
|
|
|
$this->backendManager->enableBackend($id); |
55
|
|
|
return new JSONResponse(array("status" => "success")); |
56
|
|
|
} Catch (BackendNotFoundException $e) { |
57
|
|
|
return new JSONResponse(array("status" => "error", "msg" => 404)); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param $id |
63
|
|
|
* @return JSONResponse |
64
|
|
|
*/ |
65
|
|
|
public function disableBackend($id){ |
66
|
|
|
try { |
67
|
|
|
$this->backendManager->disableBackend($id); |
68
|
|
|
return new JSONResponse(array("status" => "success")); |
69
|
|
|
} Catch (BackendNotFoundException $e) { |
70
|
|
|
return new JSONResponse(array("status" => "error", "msg" => 404)); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.