Skip to content

Commit 02e37ca

Browse files
Added '--extended-insert' support to 'Mysqldump'
1 parent 1149fbb commit 02e37ca

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

doc/config/source/mysqldump.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"structureOnly": "myTableWithoutData1,myTableWithoutData2",
1212
"quick": "true",
1313
"compress": "true",
14+
"extendedInsert": "true",
1415
"hexBlob": "true"
1516
}
1617
}

doc/config/source/mysqldump.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<!-- optional, default=false -->
3131
<option name="compress" value="true" />
3232

33+
<!-- optional, default=false -->
34+
<option name="extendedInsert" value="true" />
35+
3336
<!-- optional, default=false -->
3437
<option name="hexBlob" value="true" />
3538
</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+
* Use mysqldump with extended insert
111+
* -e
112+
*
113+
* @var boolean
114+
*/
115+
private $extendedInsert;
116+
109117
/**
110118
* Dump blob fields as hex.
111119
* --hex-blob
@@ -147,6 +155,7 @@ public function setup(array $conf = array())
147155
$this->hexBlob = Util\Str::toBoolean(Util\Arr::getValue($conf, 'hexBlob', ''), false);
148156
$this->quick = Util\Str::toBoolean(Util\Arr::getValue($conf, 'quick', ''), false);
149157
$this->compress = Util\Str::toBoolean(Util\Arr::getValue($conf, 'compress', ''), false);
158+
$this->extendedInsert = Util\Str::toBoolean(Util\Arr::getValue($conf, 'extendedInsert', ''), false);
150159
$this->noData = Util\Str::toBoolean(Util\Arr::getValue($conf, 'noData', ''), false);
151160
}
152161

@@ -202,6 +211,7 @@ public function getExecutable(Target $target)
202211
->useQuickMode($this->quick)
203212
->dumpBlobsHexadecimal($this->hexBlob)
204213
->useCompression($this->compress)
214+
->useExtendedInsert($this->extendedInsert)
205215
->dumpTables($this->tables)
206216
->dumpDatabases($this->databases)
207217
->ignoreTables($this->ignoreTables)

src/Cli/Executable/Mysqldump.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ class Mysqldump extends Abstraction implements Executable
9696
*/
9797
private $noData = false;
9898

99+
/**
100+
* Use mysqldump extended insert mode
101+
* -e, --extended-insert
102+
*
103+
* @var boolean
104+
*/
105+
private $extendedInsert = false;
106+
99107
/**
100108
* Dump blob fields as hex.
101109
* --hex-blob
@@ -172,6 +180,18 @@ public function useCompression($bool)
172180
return $this;
173181
}
174182

183+
/**
184+
* Use '-e' extended insert mode.
185+
*
186+
* @param boolean $bool
187+
* @return \phpbu\App\Cli\Executable\Mysqldump
188+
*/
189+
public function useExtendedInsert($bool)
190+
{
191+
$this->extendedInsert = $bool;
192+
return $this;
193+
}
194+
175195
/**
176196
* Use '--hex-blob' to encode binary fields.
177197
*
@@ -275,6 +295,7 @@ protected function createProcess()
275295
$cmd->addOptionIfNotEmpty('--host', $this->host);
276296
$cmd->addOptionIfNotEmpty('-q', $this->quick, false);
277297
$cmd->addOptionIfNotEmpty('-C', $this->compress, false);
298+
$cmd->addOptionIfNotEmpty('-e', $this->extendedInsert, false);
278299
$cmd->addOptionIfNotEmpty('--hex-blob', $this->hexBlob, false);
279300

280301
if (count($this->tablesToDump)) {

tests/phpbu/Backup/Source/MysqldumpTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ public function testHexBlob()
6868
$this->assertEquals($path . '/mysqldump --hex-blob --all-databases 2> /dev/null', $cmd);
6969
}
7070

71+
/**
72+
* Tests Mysqldump::getExecutable
73+
*/
74+
public function testExtendedInsert()
75+
{
76+
$target = $this->getTargetMock();
77+
$path = realpath(__DIR__ . '/../../../_files/bin');
78+
$this->mysqldump->setup(array('pathToMysqldump' => $path, 'extendedInsert' => 'true'));
79+
80+
$executable = $this->mysqldump->getExecutable($target);
81+
$cmd = $executable->getCommandLine();
82+
83+
$this->assertEquals($path . '/mysqldump -e --all-databases 2> /dev/null', $cmd);
84+
}
85+
7186
/**
7287
* Tests Mysqldump::backup
7388
*/

tests/phpbu/Cli/Executable/MysqldumpTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ public function testHexBlob()
3939
$this->assertEquals($path . '/mysqldump --hex-blob --all-databases 2> /dev/null', $cmd);
4040
}
4141

42+
/**
43+
* Tests Mysqldump::useExtendedInsert
44+
*/
45+
public function testUseExtendedInsert()
46+
{
47+
$path = realpath(__DIR__ . '/../../../_files/bin');
48+
$mysqldump = new Mysqldump($path);
49+
$mysqldump->useExtendedInsert(true);
50+
$cmd = $mysqldump->getCommandLine();
51+
52+
$this->assertEquals($path . '/mysqldump -e --all-databases 2> /dev/null', $cmd);
53+
}
54+
4255
/**
4356
* Tests Mysqldump::getCommandLine
4457
*/

0 commit comments

Comments
 (0)