1 |
efrain |
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 |
* CLI interface for creating a test site.
|
|
|
19 |
*
|
|
|
20 |
* @package tool_generator
|
|
|
21 |
* @copyright 2013 David Monllaó
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
define('CLI_SCRIPT', true);
|
|
|
26 |
define('NO_OUTPUT_BUFFERING', true);
|
|
|
27 |
|
|
|
28 |
require(__DIR__ . '/../../../../config.php');
|
|
|
29 |
require_once($CFG->libdir. '/clilib.php');
|
|
|
30 |
|
|
|
31 |
// CLI options.
|
|
|
32 |
list($options, $unrecognized) = cli_get_params(
|
|
|
33 |
array(
|
|
|
34 |
'help' => false,
|
|
|
35 |
'size' => false,
|
|
|
36 |
'fixeddataset' => false,
|
|
|
37 |
'filesizelimit' => false,
|
|
|
38 |
'bypasscheck' => false,
|
|
|
39 |
'quiet' => false
|
|
|
40 |
),
|
|
|
41 |
array(
|
|
|
42 |
'h' => 'help'
|
|
|
43 |
)
|
|
|
44 |
);
|
|
|
45 |
|
|
|
46 |
$sitesizes = '* ' . implode(PHP_EOL . '* ', tool_generator_site_backend::get_size_choices());
|
|
|
47 |
|
|
|
48 |
// Display help.
|
|
|
49 |
if (!empty($options['help']) || empty($options['size'])) {
|
|
|
50 |
echo "
|
|
|
51 |
Utility to generate a standard test site data set.
|
|
|
52 |
|
|
|
53 |
Not for use on live sites; only normally works if debugging is set to DEVELOPER
|
|
|
54 |
level.
|
|
|
55 |
|
|
|
56 |
Consider that, depending on the size you select, this CLI tool can really generate a lot of data, aproximated sizes:
|
|
|
57 |
|
|
|
58 |
$sitesizes
|
|
|
59 |
|
|
|
60 |
Options:
|
|
|
61 |
--size Size of the generated site, this value affects the number of courses and their size. Accepted values: XS, S, M, L, XL, or XXL (required)
|
|
|
62 |
--fixeddataset Use a fixed data set instead of randomly generated data
|
|
|
63 |
--filesizelimit Limits the size of the generated files to the specified bytes
|
|
|
64 |
--bypasscheck Bypasses the developer-mode check (be careful!)
|
|
|
65 |
--quiet Do not show any output
|
|
|
66 |
|
|
|
67 |
-h, --help Print out this help
|
|
|
68 |
|
|
|
69 |
Example from Moodle root directory:
|
|
|
70 |
\$ php admin/tool/generator/cli/maketestsite.php --size=S
|
|
|
71 |
";
|
|
|
72 |
// Exit with error unless we're showing this because they asked for it.
|
|
|
73 |
exit(empty($options['help']) ? 1 : 0);
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
// Check debugging is set to developer level.
|
|
|
77 |
if (empty($options['bypasscheck']) && !$CFG->debugdeveloper) {
|
|
|
78 |
cli_error(get_string('error_notdebugging', 'tool_generator'));
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
// Get options.
|
|
|
82 |
$sizename = $options['size'];
|
|
|
83 |
$fixeddataset = $options['fixeddataset'];
|
|
|
84 |
$filesizelimit = $options['filesizelimit'];
|
|
|
85 |
|
|
|
86 |
// Check size.
|
|
|
87 |
try {
|
|
|
88 |
$size = tool_generator_site_backend::size_for_name($sizename);
|
|
|
89 |
} catch (coding_exception $e) {
|
|
|
90 |
cli_error("Invalid size ($sizename). Use --help for help.");
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
// Switch to admin user account.
|
|
|
94 |
\core\session\manager::set_user(get_admin());
|
|
|
95 |
|
|
|
96 |
// Do backend code to generate site.
|
|
|
97 |
$backend = new tool_generator_site_backend($size, $options['bypasscheck'], $fixeddataset, $filesizelimit, empty($options['quiet']));
|
|
|
98 |
$backend->make();
|