2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * CLI interface for creating a test course.
20 * @package tool_generator
21 * @copyright 2013 The Open University
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 define('CLI_SCRIPT', true);
26 define('NO_OUTPUT_BUFFERING', true);
28 require(dirname(__FILE__) . '/../../../../config.php');
29 require_once($CFG->libdir. '/clilib.php');
32 list($options, $unrecognized) = cli_get_params(
37 'fixeddataset' => false,
38 'filesizelimit' => false,
39 'bypasscheck' => false,
48 if (!empty($options['help']) || empty($options['shortname']) || empty($options['size'])) {
50 Utility to create standard test course. (Also available in GUI interface.)
52 Not for use on live sites; only normally works if debugging is set to DEVELOPER
56 --shortname Shortname of course to create (required)
57 --size Size of course to create XS, S, M, L, XL, or XXL (required)
58 --fixeddataset Use a fixed data set instead of randomly generated data
59 --filesizelimit Limits the size of the generated files to the specified bytes
60 --bypasscheck Bypasses the developer-mode check (be careful!)
61 --quiet Do not show any output
63 -h, --help Print out this help
65 Example from Moodle root directory:
66 \$ php admin/tool/generator/cli/maketestcourse.php --shortname=SIZE_S --size=S
68 // Exit with error unless we're showing this because they asked for it.
69 exit(empty($options['help']) ? 1 : 0);
72 // Check debugging is set to developer level.
73 if (empty($options['bypasscheck']) && !debugging('', DEBUG_DEVELOPER)) {
74 cli_error(get_string('error_notdebugging', 'tool_generator'));
78 $shortname = $options['shortname'];
79 $sizename = $options['size'];
80 $fixeddataset = $options['fixeddataset'];
81 $filesizelimit = $options['filesizelimit'];
85 $size = tool_generator_course_backend::size_for_name($sizename);
86 } catch (coding_exception $e) {
87 cli_error("Invalid size ($sizename). Use --help for help.");
91 if ($error = tool_generator_course_backend::check_shortname_available($shortname)) {
95 // Switch to admin user account.
96 \core\session\manager::set_user(get_admin());
98 // Do backend code to generate course.
99 $backend = new tool_generator_course_backend($shortname, $size, $fixeddataset, $filesizelimit, empty($options['quiet']));
100 $id = $backend->make();