Skip to content

Commit

Permalink
move start transaction code to a global level
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsnop committed Apr 12, 2023
1 parent ec6a777 commit 2d3a43f
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Ifsnop/Mysqldump/Mysqldump.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ public function start($filename = '')
// Write some basic info to output file
$this->compressManager->write($this->getDumpFileHeader());

// initiate a transaction at global level to create a consistent snapshot
if ($this->dumpSettings['single-transaction']) {
$this->dbHandler->exec($this->typeAdapter->setup_transaction());
$this->dbHandler->exec($this->typeAdapter->start_transaction());
}

// Store server settings and use sanner defaults to dump
$this->compressManager->write(
$this->typeAdapter->backup_parameters()
Expand Down Expand Up @@ -484,6 +490,12 @@ public function start($filename = '')
$this->compressManager->write(
$this->typeAdapter->restore_parameters()
);

// end transaction
if ($this->dumpSettings['single-transaction']) {
$this->dbHandler->exec($this->typeAdapter->commit_transaction());
}

// Write some stats to output file.
$this->compressManager->write($this->getDumpFileFooter());
// Close output file.
Expand Down Expand Up @@ -694,6 +706,8 @@ private function matches($table, $arr)
*/
private function exportTables()
{


// Exporting tables one by one
foreach ($this->tables as $table) {
if ($this->matches($table, $this->dumpSettings['exclude-tables'])) {
Expand Down Expand Up @@ -1216,11 +1230,6 @@ public function prepareListValues($tableName)
);
}

if ($this->dumpSettings['single-transaction']) {
$this->dbHandler->exec($this->typeAdapter->setup_transaction());
$this->dbHandler->exec($this->typeAdapter->start_transaction());
}

if ($this->dumpSettings['lock-tables'] && !$this->dumpSettings['single-transaction']) {
$this->typeAdapter->lock_table($tableName);
}
Expand Down Expand Up @@ -1269,10 +1278,6 @@ public function endListValues($tableName, $count = 0)
);
}

if ($this->dumpSettings['single-transaction']) {
$this->dbHandler->exec($this->typeAdapter->commit_transaction());
}

if ($this->dumpSettings['lock-tables'] && !$this->dumpSettings['single-transaction']) {
$this->typeAdapter->unlock_table($tableName);
}
Expand Down

0 comments on commit 2d3a43f

Please sign in to comment.