diff --git a/lib/dtl/database_importer.php b/lib/dtl/database_importer.php index 45a9dcb5029..7d1b8bf4dc8 100644 --- a/lib/dtl/database_importer.php +++ b/lib/dtl/database_importer.php @@ -35,6 +35,10 @@ class database_importer { * @see begin_database_import). */ protected $check_schema; + /** + * How to use transactions. + */ + protected $transactionmode = 'allinone'; /** * Object constructor. @@ -52,6 +56,17 @@ class database_importer { $this->check_schema = $check_schema; } + /** + * How to use transactions during the import. + * @param string $mode 'pertable', 'allinone' or 'none'. + */ + public function set_transaction_mode($mode) { + if (!in_array($mode, array('pertable', 'allinone', 'none'))) { + throw new coding_exception('Unknown transaction mode', $mode); + } + $this->transactionmode = $mode; + } + /** * Callback function. Should be called only once database per import * operation, before any database changes are made. It will check the database @@ -89,7 +104,9 @@ class database_importer { } throw new dbtransfer_exception('importschemaexception', $details); } - $this->mdb->begin_sql(); + if ($this->transactionmode == 'allinone') { + $this->mdb->begin_sql(); + } } /** @@ -104,6 +121,9 @@ class database_importer { * @return void */ public function begin_table_import($tablename, $schemaHash) { + if ($this->transactionmode == 'pertable') { + $this->mdb->begin_sql(); + } if (!$table = $this->schema->getTable($tablename)) { throw new dbtransfer_exception('unknowntableexception', $tablename); } @@ -132,6 +152,9 @@ class database_importer { return; } } + if ($this->transactionmode == 'pertable') { + $this->mdb->commit_sql(); + } } /** @@ -140,7 +163,9 @@ class database_importer { * @return void */ public function finish_database_import() { - $this->mdb->commit_sql(); + if ($this->transactionmode == 'allinone') { + $this->mdb->commit_sql(); + } } /** diff --git a/lib/dtl/database_mover.php b/lib/dtl/database_mover.php index 6236a881815..3856a520fdc 100644 --- a/lib/dtl/database_mover.php +++ b/lib/dtl/database_mover.php @@ -31,6 +31,14 @@ class database_mover extends database_exporter { $this->importer = new database_importer($mdb_target, $check_schema); } + /** + * How to use transactions during the transfer. + * @param string $mode 'pertable', 'allinone' or 'none'. + */ + public function set_transaction_mode($mode) { + $this->importer->set_transaction_mode($mode); + } + /** * Callback function. Calls importer's begin_database_import callback method. *