source: moodle/trunk/fuentes/admin/tool/generator/cli/maketestplan.php @ 136

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

Ported code to xenial

File size: 4.3 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 * CLI interface for creating a test plan
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
25define('CLI_SCRIPT', true);
26define('NO_OUTPUT_BUFFERING', true);
27
28require(dirname(__FILE__) . '/../../../../config.php');
29require_once($CFG->libdir. '/clilib.php');
30
31// CLI options.
32list($options, $unrecognized) = cli_get_params(
33    array(
34        'help' => false,
35        'shortname' => false,
36        'size' => false,
37        'bypasscheck' => false,
38        'updateuserspassword' => false
39    ),
40    array(
41        'h' => 'help'
42    )
43);
44
45$testplansizes = '* ' . implode(PHP_EOL . '* ', tool_generator_testplan_backend::get_size_choices());
46
47// Display help.
48if (!empty($options['help']) || empty($options['shortname']) || empty($options['size'])) {
49
50    echo get_string('testplanexplanation', 'tool_generator', tool_generator_testplan_backend::get_repourl()) .
51"Options:
52-h, --help              Print out this help
53--shortname             Shortname of the test plan's target course (required)
54--size                  Size of the test plan to create XS, S, M, L, XL, or XXL (required)
55--bypasscheck           Bypasses the developer-mode check (be careful!)
56--updateuserspassword   Updates the target course users password according to \$CFG->tool_generator_users_password
57
58$testplansizes
59
60Consider that, the server resources you will need to run the test plan will be higher as the test plan size is higher.
61
62Example from Moodle root directory:
63\$ sudo -u www-data /usr/bin/php admin/tool/generator/cli/maketestplan.php --shortname=\"testcourse_12\" --size=S
64";
65    // Exit with error unless we're showing this because they asked for it.
66    exit(empty($options['help']) ? 1 : 0);
67}
68
69// Check debugging is set to developer level.
70if (empty($options['bypasscheck']) && !$CFG->debugdeveloper) {
71    cli_error(get_string('error_notdebugging', 'tool_generator'));
72}
73
74// Get options.
75$shortname = $options['shortname'];
76$sizename = $options['size'];
77
78// Check size.
79try {
80    $size = tool_generator_testplan_backend::size_for_name($sizename);
81} catch (coding_exception $e) {
82    cli_error("Error: Invalid size ($sizename). Use --help for help.");
83}
84
85// Check selected course.
86if ($errors = tool_generator_testplan_backend::has_selected_course_any_problem($shortname, $size)) {
87    // Showing the first reported problem.
88    cli_error("Error: " . reset($errors));
89}
90
91// Checking if test users password is set.
92if (empty($CFG->tool_generator_users_password) || is_bool($CFG->tool_generator_users_password)) {
93    cli_error("Error: " . get_string('error_nouserspassword', 'tool_generator'));
94}
95
96// Switch to admin user account.
97\core\session\manager::set_user(get_admin());
98
99// Create files.
100$courseid = $DB->get_field('course', 'id', array('shortname' => $shortname));
101$usersfile = tool_generator_testplan_backend::create_users_file($courseid, !empty($options['updateuserspassword']));
102$testplanfile = tool_generator_testplan_backend::create_testplan_file($courseid, $size);
103
104// One file path per line so other CLI scripts can easily parse the output.
105echo moodle_url::make_pluginfile_url(
106        $testplanfile->get_contextid(),
107        $testplanfile->get_component(),
108        $testplanfile->get_filearea(),
109        $testplanfile->get_itemid(),
110        $testplanfile->get_filepath(),
111        $testplanfile->get_filename()
112    ) .
113    PHP_EOL .
114    moodle_url::make_pluginfile_url(
115        $usersfile->get_contextid(),
116        $usersfile->get_component(),
117        $usersfile->get_filearea(),
118        $usersfile->get_itemid(),
119        $usersfile->get_filepath(),
120        $usersfile->get_filename()
121    ) .
122    PHP_EOL;
Note: See TracBrowser for help on using the repository browser.