]> git.mjollnir.org Git - moodle.git/commitdiff
admin dbtransfer: MDL-18225 dbtransfer script should do some output to reassure you...
authortjhunt <tjhunt>
Thu, 12 Feb 2009 08:34:35 +0000 (08:34 +0000)
committertjhunt <tjhunt>
Thu, 12 Feb 2009 08:34:35 +0000 (08:34 +0000)
admin/dbtransfer/index.php
admin/dbtransfer/lib.php
lang/en_utf8/dbtransfer.php
lang/en_utf8/error.php
lib/dtl/database_mover.php

index 76bb6c941823e5f983241f459e06caf8bbdf9805..0ee0489e1de12f0a6dc4243e292664ebc1609a50 100644 (file)
@@ -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 '<p>', get_string('transferdbintro', 'dbtransfer'), "</p>\n\n";
 $form->display();
 admin_externalpage_print_footer();
index c1d7858a8672f49ac95bf4e5144969d07cf661f5..a14e745945b27226ab9113315d088e903f9402e2 100644 (file)
@@ -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);
 }
index bf9895aac5f64963e2f746268e856ec4529202d1..e2d40afbc9d92dfc70b48c59623e2f28e2dfa566 100644 (file)
@@ -1,8 +1,13 @@
 <?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';
@@ -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.';
index 437b866a07a62a0a974ef5b8583fb8a1be984588..d587a8bdb75b010f3f1fde3894c8256731856e8f 100644 (file)
@@ -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';
index 415b753d8d1a48cc0ae62e14e1c5cb492259053c..6236a881815e8fc1f7c279f324df97e28b768994 100644 (file)
@@ -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());
     }