'.get_string('table').' '.$table.':';
$details .= '
';
foreach ($items as $item) {
$details .= '- '.$item.'
';
}
$details .= '
';
}
throw new dbtransfer_exception('importschemaexception', $details);
}
if ($this->transactionmode == 'allinone') {
$this->transaction = $this->mdb->start_delegated_transaction();
}
}
/**
* Callback function. Should be called only once per table import operation,
* before any table changes are made. It will delete all table data.
*
* @throws dbtransfer_exception an unknown table import is attempted
* @throws ddl_table_missing_exception if the table is missing
*
* @param string $tablename - the name of the table that will be imported
* @param string $schemaHash - the hash of the xmldb_table schema of the table
* @return void
*/
public function begin_table_import($tablename, $schemaHash) {
if ($this->transactionmode == 'pertable') {
$this->transaction = $this->mdb->start_delegated_transaction();
}
if (!$table = $this->schema->getTable($tablename)) {
throw new dbtransfer_exception('unknowntableexception', $tablename);
}
if ($schemaHash != $table->getHash()) {
throw new dbtransfer_exception('differenttableexception', $tablename);
}
// this should not happen, unless someone drops tables after import started
if (!$this->manager->table_exists($table)) {
throw new ddl_table_missing_exception($tablename);
}
$this->mdb->delete_records($tablename);
}
/**
* Callback function. Should be called only once per table import operation,
* after all table changes are made. It will reset table sequences if any.
* @param string $tablename
* @return void
*/
public function finish_table_import($tablename) {
$table = $this->schema->getTable($tablename);
$fields = $table->getFields();
foreach ($fields as $field) {
if ($field->getSequence()) {
$this->manager->reset_sequence($tablename);
return;
}
}
if ($this->transactionmode == 'pertable') {
$this->transaction->allow_commit();
}
}
/**
* Callback function. Should be called only once database per import
* operation, after all database changes are made. It will commit changes.
* @return void
*/
public function finish_database_import() {
if ($this->transactionmode == 'allinone') {
$this->transaction->allow_commit();
}
}
/**
* Callback function. Should be called only once per record import operation, only
* between @see begin_table_import and @see finish_table_import calls.
* It will insert table data.
*
* @throws dml_exception if data insert operation failed
*
* @param string $tablename - the name of the table in which data will be
* imported
* @param object $data - data object (fields and values will be inserted
* into table)
* @return void
*/
public function import_table_data($tablename, $data) {
$this->mdb->import_record($tablename, $data);
}
/**
* Common import method
* @return void
*/
public function import_database() {
// implement in subclasses
}
}