MysqlTableDumper::dump()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 3
dl 0
loc 18
ccs 12
cts 12
cp 1
crap 1
rs 9.8333
c 0
b 0
f 0
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 3
    public function __construct(Pool $pool, ConnectionConfigInterface $connection)
35
    {
36 3
        $this->connection = $connection;
37 3
        $this->pool = $pool;
38 3
    }
39
40
    /**
41
     * @param string $schema
42
     * @param string $table
43
     * @param string $file
44
     */
45 1
    public function dump(string $schema, string $table, string $file)
46
    {
47 1
        $process = new Process('');
48 1
        $process->setCommandLine(
49 1
            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 1
                '| process-mysqldump > %6$s',
53 1
                escapeshellarg($this->connection->getHost()),
54 1
                escapeshellarg($this->connection->getUser()),
55 1
                escapeshellarg($this->connection->getPassword()),
56 1
                escapeshellarg($schema),
57 1
                escapeshellarg($table),
58 1
                escapeshellarg($file)
59
            )
60
        );
61
62 1
        $this->pool->add($process, ['dump', 'schema' => $schema, 'table' => $table]);
63 1
    }
64
}
65