source: moodle/trunk/fuentes/admin/tool/dbtransfer/database_transfer_form.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 4.3 KB
Line 
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
17/**
18 * Transfer form
19 *
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
23 */
24
25defined('MOODLE_INTERNAL') || die;
26
27require_once($CFG->libdir.'/formslib.php');
28require_once(__DIR__.'/locallib.php');
29
30
31/**
32 * Definition of db transfer settings form.
33 *
34 * @copyright  2008 Petr Skoda {@link http://skodak.org/}
35 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 */
37class database_transfer_form extends moodleform {
38
39    /**
40     * Define transfer form.
41     */
42    protected function definition() {
43        global $CFG;
44
45        $mform = $this->_form;
46
47        $mform->addElement('header', 'database', get_string('targetdatabase', 'tool_dbtransfer'));
48
49        $drivers = tool_dbtransfer_get_drivers();
50        $drivers = array_reverse($drivers, true);
51        $drivers[''] = get_string('choosedots');
52        $drivers = array_reverse($drivers, true);
53
54        $mform->addElement('select', 'driver', get_string('dbtype', 'install'), $drivers);
55        $mform->setType('driver', PARAM_RAW);
56
57        $mform->addElement('text', 'dbhost', get_string('databasehost', 'install'));
58        $mform->setType('dbhost', PARAM_HOST);
59
60        $mform->addElement('text', 'dbname', get_string('databasename', 'install'));
61        $mform->setType('dbname', PARAM_ALPHANUMEXT);
62
63        $mform->addElement('text', 'dbuser', get_string('databaseuser', 'install'));
64        $mform->setType('dbuser', PARAM_ALPHANUMEXT);
65
66        $mform->addElement('passwordunmask', 'dbpass', get_string('databasepass', 'install'));
67        $mform->setType('dbpass', PARAM_RAW);
68
69        $mform->addElement('text', 'prefix', get_string('dbprefix', 'install'));
70        $mform->setType('prefix', PARAM_ALPHANUMEXT);
71
72        $mform->addElement('text', 'dbport', get_string('dbport', 'install'));
73        $mform->setType('dbport', PARAM_INT);
74
75        if ($CFG->ostype !== 'WINDOWS') {
76            $mform->addElement('text', 'dbsocket', get_string('databasesocket', 'install'));
77        } else {
78            $mform->addElement('hidden', 'dbsocket');
79        }
80        $mform->setType('dbsocket', PARAM_RAW);
81
82        $mform->addRule('driver', get_string('required'), 'required', null);
83        $mform->addRule('dbhost', get_string('required'), 'required', null);
84        $mform->addRule('dbname', get_string('required'), 'required', null);
85        $mform->addRule('dbuser', get_string('required'), 'required', null);
86        $mform->addRule('dbpass', get_string('required'), 'required', null);
87        if (!isset($drivers['mysqli/native'])) {
88            $mform->addRule('prefix', get_string('required'), 'required', null);
89        }
90
91        $mform->addElement('header', 'database', get_string('options', 'tool_dbtransfer'));
92
93        $mform->addElement('advcheckbox', 'enablemaintenance', get_string('enablemaintenance', 'tool_dbtransfer'));
94        $mform->setType('enablemaintenance', PARAM_BOOL);
95        $mform->addHelpButton('enablemaintenance', 'enablemaintenance', 'tool_dbtransfer');
96
97        $this->add_action_buttons(false, get_string('transferdata', 'tool_dbtransfer'));
98    }
99
100    /**
101     * Validate prefix is present for non-mysql drivers.
102     * @param array $data
103     * @param array $files
104     * @return array
105     */
106    public function validation($data, $files) {
107        $errors = parent::validation($data, $files);
108        if ($data['driver'] !== 'mysqli/native') {
109            // This is a bloody hack, let's pretend we do not need to look at db family...
110            if ($data['prefix'] === '') {
111                $errors['prefix'] = get_string('required');
112            }
113        }
114        return $errors;
115    }
116}
Note: See TracBrowser for help on using the repository browser.