Skip to content

Commit ec3f1e2

Browse files
Added mysqldump '--hex-blob' option
1 parent 6c2c7d7 commit ec3f1e2

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

doc/config/source/mysqldump.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<option name="showStdErr" value="true" />
55

66
<!-- optional, default=localhost -->
7-
<option name="host" value="myhost" />
7+
<option name="host" value="myHost" />
88

99
<!-- optional, default=system user -->
1010
<option name="user" value="myUserName" />
@@ -29,4 +29,7 @@
2929

3030
<!-- optional, default=false -->
3131
<option name="compress" value="true" />
32+
33+
<!-- optional, default=false -->
34+
<option name="hexBlob" value="true" />
3235
</source>

src/Backup/Source/Mysqldump.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ class Mysqldump extends Cli implements Source
106106
*/
107107
private $compress;
108108

109+
/**
110+
* Dump blob fields as hex.
111+
* --hex-blob
112+
*
113+
* @var boolean
114+
*/
115+
private $hexBlob;
116+
109117
/**
110118
* Dump only table structures
111119
* --no-data
@@ -136,6 +144,7 @@ public function setup(array $conf = array())
136144
$this->user = Util\Arr::getValue($conf, 'user');
137145
$this->password = Util\Arr::getValue($conf, 'password');
138146
$this->showStdErr = Util\Str::toBoolean(Util\Arr::getValue($conf, 'showStdErr', ''), false);
147+
$this->hexBlob = Util\Str::toBoolean(Util\Arr::getValue($conf, 'hexBlob', ''), false);
139148
$this->quick = Util\Str::toBoolean(Util\Arr::getValue($conf, 'quick', ''), false);
140149
$this->compress = Util\Str::toBoolean(Util\Arr::getValue($conf, 'compress', ''), false);
141150
$this->noData = Util\Str::toBoolean(Util\Arr::getValue($conf, 'noData', ''), false);
@@ -191,6 +200,7 @@ public function getExecutable(Target $target)
191200
$this->executable->credentials($this->user, $this->password)
192201
->useHost($this->host)
193202
->useQuickMode($this->quick)
203+
->dumpBlobsHexadecimal($this->hexBlob)
194204
->useCompression($this->compress)
195205
->dumpTables($this->tables)
196206
->dumpDatabases($this->databases)

src/Cli/Executable/Mysqldump.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class Mysqldump extends Abstraction implements Executable
9898

9999
/**
100100
* Dump blob fields as hex.
101+
* --hex-blob
101102
*
102103
* @var boolean
103104
*/
@@ -171,6 +172,18 @@ public function useCompression($bool)
171172
return $this;
172173
}
173174

175+
/**
176+
* Use '--hex-blob' to encode binary fields.
177+
*
178+
* @param boolean $bool
179+
* @return \phpbu\App\Cli\Executable\Mysqldump
180+
*/
181+
public function dumpBlobsHexadecimal($bool)
182+
{
183+
$this->hexBlob = $bool;
184+
return $this;
185+
}
186+
174187
/**
175188
* Set tables to dump.
176189
*

tests/phpbu/Backup/Source/MysqldumpTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ public function testDefault()
5353
$this->assertEquals($path . '/mysqldump --all-databases 2> /dev/null', $cmd);
5454
}
5555

56+
/**
57+
* Tests Mysqldump::getExecutable
58+
*/
59+
public function testHexBlob()
60+
{
61+
$target = $this->getTargetMock();
62+
$path = realpath(__DIR__ . '/../../../_files/bin');
63+
$this->mysqldump->setup(array('pathToMysqldump' => $path, 'hexBlob' => 'true'));
64+
65+
$executable = $this->mysqldump->getExecutable($target);
66+
$cmd = $executable->getCommandLine();
67+
68+
$this->assertEquals($path . '/mysqldump --hex-blob --all-databases 2> /dev/null', $cmd);
69+
}
70+
5671
/**
5772
* Tests Mysqldump::backup
5873
*/

tests/phpbu/Cli/Executable/MysqldumpTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ public function testDefault()
2626
$this->assertEquals($path . '/mysqldump --all-databases 2> /dev/null', $cmd);
2727
}
2828

29+
/**
30+
* Tests Mysqldump::dumpBlobsHexadecimal
31+
*/
32+
public function testHexBlob()
33+
{
34+
$path = realpath(__DIR__ . '/../../../_files/bin');
35+
$mysqldump = new Mysqldump($path);
36+
$mysqldump->dumpBlobsHexadecimal(true);
37+
$cmd = $mysqldump->getCommandLine();
38+
39+
$this->assertEquals($path . '/mysqldump --hex-blob --all-databases 2> /dev/null', $cmd);
40+
}
41+
2942
/**
3043
* Tests Mysqldump::getCommandLine
3144
*/

0 commit comments

Comments
 (0)