Skip to content

Commit be73a75

Browse files
Merge pull request #274 from timble/add-events-flag-to-mysqldump
Add --events flag to mysqldump
2 parents 2dd0203 + bfd48ec commit be73a75

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

src/Backup/Source/Mysqldump.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ class Mysqldump extends SimulatorExecutable implements Simulator, Restorable
200200
*/
201201
private $routines;
202202

203+
/**
204+
* Dump scheduled events
205+
*
206+
* @var bool
207+
*/
208+
private $events;
209+
203210
/**
204211
* Skip triggers
205212
* --skip-triggers
@@ -238,6 +245,7 @@ public function setup(array $conf = [])
238245
$this->noData = Util\Str::toBoolean(Util\Arr::getValue($conf, 'noData', ''), false);
239246
$this->filePerTable = Util\Str::toBoolean(Util\Arr::getValue($conf, 'filePerTable', ''), false);
240247
$this->routines = Util\Str::toBoolean(Util\Arr::getValue($conf, 'routines', ''), false);
248+
$this->events = Util\Str::toBoolean(Util\Arr::getValue($conf, 'events', ''), false);
241249
$this->skipTriggers = Util\Str::toBoolean(Util\Arr::getValue($conf, 'skipTriggers', ''), false);
242250

243251
// this doesn't fail, but it doesn't work, so throw an exception so the user understands
@@ -369,6 +377,7 @@ protected function createExecutable(Target $target) : Executable
369377
->produceFilePerTable($this->filePerTable)
370378
->dumpNoData($this->noData)
371379
->dumpRoutines($this->routines)
380+
->dumpEvents($this->events)
372381
->skipTriggers($this->skipTriggers)
373382
->dumpStructureOnly($this->structureOnly)
374383
->dumpTo($this->getDumpTarget($target));

src/Cli/Executable/Mysqldump.php

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

183+
/**
184+
* Dump scheduled events.
185+
* --events
186+
*
187+
* @var bool
188+
*/
189+
private $events = false;
190+
183191
/**
184192
* Skip triggers
185193
* --skip-triggers
@@ -443,6 +451,18 @@ public function dumpRoutines(bool $bool) : Mysqldump
443451
return $this;
444452
}
445453

454+
/**
455+
* Dump scheduled events
456+
*
457+
* @param bool $bool
458+
* @return \phpbu\App\Cli\Executable\Mysqldump
459+
*/
460+
public function dumpEvents(bool $bool) : Mysqldump
461+
{
462+
$this->events = $bool;
463+
return $this;
464+
}
465+
446466
/**
447467
* Skip triggers
448468
*
@@ -505,6 +525,7 @@ protected function createCommandLine() : CommandLine
505525
$cmd->addOptionIfNotEmpty('--set-gtid-purged', $this->gtidPurged);
506526
$cmd->addOptionIfNotEmpty('--ssl-ca', $this->sslCa);
507527
$cmd->addOptionIfNotEmpty('--routines', $this->routines, false);
528+
$cmd->addOptionIfNotEmpty('--events', $this->events, false);
508529
$cmd->addOptionIfNotEmpty('--skip-triggers', $this->skipTriggers, false);
509530

510531
$this->configureSourceData($cmd);

tests/phpbu/Backup/Source/MysqldumpTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ public function testSkipTriggers()
209209
$this->assertEquals(PHPBU_TEST_BIN . '/mysqldump --skip-triggers --all-databases', $executable->getCommand());
210210
}
211211

212+
/**
213+
* Tests Mysqldump::
214+
*/
215+
public function testEvents()
216+
{
217+
$target = $this->createTargetMock();
218+
$mysqldump = new Mysqldump();
219+
$mysqldump->setup(['pathToMysqldump' => PHPBU_TEST_BIN, 'events' => 'true']);
220+
221+
$executable = $mysqldump->getExecutable($target);
222+
223+
$this->assertEquals(PHPBU_TEST_BIN . '/mysqldump --events --all-databases', $executable->getCommand());
224+
}
225+
212226
/**
213227
* Tests Mysqldump::backup
214228
*/

tests/phpbu/Cli/Executable/MysqldumpTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ public function testNoData()
226226
$this->assertEquals($path . '/mysqldump --all-databases --no-data', $mysqldump->getCommand());
227227
}
228228

229+
/**
230+
* Tests Mysqldump::dumpEvents
231+
*/
232+
public function testEvents()
233+
{
234+
$path = realpath(__DIR__ . '/../../../_files/bin');
235+
$mysqldump = new Mysqldump($path);
236+
$mysqldump->dumpEvents(true);
237+
238+
$this->assertEquals($path . '/mysqldump --events --all-databases', $mysqldump->getCommand());
239+
}
240+
229241
/**
230242
* Tests Mysqldump::getCommand
231243
*/

0 commit comments

Comments
 (0)