/**
  * Define transfer form.
  */
 protected function definition()
 {
     global $CFG;
     $mform = $this->_form;
     $mform->addElement('header', 'database', get_string('targetdatabase', 'tool_dbtransfer'));
     $drivers = tool_dbtransfer_get_drivers();
     $drivers = array_reverse($drivers, true);
     $drivers[''] = get_string('choosedots');
     $drivers = array_reverse($drivers, true);
     $mform->addElement('select', 'driver', get_string('dbtype', 'install'), $drivers);
     $mform->addElement('text', 'dbhost', get_string('databasehost', 'install'));
     $mform->addElement('text', 'dbname', get_string('databasename', 'install'));
     $mform->addElement('text', 'dbuser', get_string('databaseuser', 'install'));
     $mform->addElement('passwordunmask', 'dbpass', get_string('databasepass', 'install'));
     $mform->addElement('text', 'prefix', get_string('dbprefix', 'install'));
     $mform->addElement('text', 'dbport', get_string('dbport', 'install'));
     if ($CFG->ostype !== 'WINDOWS') {
         $mform->addElement('text', 'dbsocket', get_string('databasesocket', 'install'));
     } else {
         $mform->addElement('hidden', 'dbsocket');
     }
     $mform->addRule('driver', get_string('required'), 'required', null);
     $mform->addRule('dbhost', get_string('required'), 'required', null);
     $mform->addRule('dbname', get_string('required'), 'required', null);
     $mform->addRule('dbuser', get_string('required'), 'required', null);
     $mform->addRule('dbpass', get_string('required'), 'required', null);
     if (!isset($drivers['mysqli/native'])) {
         $mform->addRule('prefix', get_string('required'), 'required', null);
     }
     $mform->addElement('header', 'database', get_string('options', 'tool_dbtransfer'));
     $mform->addElement('advcheckbox', 'enablemaintenance', get_string('enablemaintenance', 'tool_dbtransfer'));
     $mform->addHelpButton('enablemaintenance', 'enablemaintenance', 'tool_dbtransfer');
     $this->add_action_buttons(false, get_string('transferdata', 'tool_dbtransfer'));
 }
Beispiel #2
0
define('CLI_SCRIPT', true);
require __DIR__ . '/../../../../config.php';
require_once $CFG->libdir . '/clilib.php';
require_once __DIR__ . '/../locallib.php';
$help = "Database migration script.\n\nIt is strongly recommended to turn off the web server\nor enable CLI maintenance mode before starting the migration.\n\nOptions:\n--dbtype=TYPE         Database type.\n--dblibrary=TYPE      Database library. Defaults to 'native'.\n--dbhost=HOST         Database host.\n--dbname=NAME         Database name.\n--dbuser=USERNAME     Database user.\n--dbpass=PASSWORD     Database password.\n--dbport=NUMBER       Database port.\n--prefix=STRING       Table prefix for above database tables.\n--dbsocket=PATH       Use database sockets. Available for some databases only.\n-h, --help            Print out this help.\n\nExample:\n\$ sudo -u www-data /usr/bin/php admin/tool/dbtransfer/cli/migrate.php\n";
// Now get cli options.
list($options, $unrecognized) = cli_get_params(array('dbtype' => null, 'dblibrary' => 'native', 'dbhost' => null, 'dbname' => null, 'dbuser' => null, 'dbpass' => null, 'dbport' => null, 'prefix' => null, 'dbsocket' => null, 'maintenance' => null, 'list' => false, 'help' => false), array('m' => 'maintenance', 'l' => 'list', 'h' => 'help'));
if ($options['help']) {
    echo $help;
    exit(0);
}
if (empty($CFG->version)) {
    cli_error(get_string('missingconfigversion', 'debug'));
}
echo "\n" . get_string('cliheading', 'tool_dbtransfer') . "\n\n";
$drivers = tool_dbtransfer_get_drivers();
if (!isset($options['dbtype'])) {
    $choose = array();
    foreach ($drivers as $driver => $name) {
        list($dbtype, $dblibrary) = explode('/', $driver);
        $choose[$dbtype] = $dbtype;
    }
    $optionsstr = implode(', ', $choose);
    cli_heading(get_string('databasetypehead', 'install') . " ({$optionsstr})");
    $options['dbtype'] = cli_input(get_string('clitypevalue', 'admin'), '', $choose, true);
}
$choose = array();
foreach ($drivers as $driver => $name) {
    list($dbtype, $dblibrary) = explode('/', $driver);
    if ($dbtype === $options['dbtype']) {
        $choose[$dblibrary] = $dblibrary;