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
|
|
|
|