|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00026 define('NO_OUTPUT_BUFFERING', true); 00027 00028 require('../../../config.php'); 00029 require_once('locallib.php'); 00030 require_once('database_transfer_form.php'); 00031 00032 require_login(); 00033 admin_externalpage_setup('tooldbtransfer'); 00034 00035 // Create the form 00036 $form = new database_transfer_form(); 00037 00038 // If we have valid input. 00039 if ($data = $form->get_data()) { 00040 // Connect to the other database. 00041 list($dbtype, $dblibrary) = explode('/', $data->driver); 00042 $targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary); 00043 $dboptions = array(); 00044 if ($data->dbport) { 00045 $dboptions['dbport'] = $data->dbport; 00046 } 00047 if ($data->dbsocket) { 00048 $dboptions['dbsocket'] = $data->dbsocket; 00049 } 00050 if (!$targetdb->connect($data->dbhost, $data->dbuser, $data->dbpass, $data->dbname, $data->prefix, $dboptions)) { 00051 throw new dbtransfer_exception('notargetconectexception', null, "$CFG->wwwroot/$CFG->admin/tool/dbtransfer/"); 00052 } 00053 if ($targetdb->get_tables()) { 00054 throw new dbtransfer_exception('targetdatabasenotempty', null, "$CFG->wwwroot/$CFG->admin/tool/dbtransfer/"); 00055 } 00056 00057 // Start output. 00058 echo $OUTPUT->header(); 00059 $data->dbtype = $dbtype; 00060 echo $OUTPUT->heading(get_string('transferringdbto', 'tool_dbtransfer', $data)); 00061 00062 // Do the transfer. 00063 $feedback = new html_list_progress_trace(); 00064 dbtransfer_transfer_database($DB, $targetdb, $feedback); 00065 $feedback->finished(); 00066 00067 // Finish up. 00068 echo $OUTPUT->notification(get_string('success'), 'notifysuccess'); 00069 echo $OUTPUT->continue_button("$CFG->wwwroot/$CFG->admin/"); 00070 echo $OUTPUT->footer(); 00071 die; 00072 } 00073 00074 // Otherwise display the settings form. 00075 echo $OUTPUT->header(); 00076 echo $OUTPUT->heading(get_string('transferdbtoserver', 'tool_dbtransfer')); 00077 echo '<p>', get_string('transferdbintro', 'tool_dbtransfer'), "</p>\n\n"; 00078 $form->display(); 00079 echo $OUTPUT->footer();