Conditions | 7 |
Paths | 10 |
Total Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
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 |