Skip to content

Commit ce4ea64

Browse files
committed
Allow mysqldump to skip triggers
1 parent 704224d commit ce4ea64

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

src/Backup/Source/Mysqldump.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ class Mysqldump extends SimulatorExecutable implements Simulator, Restorable
192192
*/
193193
private $routines;
194194

195+
/**
196+
* Skip triggers
197+
* --skip-triggers
198+
*
199+
* @var bool
200+
*/
201+
private $skipTriggers;
202+
195203
/**
196204
* Setup.
197205
*
@@ -221,6 +229,7 @@ public function setup(array $conf = [])
221229
$this->noData = Util\Str::toBoolean(Util\Arr::getValue($conf, 'noData', ''), false);
222230
$this->filePerTable = Util\Str::toBoolean(Util\Arr::getValue($conf, 'filePerTable', ''), false);
223231
$this->routines = Util\Str::toBoolean(Util\Arr::getValue($conf, 'routines', ''), false);
232+
$this->skipTriggers = Util\Str::toBoolean(Util\Arr::getValue($conf, 'skipTriggers', ''), false);
224233

225234
// this doesn't fail, but it doesn't work, so throw an exception so the user understands
226235
if ($this->filePerTable && count($this->structureOnly)) {
@@ -331,6 +340,7 @@ protected function createExecutable(Target $target) : Executable
331340
->produceFilePerTable($this->filePerTable)
332341
->dumpNoData($this->noData)
333342
->dumpRoutines($this->routines)
343+
->skipTriggers($this->skipTriggers)
334344
->dumpStructureOnly($this->structureOnly)
335345
->dumpTo($this->getDumpTarget($target));
336346
// if compression is active and commands can be piped

src/Cli/Executable/Mysqldump.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ class Mysqldump extends Abstraction implements Executable
172172
*/
173173
private $routines = false;
174174

175+
/**
176+
* Skip triggers
177+
* --skip-triggers
178+
*
179+
* @var boolean
180+
*/
181+
private $skipTriggers = false;
182+
175183
/**
176184
* Path to dump file
177185
*
@@ -415,6 +423,18 @@ public function dumpRoutines(bool $bool) : Mysqldump
415423
return $this;
416424
}
417425

426+
/**
427+
* Skip triggers.
428+
*
429+
* @param bool $bool
430+
* @return \phpbu\App\Cli\Executable\Mysqldump
431+
*/
432+
public function skipTriggers(bool $bool) : Mysqldump
433+
{
434+
$this->skipTriggers = $bool;
435+
return $this;
436+
}
437+
418438
/**
419439
* Pipe compressor.
420440
*
@@ -464,6 +484,7 @@ protected function createCommandLine() : CommandLine
464484
$cmd->addOptionIfNotEmpty('--hex-blob', $this->hexBlob, false);
465485
$cmd->addOptionIfNotEmpty('--set-gtid-purged', $this->gtidPurged);
466486
$cmd->addOptionIfNotEmpty('--routines', $this->routines, false);
487+
$cmd->addOptionIfNotEmpty('--skip-triggers', $this->skipTriggers, false);
467488

468489
$this->configureSourceData($cmd);
469490
$this->configureIgnoredTables($cmd);

tests/phpbu/Backup/Source/MysqldumpTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ public function testExtendedInsert()
176176
$this->assertEquals(PHPBU_TEST_BIN . '/mysqldump -e --all-databases', $executable->getCommand());
177177
}
178178

179+
/**
180+
* Tests Mysqldump::getExecutable
181+
*/
182+
public function testSkipTriggers()
183+
{
184+
$target = $this->createTargetMock();
185+
$mysqldump = new Mysqldump();
186+
$mysqldump->setup(['pathToMysqldump' => PHPBU_TEST_BIN, 'skipTriggers' => 'true']);
187+
188+
$executable = $mysqldump->getExecutable($target);
189+
190+
$this->assertEquals(PHPBU_TEST_BIN . '/mysqldump --skip-triggers --all-databases', $executable->getCommand());
191+
}
192+
179193
/**
180194
* Tests Mysqldump::backup
181195
*/

tests/phpbu/Cli/Executable/MysqldumpTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,18 @@ public function testStructureOnly()
285285
$mysqldump->getCommand()
286286
);
287287
}
288+
289+
/**
290+
* Tests Mysqldump::getCommand
291+
*/
292+
public function testSkipTriggers()
293+
{
294+
$mysqldump = new Mysqldump(PHPBU_TEST_BIN);
295+
$mysqldump->skipTriggers(true);
296+
297+
$this->assertEquals(
298+
PHPBU_TEST_BIN . '/mysqldump --skip-triggers --all-databases',
299+
$mysqldump->getCommand()
300+
);
301+
}
288302
}

0 commit comments

Comments
 (0)