mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
admin dbtransfer: MDL-18225 also, let the caller control how transactions are used.
This commit is contained in:
parent
2722269247
commit
8915fb70b0
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user