1
|
|
|
<?php |
2
|
|
|
namespace App\Controllers\Ajax; |
3
|
|
|
|
4
|
|
|
use App\Models\ConfigModel; |
5
|
|
|
use Core\AjaxController; |
6
|
|
|
use Core\JsonException; |
7
|
|
|
use Core\Traits\StringFunctions; |
8
|
|
|
|
9
|
|
|
class Update extends AjaxController{ |
10
|
|
|
use StringFunctions; |
11
|
|
|
|
12
|
|
|
public function updateConfig() |
13
|
|
|
{ |
14
|
|
|
$this->onlyAdmin(); |
15
|
|
|
if (!$this->container->getRequest()->isPost()) { |
16
|
|
|
throw new JsonException('Call is not post'); |
17
|
|
|
} |
18
|
|
|
$result = array(); |
19
|
|
|
$result['successId'] = []; |
20
|
|
|
$result['errorId'] = []; |
21
|
|
|
$configUpdateJson = $this->container->getRequest()->getData('config-update'); |
22
|
|
|
$configUpdate = json_decode($configUpdateJson); |
23
|
|
|
|
24
|
|
|
$configModel = new ConfigModel($this->container); |
25
|
|
|
|
26
|
|
|
$success = true; |
27
|
|
|
foreach ($configUpdate as $update){ |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
if (!$configModel->updateConfig($update->dbId, $update->value)) { |
31
|
|
|
$success = false; |
32
|
|
|
$result['errorId'][] = $update->id; |
33
|
|
|
}else{ |
34
|
|
|
$result['successId'][] = $update->id; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
$result['success']=$success; |
38
|
|
|
|
39
|
|
|
echo json_encode($result); |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
die(); |
|
|
|
|
43
|
|
|
$configModel = new ConfigModel($this->container); |
|
|
|
|
44
|
|
|
$posts = $this->container->getRequest()->getDataFull(); |
45
|
|
|
|
46
|
|
|
$success = true; |
47
|
|
|
foreach ($posts as $key => $config) { |
48
|
|
|
$configId = $this->removeFromBeginning($key, 'config-'); |
49
|
|
|
if (!$configModel->updateConfig($configId, $config)) { |
50
|
|
|
$success = false; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
if ($success) { |
54
|
|
|
$this->alertBox->setAlert('Configuration updates successfully'); |
55
|
|
|
} else { |
56
|
|
|
$this->alertBox->setAlert('error in configuration update', 'error'); |
57
|
|
|
} |
58
|
|
|
$this->container->getResponse()->redirect('admin/config'); |
59
|
|
|
} |
60
|
|
|
} |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.