* @see begin_database_import).
*/
protected $check_schema;
+ /**
+ * How to use transactions.
+ */
+ protected $transactionmode = 'allinone';
/**
* Object constructor.
$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
}
throw new dbtransfer_exception('importschemaexception', $details);
}
- $this->mdb->begin_sql();
+ if ($this->transactionmode == 'allinone') {
+ $this->mdb->begin_sql();
+ }
}
/**
* @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);
}
return;
}
}
+ if ($this->transactionmode == 'pertable') {
+ $this->mdb->commit_sql();
+ }
}
/**
* @return void
*/
public function finish_database_import() {
- $this->mdb->commit_sql();
+ if ($this->transactionmode == 'allinone') {
+ $this->mdb->commit_sql();
+ }
}
/**
$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.
*