2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * @package tool_dbtransfer
21 * @copyright 2008 Petr Skoda {@link http://skodak.org/}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 define('NO_OUTPUT_BUFFERING', true);
27 require('../../../config.php');
28 require_once('locallib.php');
29 require_once('database_transfer_form.php');
32 admin_externalpage_setup('tooldbtransfer');
35 $form = new database_transfer_form();
38 // If we have valid input.
39 if ($data = $form->get_data()) {
40 // Connect to the other database.
41 list($dbtype, $dblibrary) = explode('/', $data->driver
);
42 $targetdb = moodle_database
::get_driver_instance($dbtype, $dblibrary);
45 $dboptions['dbport'] = $data->dbport
;
47 if ($data->dbsocket
) {
48 $dboptions['dbsocket'] = $data->dbsocket
;
51 $targetdb->connect($data->dbhost
, $data->dbuser
, $data->dbpass
, $data->dbname
, $data->prefix
, $dboptions);
52 if ($targetdb->get_tables()) {
53 $problem .= get_string('targetdatabasenotempty', 'tool_dbtransfer');
55 } catch (moodle_exception
$e) {
56 $problem .= get_string('notargetconectexception', 'tool_dbtransfer').'<br />'.$e->debuginfo
;
59 if ($problem === '') {
60 // Scroll down to the bottom when finished.
61 $PAGE->requires
->js_init_code("window.scrollTo(0, 5000000);");
63 // Enable CLI maintenance mode if requested.
64 if ($data->enablemaintenance
) {
65 $PAGE->set_pagelayout('maintenance');
66 tool_dbtransfer_create_maintenance_file();
70 echo $OUTPUT->header();
71 $data->dbtype
= $dbtype;
72 $data->dbtypefrom
= $CFG->dbtype
;
73 echo $OUTPUT->heading(get_string('transferringdbto', 'tool_dbtransfer', $data));
76 $CFG->tool_dbransfer_migration_running
= true;
78 $feedback = new html_list_progress_trace();
79 tool_dbtransfer_transfer_database($DB, $targetdb, $feedback);
80 $feedback->finished();
81 } catch (Exception
$e) {
82 if ($data->enablemaintenance
) {
83 tool_dbtransfer_maintenance_callback();
85 unset($CFG->tool_dbransfer_migration_running
);
88 unset($CFG->tool_dbransfer_migration_running
);
91 echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
92 echo $OUTPUT->continue_button("$CFG->wwwroot/$CFG->admin/");
93 echo $OUTPUT->footer();
98 // Otherwise display the settings form.
99 echo $OUTPUT->header();
100 echo $OUTPUT->heading(get_string('transferdbtoserver', 'tool_dbtransfer'));
102 $info = format_text(get_string('transferdbintro', 'tool_dbtransfer'), FORMAT_MARKDOWN
);
103 echo $OUTPUT->box($info);
106 if ($problem !== '') {
107 echo $OUTPUT->box($problem, 'generalbox error');
109 echo $OUTPUT->footer();