mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
admin dbtransfer: MDL-18225 dbtransfer script should do some output to reassure you that something is happening.
This commit is contained in:
parent
e82e01d1e0
commit
e69b06efd6
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.';
|
||||
|
@ -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';
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user