Controller   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 54
rs 10
wmc 7
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B show() 0 48 7
1
<?php
2
3
namespace Rudolf\Modules\Tools\Admin\One\DatabaseImport;
4
5
use Rudolf\Component\Alerts\Alert;
6
use Rudolf\Component\Alerts\AlertsCollection;
7
use Rudolf\Framework\Controller\AdminController;
8
9
class Controller extends AdminController
10
{
11
    /**
12
     * @throws \Exception
13
     */
14
    public function show()
15
    {
16
        if (isset($_POST['upload'])) {
17
            $error = 0;
18
            $file = $_FILES['sqlfile'];
19
20
            /** @var array $_FILES */
21
            if ($file['error'] !== UPLOAD_ERR_OK
22
                || !is_uploaded_file($file['tmp_name'])) {
23
                $error = 1;
24
                AlertsCollection::add(new Alert(
25
                    'error',
26
                    'Uszkodzony plik.',
27
                    ALERT::MODE_IMMEDIATELY
28
                ));
29
            } elseif ('application/sql' !== $file['type']) {
30
                $error = 1;
31
                AlertsCollection::add(new Alert(
32
                    'error',
33
                    'Nieprawidłowy plik. Tylko .sql.',
34
                    ALERT::MODE_IMMEDIATELY
35
                ));
36
            }
37
38
            if (0 === $error) {
39
                $model = new Model();
40
                $model->clear();
41
                $queries = $model->import(file_get_contents($file['tmp_name']));
42
                if ($queries) {
43
                    AlertsCollection::add(new Alert(
44
                        'success',
45
                        'Poprawnie zaimportowano ' . $file['name'].'! Wykonano '.$queries.' zapytań.'
46
                    ));
47
                    $this->redirectTo(DIR.'/admin/tools/db-import');
48
                } else {
49
                    AlertsCollection::add(new Alert(
50
                        'error',
51
                        'Nastąpił błąd podczas importu!',
52
                        ALERT::MODE_IMMEDIATELY
53
                    ));
54
                }
55
            }
56
        }
57
58
        $view = new View();
59
        $view->setData($data = []);
60
        $view->render();
61
    }
62
}
63