[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 require_login(); 29 $context = context_system::instance(); 30 require_capability('moodle/site:config', $context); 31 require_sesskey(); 32 33 navigation_node::override_active_url(new moodle_url('/admin/settings.php', array('section' => 'logsettingdatabase'))); 34 admin_externalpage_setup('logstoredbtestsettings'); 35 36 echo $OUTPUT->header(); 37 echo $OUTPUT->heading(get_string('testingsettings', 'logstore_database')); 38 39 // NOTE: this is not localised intentionally, admins are supposed to understand English at least a bit... 40 41 raise_memory_limit(MEMORY_HUGE); 42 $dbtable = get_config('logstore_database', 'dbtable'); 43 if (empty($dbtable)) { 44 echo $OUTPUT->notification('External table not specified.', 'notifyproblem'); 45 die(); 46 } 47 48 $dbdriver = get_config('logstore_database', 'dbdriver'); 49 list($dblibrary, $dbtype) = explode('/', $dbdriver); 50 if (!$db = \moodle_database::get_driver_instance($dbtype, $dblibrary, true)) { 51 echo $OUTPUT->notification("Unknown driver $dblibrary/$dbtype", "notifyproblem"); 52 die(); 53 } 54 55 $olddebug = $CFG->debug; 56 $olddisplay = ini_get('display_errors'); 57 ini_set('display_errors', '1'); 58 $CFG->debug = DEBUG_DEVELOPER; 59 error_reporting($CFG->debug); 60 61 $dboptions = array(); 62 $dboptions['dbpersist'] = get_config('logstore_database', 'dbpersist'); 63 $dboptions['dbsocket'] = get_config('logstore_database', 'dbsocket'); 64 $dboptions['dbport'] = get_config('logstore_database', 'dbport'); 65 $dboptions['dbschema'] = get_config('logstore_database', 'dbschema'); 66 $dboptions['dbcollation'] = get_config('logstore_database', 'dbcollation'); 67 68 try { 69 $db->connect(get_config('logstore_database', 'dbhost'), get_config('logstore_database', 'dbuser'), 70 get_config('logstore_database', 'dbpass'), get_config('logstore_database', 'dbname'), false, $dboptions); 71 } catch (\moodle_exception $e) { 72 echo $OUTPUT->notification('Cannot connect to the database.', 'notifyproblem'); 73 $CFG->debug = $olddebug; 74 ini_set('display_errors', $olddisplay); 75 error_reporting($CFG->debug); 76 ob_end_flush(); 77 echo $OUTPUT->footer(); 78 die(); 79 } 80 echo $OUTPUT->notification('Connection made.', 'notifysuccess'); 81 $tables = $db->get_tables(); 82 if (!in_array($dbtable, $tables)) { 83 echo $OUTPUT->notification('Cannot find the specified table ' . $dbtable, 'notifyproblem'); 84 $CFG->debug = $olddebug; 85 ini_set('display_errors', $olddisplay); 86 error_reporting($CFG->debug); 87 ob_end_flush(); 88 echo $OUTPUT->footer(); 89 die(); 90 } 91 echo $OUTPUT->notification('Table ' . $dbtable . ' found.', 'notifysuccess'); 92 93 $cols = $db->get_columns($dbtable); 94 if (empty($cols)) { 95 echo $OUTPUT->notification('Can not read external table.', 'notifyproblem'); 96 } else { 97 $columns = array_keys((array)$cols); 98 echo $OUTPUT->notification('External table contains following columns:<br />' . implode(', ', $columns), 'notifysuccess'); 99 } 100 101 $db->dispose(); 102 103 $CFG->debug = $olddebug; 104 ini_set('display_errors', $olddisplay); 105 error_reporting($CFG->debug); 106 ob_end_flush(); 107 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |