MDL-75334 mod_bigbluebuttonbn: Generate course with BigblueButtonBN

* Use a new generator to create a course full of BigblueButton Activities
in order to check for performances with a lot of activities
This commit is contained in:
Laurent David 2022-07-21 19:11:31 -04:00
parent 794f107e88
commit 7af38677b6
9 changed files with 99 additions and 12 deletions

View File

@ -122,11 +122,13 @@ abstract class tool_generator_backend {
/**
* Displays information as part of progress.
*
* @param string $langstring Part of langstring (after progress_)
* @param mixed $a Optional lang string parameters
* @param bool $leaveopen If true, doesn't close LI tag (ready for dots)
* @param string $module module for language string
*/
protected function log($langstring, $a = null, $leaveopen = false) {
public function log(string $langstring, $a = null, bool $leaveopen = false, string $module = 'tool_generator'): void {
if (!$this->progress) {
return;
}
@ -135,7 +137,7 @@ abstract class tool_generator_backend {
} else {
echo html_writer::start_tag('li');
}
echo get_string('progress_' . $langstring, 'tool_generator', $a);
echo get_string('progress_' . $langstring, $module, $a);
if (!$leaveopen) {
if (CLI_SCRIPT) {
echo "\n";
@ -153,10 +155,11 @@ abstract class tool_generator_backend {
/**
* Outputs dots. There is up to one dot per second. Once a minute, it
* displays a percentage.
*
* @param int $number Number of completed items
* @param int $total Total number of items to complete
*/
protected function dot($number, $total) {
public function dot(int $number, int $total): void {
if (!$this->progress) {
return;
}
@ -184,7 +187,7 @@ abstract class tool_generator_backend {
/**
* Ends a log string that was started using log function with $leaveopen.
*/
protected function end_log() {
public function end_log(): void {
if (!$this->progress) {
return;
}
@ -195,5 +198,4 @@ abstract class tool_generator_backend {
echo html_writer::end_tag('li');
}
}
}

View File

@ -78,6 +78,10 @@ class tool_generator_course_backend extends tool_generator_backend {
*/
private static $paramforumposts = array(2, 2, 5, 10, 10, 10);
/**
* @var array Number of assignments in course
*/
private static $paramactivities = array(1, 10, 100, 500, 1000, 2000);
/**
* @var string Course shortname
*/
@ -113,6 +117,10 @@ class tool_generator_course_backend extends tool_generator_backend {
*/
private $userids;
/**
* @var array $additionalmodules
*/
private $additionalmodules;
/**
* Constructs object ready to create course.
*
@ -121,6 +129,7 @@ class tool_generator_course_backend extends tool_generator_backend {
* @param bool $fixeddataset To use fixed or random data
* @param int|bool $filesizelimit The max number of bytes for a generated file
* @param bool $progress True if progress information should be displayed
* @param array $additionalmodules potential additional modules to be added (quiz, bigbluebutton...)
*/
public function __construct(
$shortname,
@ -130,7 +139,9 @@ class tool_generator_course_backend extends tool_generator_backend {
$progress = true,
$fullname = null,
$summary = null,
$summaryformat = FORMAT_HTML) {
$summaryformat = FORMAT_HTML,
$additionalmodules = []
) {
// Set parameters.
$this->shortname = $shortname;
@ -153,7 +164,7 @@ class tool_generator_course_backend extends tool_generator_backend {
$this->summary = $summary;
$this->summaryformat = $summaryformat;
}
$this->additionalmodules = $additionalmodules;
parent::__construct($size, $fixeddataset, $filesizelimit, $progress);
}
@ -231,6 +242,16 @@ class tool_generator_course_backend extends tool_generator_backend {
$this->create_users();
$this->create_forum();
// Let plugins hook into user settings navigation.
$pluginsfunction = get_plugins_with_function('course_backend_generator_create_activity');
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginname => $pluginfunction) {
if (in_array($pluginname, $this->additionalmodules)) {
$pluginfunction($this, $this->generator, $this->course->id, self::$paramactivities[$this->size]);
}
}
}
// Log total time.
$this->log('coursecompleted', round(microtime(true) - $entirestart, 1));
@ -537,7 +558,7 @@ class tool_generator_course_backend extends tool_generator_backend {
*
* @return int A section number from 1 to the number of sections
*/
private function get_target_section() {
public function get_target_section() {
if (!$this->fixeddataset) {
$key = rand(1, self::$paramsections[$this->size]);
@ -586,5 +607,4 @@ class tool_generator_course_backend extends tool_generator_backend {
return $length;
}
}

View File

@ -57,6 +57,24 @@ class tool_generator_make_course_form extends moodleform {
$mform->addElement('editor', 'summary', get_string('coursesummary'));
$mform->setType('summary', PARAM_RAW);
$additionalmodules = [];
$pluginsfunction = get_plugins_with_function('course_backend_generator_create_activity');
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $pluginname => $pluginfunction) {
$additionalmodules[$pluginname] = get_string("pluginname", "{$plugintype}_{$pluginname}");
}
}
$mform->addElement('autocomplete', 'additionalmodules',
get_string('additionalmodules', 'tool_generator'),
$additionalmodules,
[
'multiple' => true,
'noselectionstring' => get_string('noselection', 'form')
]
);
$mform->addHelpButton('additionalmodules', 'additionalmodules', 'tool_generator');
$mform->setType('additionalmodules', PARAM_ALPHAEXT);
$mform->addElement('submit', 'submit', get_string('createcourse', 'tool_generator'));
}

View File

@ -39,6 +39,7 @@ list($options, $unrecognized) = cli_get_params(
'fixeddataset' => false,
'filesizelimit' => false,
'bypasscheck' => false,
'additionalmodules' => "",
'quiet' => false
),
array(
@ -62,6 +63,8 @@ Options:
--fixeddataset Use a fixed data set instead of randomly generated data
--filesizelimit Limits the size of the generated files to the specified bytes
--bypasscheck Bypasses the developer-mode check (be careful!)
--additionalmodules Additional modules to be created when creating a course: a comma separated modules names without the mod_prefix
(like quiz, forum...)
--quiet Do not show any output
-h, --help Print out this help
@ -100,7 +103,10 @@ if ($error = tool_generator_course_backend::check_shortname_available($shortname
// Switch to admin user account.
\core\session\manager::set_user(get_admin());
$additionalmodulesarray = [];
if (!empty($options['additionalmodules'])) {
$additionalmodulesarray = explode(',', trim($options['additionalmodules']));
}
// Do backend code to generate course.
$backend = new tool_generator_course_backend(
$shortname,
@ -110,7 +116,8 @@ $backend = new tool_generator_course_backend(
empty($options['quiet']),
$fullname,
$summary,
FORMAT_HTML
FORMAT_HTML,
$additionalmodulesarray
);
$id = $backend->make();

View File

@ -47,6 +47,9 @@ $string['coursesize_2'] = 'M (~100MB; create in ~2 minutes)';
$string['coursesize_3'] = 'L (~1GB; create in ~30 minutes)';
$string['coursesize_4'] = 'XL (~10GB; create in ~2 hours)';
$string['coursesize_5'] = 'XXL (~20GB; create in ~4 hours)';
$string['additionalmodules'] = 'Additional modules';
$string['additionalmodules_help'] = 'We normally create standard modules in the course (like forum, page or label),
but you can select any other module that implements the course_backend_generator_create_activity function.';
$string['coursewithoutusers'] = 'The selected course has no users';
$string['createcourse'] = 'Create course';
$string['createtestplan'] = 'Create test plan';

View File

@ -62,7 +62,8 @@ if ($data = $mform->get_data()) {
true,
$data->fullname,
$data->summary['text'],
$data->summary['format']
$data->summary['format'],
$data->additionalmodules
);
$id = $backend->make();

View File

@ -1,6 +1,13 @@
This files describes API changes in core libraries and APIs,
information provided here is intended especially for developers.
=== 4.2 ===
* Any activity module (mod) that declares the 'xxx_course_backend_generator_create_activity' function in lib.php will now be able to create instance of the
module in the test course. There is now an additional parameter to the admin/tool/generator/cli/maketestcourse.php command so we can whitelist all the modules
that need to be added to the course via the additionalmodules parameter.
See bigbluebuttonbn_course_backend_generator_create_activity as an example.
=== 4.0 ===
* Function tool_generator_testplan_backend::create_users_file() now supports to pass the size of the testing plan,

View File

@ -420,6 +420,7 @@ $string['mod_form_locksettings'] = 'Lock settings';
$string['report_join_info'] = '{$a} meeting(s)';
$string['report_play_recording_info'] = '{$a} recording(s) played';
$string['report_room_view'] = 'viewed';
$string['progress_createbigbluebuttonbn'] = 'Creating BigBlueButton activity ({$a})';
$string['starts_at'] = 'Starts';
$string['started_at'] = 'Started';
$string['ends_at'] = 'Ends';

View File

@ -740,3 +740,31 @@ function bigbluebuttonbn_pre_enable_plugin_actions(): bool {
// Otherwise, continue and enable the plugin.
return true;
}
/**
* Creates a number of BigblueButtonBN activities.
*
* @param tool_generator_course_backend $backend
* @param testing_data_generator $generator
* @param int $courseid
* @param int $number
* @return void
*/
function bigbluebuttonbn_course_backend_generator_create_activity(tool_generator_course_backend $backend,
testing_data_generator $generator,
int $courseid,
int $number
) {
// Set up generator.
$bbbgenerator = $generator->get_plugin_generator('mod_bigbluebuttonbn');
// Create assignments.
$backend->log('createbigbluebuttonbn', $number, true, 'mod_bigbluebuttonbn');
for ($i = 0; $i < $number; $i++) {
$record = array('course' => $courseid);
$options = array('section' => $backend->get_target_section());
$bbbgenerator->create_instance($record, $options);
$backend->dot($i, $number);
}
$backend->end_log();
}