Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Filter form.
19
 *
20
 * @package    logstore_database
21
 * @copyright  2014 onwards Ankit Agarwal
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once('../../../../../config.php');
26
require_once($CFG->dirroot . '/lib/adminlib.php');
27
 
28
navigation_node::override_active_url(new moodle_url('/admin/settings.php', array('section' => 'logsettingdatabase')));
29
admin_externalpage_setup('logstoredbtestsettings');
30
 
31
echo $OUTPUT->header();
32
echo $OUTPUT->heading(get_string('testingsettings', 'logstore_database'));
33
 
34
// NOTE: this is not localised intentionally, admins are supposed to understand English at least a bit...
35
 
36
raise_memory_limit(MEMORY_HUGE);
37
$dbtable = get_config('logstore_database', 'dbtable');
38
if (empty($dbtable)) {
39
    echo $OUTPUT->notification('External table not specified.', 'notifyproblem');
40
    die();
41
}
42
 
43
$dbdriver = get_config('logstore_database', 'dbdriver');
44
list($dblibrary, $dbtype) = explode('/', $dbdriver);
45
if (!$db = \moodle_database::get_driver_instance($dbtype, $dblibrary, true)) {
46
    echo $OUTPUT->notification("Unknown driver $dblibrary/$dbtype", "notifyproblem");
47
    die();
48
}
49
 
50
$olddebug = $CFG->debug;
51
$olddisplay = ini_get('display_errors');
52
ini_set('display_errors', '1');
53
$CFG->debug = DEBUG_DEVELOPER;
54
error_reporting($CFG->debug);
55
 
56
$dboptions = array();
57
$dboptions['dbpersist'] = get_config('logstore_database', 'dbpersist');
58
$dboptions['dbsocket'] = get_config('logstore_database', 'dbsocket');
59
$dboptions['dbport'] = get_config('logstore_database', 'dbport');
60
$dboptions['dbschema'] = get_config('logstore_database', 'dbschema');
61
$dboptions['dbcollation'] = get_config('logstore_database', 'dbcollation');
62
$dboptions['dbhandlesoptions'] = get_config('logstore_database', 'dbhandlesoptions');
63
 
64
try {
65
    $db->connect(get_config('logstore_database', 'dbhost'), get_config('logstore_database', 'dbuser'),
66
        get_config('logstore_database', 'dbpass'), get_config('logstore_database', 'dbname'), false, $dboptions);
67
} catch (\moodle_exception $e) {
68
    echo $OUTPUT->notification('Cannot connect to the database.', 'notifyproblem');
69
    $CFG->debug = $olddebug;
70
    ini_set('display_errors', $olddisplay);
71
    error_reporting($CFG->debug);
72
    ob_end_flush();
73
    echo $OUTPUT->footer();
74
    die();
75
}
76
echo $OUTPUT->notification('Connection made.', 'notifysuccess');
77
$tables = $db->get_tables();
78
if (!in_array($dbtable, $tables)) {
79
    echo $OUTPUT->notification('Cannot find the specified table ' . $dbtable, 'notifyproblem');
80
    $CFG->debug = $olddebug;
81
    ini_set('display_errors', $olddisplay);
82
    error_reporting($CFG->debug);
83
    ob_end_flush();
84
    echo $OUTPUT->footer();
85
    die();
86
}
87
echo $OUTPUT->notification('Table ' . $dbtable . ' found.', 'notifysuccess');
88
 
89
$cols = $db->get_columns($dbtable);
90
if (empty($cols)) {
91
    echo $OUTPUT->notification('Can not read external table.', 'notifyproblem');
92
} else {
93
    $columns = array_keys((array)$cols);
94
    echo $OUTPUT->notification('External table contains following columns:<br />' . implode(', ', $columns), 'notifysuccess');
95
}
96
 
97
$db->dispose();
98
 
99
$CFG->debug = $olddebug;
100
ini_set('display_errors', $olddisplay);
101
error_reporting($CFG->debug);
102
ob_end_flush();
103
echo $OUTPUT->footer();