MDL-73975 course: Remove course_search_form template
[moodle.git] / admin / cli / check_database_schema.php
blob3164a27e22a928c6dc0070d1efa445fbe9a8ffdd
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.
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/>.
17 /**
18 * Validate that the current db structure matches the install.xml files.
20 * @package core
21 * @copyright 2014 Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @author Petr Skoda <petr.skoda@totaralms.com>
26 define('CLI_SCRIPT', true);
28 require(__DIR__ . '/../../config.php');
29 require_once($CFG->libdir.'/clilib.php');
31 $help = "Validate database structure
33 Options:
34 -h, --help Print out this help.
36 Example:
37 \$ sudo -u www-data /usr/bin/php admin/cli/check_database_schema.php
40 list($options, $unrecognized) = cli_get_params(
41 array(
42 'help' => false,
44 array(
45 'h' => 'help',
49 if ($options['help']) {
50 echo $help;
51 exit(0);
54 if (empty($CFG->version)) {
55 echo "Database is not yet installed.\n";
56 exit(2);
59 $dbmanager = $DB->get_manager();
60 $schema = $dbmanager->get_install_xml_schema();
62 if (!$errors = $dbmanager->check_database_schema($schema)) {
63 echo "Database structure is ok.\n";
64 exit(0);
67 foreach ($errors as $table => $items) {
68 cli_separator();
69 echo "$table\n";
70 foreach ($items as $item) {
71 echo " * $item\n";
74 cli_separator();
76 exit(1);