Conditions | 4 |
Paths | 4 |
Total Lines | 28 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
18 | public function updateConfig() |
||
19 | { |
||
20 | //security checks |
||
21 | $this->onlyAdmin(); |
||
22 | if (!$this->container->getRequest()->isPost()) { |
||
23 | throw new JsonException('Call is not post'); |
||
24 | } |
||
25 | //prepating our return results |
||
26 | $result = array(); |
||
27 | $result['successId'] = []; |
||
28 | $result['errorId'] = []; |
||
29 | $result['success'] = true; |
||
30 | $configUpdateJson = $this->container->getRequest()->getData('config-update'); |
||
31 | $configUpdate = json_decode($configUpdateJson); |
||
32 | |||
33 | $configModel = new ConfigModel($this->container); |
||
34 | |||
35 | foreach ($configUpdate as $update) { |
||
36 | |||
37 | if (!$configModel->updateConfig($update->dbId, $update->value)) { |
||
38 | $result['success'] = false; |
||
39 | $result['errorId'][] = $update->id; |
||
40 | } else { |
||
41 | $result['successId'][] = $update->id; |
||
42 | } |
||
43 | } |
||
44 | |||
45 | echo json_encode($result); |
||
46 | } |
||
47 | } |