require_login();
admin_externalpage_setup('dbtransfer');
-//create form
+// Create the form
$form = new database_transfer_form();
+// If we have valid input.
if ($data = $form->get_data()) {
+ // Connect to the other database.
list($dbtype, $dblibrary) = explode('/', $data->driver);
$targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary);
if (!$targetdb->connect($data->dbhost, $data->dbuser, $data->dbpass, $data->dbname, $data->prefix, null)) {
throw new dbtransfer_exception('notargetconectexception', null, "$CFG->wwwroot/$CFG->admin/dbtransfer/");
}
if ($targetdb->get_tables()) {
- // TODO add exception or string...
- print_error('ddltablealreadyexists');
+ throw new dbtransfer_exception('targetdatabasenotempty', null, "$CFG->wwwroot/$CFG->admin/dbtransfer/");
}
+
+ // Start output.
admin_externalpage_print_header();
- dbtransfer_transfer_database($DB, $targetdb);
+ $data->dbtype = $dbtype;
+ print_heading(get_string('transferringdbto', 'dbtransfer', $data));
+
+ // Do the transfer.
+ $feedback = new html_list_progress_trace();
+ dbtransfer_transfer_database($DB, $targetdb, $feedback);
+ $feedback->finished();
+
+ // Finish up.
notify(get_string('success'), 'notifysuccess');
print_continue("$CFG->wwwroot/$CFG->admin/");
admin_externalpage_print_footer();
die;
}
+// Otherwise display the settings form.
admin_externalpage_print_header();
-// TODO: add some more info here
+print_heading(get_string('transferdbtoserver', 'dbtransfer'));
+echo '<p>', get_string('transferdbintro', 'dbtransfer'), "</p>\n\n";
$form->display();
admin_externalpage_print_footer();
}
-function dbtransfer_transfer_database($sourcedb, $targetdb) {
+function dbtransfer_transfer_database($sourcedb, $targetdb, $feedback = null) {
@set_time_limit(0);
session_get_instance()->write_close(); // release session
- $var = new database_mover($sourcedb, $targetdb);
+ $var = new database_mover($sourcedb, $targetdb, true, $feedback);
$var->export_database(null);
}
<?php // $Id$
+$string['checkingsourcetables'] = 'Checking source table structure';
+$string['copyingtable'] = 'Copying table $a';
+$string['copyingtables'] = 'Copying table contents';
+$string['creatingtargettables'] = 'Creating the tables in the target database';
$string['dbexport'] = 'Database export';
$string['dbtransfer'] = 'Database transfer';
$string['differenttableexception'] = 'Table $a structure does not match.';
+$string['done'] = 'Done';
$string['exportdata'] = 'Export data';
$string['exportschemaexception'] = 'Current database structure does not match all install.xml files. <br /> $a';
$string['importschemaexception'] = 'Current database structure does not match all install.xml files. <br /> $a';
$string['malformedxmlexception'] = 'Malformed XML found, can not continue.';
$string['notargetconectexception'] = 'Can not connect target database, sorry.';
$string['transferdata'] = 'Transfer data';
+$string['transferdbtoserver'] = 'Transfer this Moodle database to another server';
+$string['transferdbintro'] = 'This script will transfer the entire contents of this database to another database server.';
+$string['transferringdbto'] = 'Transferring this database to $a->dbtype database $a->dbname on $a->dbhost';
$string['unknowntableexception'] = 'Unknown table $a found in export file.';
$string['storedfileproblem'] = 'Unknown exception related to local files ($a)';
$string['tagnotfound'] = 'The specified tag was not found in the database';
$string['tagdisabled'] = 'Tags are disabled!';
+$string['targetdatabasenotempty'] = 'The target database is not empty. Transfer aborted for safety reasons.';
$string['themenotinstall'] = 'This theme is not installed!';
$string['transactionvoid'] = 'Transaction cannot be voided because it has already been voided';
$string['TODO'] = 'TODO';
class database_mover extends database_exporter {
/** Importer object used to transfer data. */
protected $importer;
+ protected $feeback;
/**
* Object constructor.
* schema matches the RDBMS database schema before exporting (used by
* @see export_database).
*/
- public function __construct(moodle_database $mdb_source, moodle_database $mdb_target, $check_schema=true) {
+ public function __construct(moodle_database $mdb_source, moodle_database $mdb_target,
+ $check_schema = true, moodle_progress_trace $feeback = null) {
+ if (empty($feeback)) {
+ $this->feeback = new null_progress_trace();
+ } else {
+ $this->feeback = $feeback;
+ }
+ if ($check_schema) {
+ $this->feeback->output(get_string('checkingsourcetables', 'dbtransfer'));
+ }
parent::__construct($mdb_source, $check_schema);
+ $this->feeback->output(get_string('creatingtargettables', 'dbtransfer'));
$this->importer = new database_importer($mdb_target, $check_schema);
}
* @return void
*/
public function begin_database_export($version, $release, $timestamp, $description) {
+ $this->feeback->output(get_string('copyingtables', 'dbtransfer'));
$this->importer->begin_database_import($version, $timestamp, $description);
}
* @return void
*/
public function begin_table_export(xmldb_table $table) {
+ $this->feeback->output(get_string('copyingtable', 'dbtransfer', $table->getName()), 1);
$this->importer->begin_table_import($table->getName(), $table->getHash());
}
* @return void
*/
public function finish_table_export(xmldb_table $table) {
+ $this->feeback->output(get_string('done', 'dbtransfer', $table->getName()), 2);
$this->importer->finish_table_import($table->getName());
}