From: tjhunt Date: Thu, 12 Feb 2009 08:34:35 +0000 (+0000) Subject: admin dbtransfer: MDL-18225 dbtransfer script should do some output to reassure you... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e69b06efd6c477f3397b0ce973157a5afa9dc1fc;p=moodle.git admin dbtransfer: MDL-18225 dbtransfer script should do some output to reassure you that something is happening. --- diff --git a/admin/dbtransfer/index.php b/admin/dbtransfer/index.php index 76bb6c9418..0ee0489e1d 100644 --- a/admin/dbtransfer/index.php +++ b/admin/dbtransfer/index.php @@ -7,28 +7,41 @@ require_once('database_transfer_form.php'); 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 '

', get_string('transferdbintro', 'dbtransfer'), "

\n\n"; $form->display(); admin_externalpage_print_footer(); diff --git a/admin/dbtransfer/lib.php b/admin/dbtransfer/lib.php index c1d7858a86..a14e745945 100644 --- a/admin/dbtransfer/lib.php +++ b/admin/dbtransfer/lib.php @@ -42,11 +42,11 @@ function dbtransfer_export_xml_database($description, $mdb) { } -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); } diff --git a/lang/en_utf8/dbtransfer.php b/lang/en_utf8/dbtransfer.php index bf9895aac5..e2d40afbc9 100644 --- a/lang/en_utf8/dbtransfer.php +++ b/lang/en_utf8/dbtransfer.php @@ -1,8 +1,13 @@ $a'; $string['importschemaexception'] = 'Current database structure does not match all install.xml files.
$a'; @@ -10,4 +15,7 @@ $string['importversionmismatchexception'] = 'Current version $a->currentver does $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.'; diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index 437b866a07..d587a8bdb7 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -415,6 +415,7 @@ $string['storedfilenotcreated'] = 'Can not create file \"$a->contextid/$a->filea $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'; diff --git a/lib/dtl/database_mover.php b/lib/dtl/database_mover.php index 415b753d8d..6236a88181 100644 --- a/lib/dtl/database_mover.php +++ b/lib/dtl/database_mover.php @@ -3,6 +3,7 @@ class database_mover extends database_exporter { /** Importer object used to transfer data. */ protected $importer; + protected $feeback; /** * Object constructor. @@ -15,8 +16,18 @@ class database_mover extends database_exporter { * 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); } @@ -29,6 +40,7 @@ class database_mover extends database_exporter { * @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); } @@ -39,6 +51,7 @@ class database_mover extends database_exporter { * @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()); } @@ -60,6 +73,7 @@ class database_mover extends database_exporter { * @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()); }