Issues (59)

src/Driver/Facades/ImportFacade.php (1 issue)

Severity
1
<?php
2
3
namespace Lagdo\DbAdmin\Db\Driver\Facades;
4
5
use Jaxon\Request\Upload\FileInterface;
6
7
use function array_map;
8
use function extension_loaded;
9
use function implode;
10
use function ini_get;
11
12
/**
13
 * Facade to import functions
14
 */
15
class ImportFacade extends CommandFacade
16
{
17
    /**
18
     * Get data for import
19
     *
20
     * @return array
21
     */
22
    public function getImportOptions(): array
23
    {
24
        // From sql.inc.php
25
        $gz = extension_loaded('zlib') ? '[.gz]' : '';
26
        // ignore post_max_size because it is for all form fields
27
        // together and bytes computing would be necessary.
28
        $contents = $this->utils->iniBool('file_uploads') ?
29
            ['upload' => "SQL$gz (&lt; " . ini_get('upload_max_filesize') . 'B)'] :
30
            ['upload_disabled' => $this->utils->trans->lang('File uploads are disabled.')];
31
        if (($importServerPath = $this->page->importServerPath())) {
32
            $contents['path'] = $this->utils->str->html($importServerPath) . $gz;
33
        }
34
35
        return ['contents' => $contents];
36
    }
37
38
    /**
39
     * From the get_file() function in functions.inc.php
40
     *
41
     * @param FileInterface $file
42
     * @param bool $decompress
43
     *
44
     * @return string
45
     */
46
    protected function readFile(FileInterface $file, bool $decompress = false): string
0 ignored issues
show
The parameter $decompress is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
    protected function readFile(FileInterface $file, /** @scrutinizer ignore-unused */ bool $decompress = false): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
        // $compressed = preg_match('~\.gz$~', $file->path());
49
        // if (!$decompress || !$compressed) {
50
            //! may not be reachable because of open_basedir
51
        // }
52
53
        return $file->filesystem()->read($file->path());
54
    }
55
56
    /**
57
     * Run queries from uploaded files
58
     *
59
     * @param array<FileInterface>  $files         The uploaded files
60
     * @param bool   $errorStops    Stop executing the requests in case of error
61
     * @param bool   $onlyErrors    Return only errors
62
     *
63
     * @return array
64
     */
65
    public function executeSqlFiles(array $files, bool $errorStops, bool $onlyErrors): array
66
    {
67
        $queries = array_map(fn($file) => $this->readFile($file), $files);
68
        $queries = implode("\n\n", $queries);
69
        return $this->executeCommands($queries, 0, $errorStops, $onlyErrors);
70
    }
71
}
72