/** * Checks that the submitted data allows us to create a test plan. * * @param array $data * @param array $files * @return array An array of errors */ public function validation($data, $files) { global $CFG; $errors = array(); if (empty($CFG->tool_generator_users_password) || is_bool($CFG->tool_generator_users_password)) { $errors['updateuserspassword'] = get_string('error_nouserspassword', 'tool_generator'); } // Better to repeat here the query than to do it afterwards and end up with an exception. if ($courseerrors = tool_generator_testplan_backend::has_selected_course_any_problem($data['courseid'], $data['size'])) { $errors = array_merge($errors, $courseerrors); } return $errors; }
} // Check debugging is set to developer level. if (empty($options['bypasscheck']) && !debugging('', DEBUG_DEVELOPER)) { cli_error(get_string('error_notdebugging', 'tool_generator')); } // Get options. $shortname = $options['shortname']; $sizename = $options['size']; // Check size. try { $size = tool_generator_testplan_backend::size_for_name($sizename); } catch (coding_exception $e) { cli_error("Error: Invalid size ({$sizename}). Use --help for help."); } // Check selected course. if ($errors = tool_generator_testplan_backend::has_selected_course_any_problem($shortname, $size)) { // Showing the first reported problem. cli_error("Error: " . reset($errors)); } // Checking if test users password is set. if (empty($CFG->tool_generator_users_password) || is_bool($CFG->tool_generator_users_password)) { cli_error("Error: " . get_string('error_nouserspassword', 'tool_generator')); } // Switch to admin user account. session_set_user(get_admin()); // Create files. $courseid = $DB->get_field('course', 'id', array('shortname' => $shortname)); $usersfile = tool_generator_testplan_backend::create_users_file($courseid, !empty($options['updateuserspassword'])); $testplanfile = tool_generator_testplan_backend::create_testplan_file($courseid, $size); // One file path per line so other CLI scripts can easily parse the output. echo moodle_url::make_pluginfile_url($testplanfile->get_contextid(), $testplanfile->get_component(), $testplanfile->get_filearea(), $testplanfile->get_itemid(), $testplanfile->get_filepath(), $testplanfile->get_filename()) . PHP_EOL . moodle_url::make_pluginfile_url($usersfile->get_contextid(), $usersfile->get_component(), $usersfile->get_filearea(), $usersfile->get_itemid(), $usersfile->get_filepath(), $usersfile->get_filename()) . PHP_EOL;