for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Rudolf\Modules\Tools\Admin\One\DatabaseImport;
use Rudolf\Component\Alerts\Alert;
use Rudolf\Component\Alerts\AlertsCollection;
use Rudolf\Framework\Controller\AdminController;
class Controller extends AdminController
{
/**
* @throws \Exception
*/
public function show()
if (isset($_POST['upload'])) {
$error = 0;
$file = $_FILES['sqlfile'];
/** @var array $_FILES */
if ($file['error'] !== UPLOAD_ERR_OK
|| !is_uploaded_file($file['tmp_name'])) {
$error = 1;
AlertsCollection::add(new Alert(
'error',
'Uszkodzony plik.',
ALERT::MODE_IMMEDIATELY
));
} elseif ('application/sql' !== $file['type']) {
'Nieprawidłowy plik. Tylko .sql.',
}
if (0 === $error) {
$model = new Model();
$model->clear();
$queries = $model->import(file_get_contents($file['tmp_name']));
if ($queries) {
'success',
'Poprawnie zaimportowano ' . $file['name'].'! Wykonano '.$queries.' zapytań.'
$this->redirectTo(DIR.'/admin/tools/db-import');
} else {
'Nastąpił błąd podczas importu!',
$view = new View();
$view->setData($data = []);
$view->render();