diff --git a/admin/cli/check_database_schema.php b/admin/cli/check_database_schema.php new file mode 100644 index 00000000000..3164a27e22a --- /dev/null +++ b/admin/cli/check_database_schema.php @@ -0,0 +1,76 @@ +. + +/** + * Validate that the current db structure matches the install.xml files. + * + * @package core + * @copyright 2014 Totara Learning Solutions Ltd {@link http://www.totaralms.com/} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Petr Skoda + */ + +define('CLI_SCRIPT', true); + +require(__DIR__ . '/../../config.php'); +require_once($CFG->libdir.'/clilib.php'); + +$help = "Validate database structure + +Options: +-h, --help Print out this help. + +Example: +\$ sudo -u www-data /usr/bin/php admin/cli/check_database_schema.php +"; + +list($options, $unrecognized) = cli_get_params( + array( + 'help' => false, + ), + array( + 'h' => 'help', + ) +); + +if ($options['help']) { + echo $help; + exit(0); +} + +if (empty($CFG->version)) { + echo "Database is not yet installed.\n"; + exit(2); +} + +$dbmanager = $DB->get_manager(); +$schema = $dbmanager->get_install_xml_schema(); + +if (!$errors = $dbmanager->check_database_schema($schema)) { + echo "Database structure is ok.\n"; + exit(0); +} + +foreach ($errors as $table => $items) { + cli_separator(); + echo "$table\n"; + foreach ($items as $item) { + echo " * $item\n"; + } +} +cli_separator(); + +exit(1);