Passed
Push — master ( 03ea78...8fc551 )
by Harry
10:08
created

MysqlTableDumper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A dump() 0 18 1
1
<?php
2
/**
3
 * This file is part of graze/sprout.
4
 *
5
 * Copyright © 2018 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/sprout/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/sprout
12
 */
13
14
namespace Graze\Sprout\Db\Mysql;
15
16
use Graze\ParallelProcess\Pool;
17
use Graze\Sprout\Config\ConnectionConfigInterface;
18
use Graze\Sprout\Dump\TableDumperInterface;
19
use Symfony\Component\Process\Process;
20
21
class MysqlTableDumper implements TableDumperInterface
22
{
23
    /** @var ConnectionConfigInterface */
24
    private $connection;
25
    /** @var Pool */
26
    private $pool;
27
28
    /**
29
     * MysqlTableDumper constructor.
30
     *
31
     * @param Pool                      $pool
32
     * @param ConnectionConfigInterface $connection
33
     */
34
    public function __construct(Pool $pool, ConnectionConfigInterface $connection)
35
    {
36
        $this->connection = $connection;
37
        $this->pool = $pool;
38
    }
39
40
    /**
41
     * @param string $schema
42
     * @param string $table
43
     * @param string $file
44
     */
45
    public function dump(string $schema, string $table, string $file)
0 ignored issues
show
Coding Style introduced by
Unknown type hint "string" found for $schema
Loading history...
Coding Style introduced by
Unknown type hint "string" found for $table
Loading history...
Coding Style introduced by
Unknown type hint "string" found for $file
Loading history...
46
    {
47
        $process = new Process('');
48
        $process->setCommandLine(
49
            sprintf(
50
                'mysqldump -h%1$s -u%2$s -p%3$s --compress --compact --no-create-info' .
51
                ' --extended-insert --hex-blob --quick --complete-insert %4$s %5$s ' .
52
                '| process-mysqldump > %6$s',
53
                escapeshellarg($this->connection->getHost()),
54
                escapeshellarg($this->connection->getUser()),
55
                escapeshellarg($this->connection->getPassword()),
56
                escapeshellarg($schema),
57
                escapeshellarg($table),
58
                escapeshellarg($file)
59
            )
60
        );
61
62
        $this->pool->add($process, ['dump', 'schema' => $schema, 'table' => $table]);
63
    }
64
}
65