source: moodle/trunk/fuentes/admin/tool/innodb/index.php @ 136

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

Ported code to xenial

File size: 3.0 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 * InnoDB conversion tool.
19 *
20 * @package    tool
21 * @subpackage innodb
22 * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26define('NO_OUTPUT_BUFFERING', true);
27
28require_once('../../../config.php');
29require_once($CFG->libdir.'/adminlib.php');
30
31admin_externalpage_setup('toolinnodb');
32
33$confirm = optional_param('confirm', 0, PARAM_BOOL);
34
35require_login();
36require_capability('moodle/site:config', context_system::instance());
37
38echo $OUTPUT->header();
39echo $OUTPUT->heading('Convert all MySQL tables from MYISAM to InnoDB');
40
41if ($DB->get_dbfamily() != 'mysql') {
42    notice('This function is for MySQL databases only!', new moodle_url('/admin/'));
43}
44
45$prefix = str_replace('_', '\\_', $DB->get_prefix()).'%';
46$sql = "SHOW TABLE STATUS WHERE Name LIKE ? AND Engine <> 'InnoDB'";
47$rs = $DB->get_recordset_sql($sql, array($prefix));
48if (!$rs->valid()) {
49    $rs->close();
50    echo $OUTPUT->box('<p>All tables are already using InnoDB database engine.</p>');
51    echo $OUTPUT->continue_button('/admin/');
52    echo $OUTPUT->footer();
53    die;
54}
55
56if (data_submitted() and $confirm and confirm_sesskey()) {
57
58    echo $OUTPUT->notification('Please be patient and wait for this to complete...', 'notifysuccess');
59
60    core_php_time_limit::raise();
61
62    foreach ($rs as $table) {
63        $DB->set_debug(true);
64        $fulltable = $table->name;
65        try {
66            $DB->change_database_structure("ALTER TABLE $fulltable ENGINE=INNODB");
67        } catch (moodle_exception $e) {
68            echo $OUTPUT->notification(s($e->getMessage()).'<br />'.s($e->debuginfo));
69        }
70        $DB->set_debug(false);
71    }
72    $rs->close();
73    echo $OUTPUT->notification('... done.', 'notifysuccess');
74    echo $OUTPUT->continue_button(new moodle_url('/admin/'));
75    echo $OUTPUT->footer();
76
77} else {
78    $rs->close();
79    $optionsyes = array('confirm'=>'1', 'sesskey'=>sesskey());
80    $formcontinue = new single_button(new moodle_url('/admin/tool/innodb/index.php', $optionsyes), get_string('yes'));
81    $formcancel = new single_button(new moodle_url('/admin/'), get_string('no'), 'get');
82    echo $OUTPUT->confirm('Are you sure you want convert all your tables to the InnoDB format?', $formcontinue, $formcancel);
83    echo $OUTPUT->footer();
84}
85
86
Note: See TracBrowser for help on using the repository browser.