From 2d3a43fc0c49f23bf7dee392b0dd1f8c799f89d3 Mon Sep 17 00:00:00 2001 From: Diego Torres Date: Wed, 12 Apr 2023 07:43:14 +0000 Subject: [PATCH] move start transaction code to a global level --- src/Ifsnop/Mysqldump/Mysqldump.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Ifsnop/Mysqldump/Mysqldump.php b/src/Ifsnop/Mysqldump/Mysqldump.php index d5dbc68..0a2f2b7 100644 --- a/src/Ifsnop/Mysqldump/Mysqldump.php +++ b/src/Ifsnop/Mysqldump/Mysqldump.php @@ -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() @@ -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. @@ -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'])) { @@ -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); } @@ -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); }