Passed
Pull Request — dev (#47)
by Stone
04:18 queued 02:10
created

Update   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A updateConfig() 0 24 5
1
<?php
2
3
namespace App\Controllers\Admin;
4
5
use App\Models\ConfigModel;
6
use Core\AdminController;
7
use Core\Traits\StringFunctions;
8
9
10
class Update extends AdminController
11
{
12
13
    use StringFunctions;
14
15
    /**
16
     * gets the information in post and sets the corresponding site config details
17
     * this is pure php with no ajax
18
     * @throws \Exception
19
     */
20
    public function updateConfig()
21
    {
22
        //Security checks
23
        $this->onlyAdmin();
24
        if (!$this->container->getRequest()->isPost()) {
25
            $this->alertBox->setAlert('Only post messages allowed', 'error');
26
            $this->container->getResponse()->redirect('admin');
27
        }
28
29
        $configModel = new ConfigModel($this->container);
30
        $posts = $this->container->getRequest()->getDataFull();
31
        $success = true;
32
33
        foreach ($posts as $key => $config) {
34
            if (!$configModel->updateConfig($key, $config)) {
35
                $success = false;
36
            }
37
        }
38
        if ($success) {
39
            $this->alertBox->setAlert('Configuration updates successfully');
40
        } else {
41
            $this->alertBox->setAlert('error in configuration update', 'error');
42
        }
43
        $this->container->getResponse()->redirect('admin/config');
44
    }
45
}