Skip to content
Snippets Groups Projects
Commit 39c59e0c authored by Chris Sangwin's avatar Chris Sangwin Committed by Chris Sangwin
Browse files

Auto-deploy in place.

parent 0117b4bf
No related branches found
No related tags found
No related merge requests found
...@@ -70,4 +70,79 @@ if (!is_null($undeploy)) { ...@@ -70,4 +70,79 @@ if (!is_null($undeploy)) {
redirect($nexturl); redirect($nexturl);
} }
$deploy = optional_param('deploymany', null, PARAM_INT);
$deploytxt = optional_param('deploymany', null, PARAM_TEXT);
if (!is_null($deploy)) {
if (0==$deploy) {
$nexturl->param('deployfeedbackerr', stack_string('deploymanyerror', array('err'=>$deploytxt)));
redirect($nexturl);
}
$maxfailedattempts = 3;
$failedattempts = 0;
$numberdeployed = 0;
while($failedattempts<$maxfailedattempts and $numberdeployed<$deploy) {
// Genrate a new seed
$seed = mt_rand();
$variantdeployed = false;
// Reload the question to ensure any new deployed version is included.
$question = question_bank::load_question($questionid);
$question->seed = (int) $seed;
$quba = question_engine::make_questions_usage_by_activity('qtype_stack', $context);
$quba->set_preferred_behaviour('adaptive');
$slot = $quba->add_question($question, $question->defaultmark);
$quba->start_question($slot);
foreach ($question->deployedseeds as $key => $deployedseed) {
$qn = question_bank::load_question($questionid);
$qn->seed = (int) $deployedseed;
$cn = $qn->get_context();
$qunote = question_engine::make_questions_usage_by_activity('qtype_stack', $cn);
$qunote->set_preferred_behaviour('adaptive');
$slotnote = $qunote->add_question($qn, $qn->defaultmark);
$qunote->start_question($slotnote);
// Check if the question note has already been deployed.
if ($qn->get_question_summary() == $question->get_question_summary()) {
$variantdeployed = true;
$failedattempts++;
}
}
if (!$variantdeployed) {
// Load the list of test cases.
$testscases = question_bank::get_qtype('stack')->load_question_tests($question->id);
// Exectue the tests.
$testresults = array();
$allpassed = true;
foreach ($testscases as $key => $testcase) {
$testresults[$key] = $testcase->test_question($quba, $question, $seed);
if (!$testresults[$key]->passed()) {
$nexturl->param('seed', $seed);
$nexturl->param('deployfeedback', stack_string('deploymanysuccess', array('no'=>$numberdeployed)));
$nexturl->param('deployfeedbackerr', stack_string('stackInstall_testsuite_fail'));
redirect($nexturl); redirect($nexturl);
}
}
// Actually deploy the question.
$record = new stdClass();
$record->questionid = $question->id;
$record->seed = $seed;
$DB->insert_record('qtype_stack_deployed_seeds', $record);
$numberdeployed++;
}
}
$nexturl->param('deployfeedback', stack_string('deploymanysuccess', array('no'=>$numberdeployed)));
$nexturl->param('seed', $seed);
if ($failedattempts>=$maxfailedattempts) {
$nexturl->param('deployfeedbackerr', stack_string('deploymanynonew'));
}
redirect($nexturl);
}
...@@ -314,6 +314,11 @@ $string['testingquestion'] = 'Testing question {$a}'; ...@@ -314,6 +314,11 @@ $string['testingquestion'] = 'Testing question {$a}';
$string['testinputs'] = 'Test inputs'; $string['testinputs'] = 'Test inputs';
$string['testthisvariant'] = 'Switch to test this variant'; $string['testthisvariant'] = 'Switch to test this variant';
$string['undeploy'] = 'Un-deploy'; $string['undeploy'] = 'Un-deploy';
$string['deploymany'] = 'Attempt to automatically deploy the following number of variants:';
$string['deploymanynotes'] = 'Note, STACK will give up if there are 3 failed attempts to generate a new question note, or when one question test fails.';
$string['deploymanyerror'] = 'Error in user input: cannot deploy "{$a->err}" variants.';
$string['deploymanynonew'] = 'Too many repeated existing question notes were generated.';
$string['deploymanysuccess'] = 'Number of new variants successfully created, tested and deployed: {$a->no}.';
// Support scripts (CAS chat, healthcheck, etc.) // Support scripts (CAS chat, healthcheck, etc.)
$string['all'] = 'All'; $string['all'] = 'All';
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Stack. If not, see <http://www.gnu.org/licenses/>. // along with STACK. If not, see <http://www.gnu.org/licenses/>.
/** /**
* This script lets the user test a question using any question tests defined * This script lets the user test a question using any question tests defined
...@@ -94,6 +94,15 @@ foreach ($testscases as $key => $testcase) { ...@@ -94,6 +94,15 @@ foreach ($testscases as $key => $testcase) {
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->heading($title); echo $OUTPUT->heading($title);
$deployfeedback = optional_param('deployfeedback', null, PARAM_TEXT);
if (!is_null($deployfeedback)) {
echo html_writer::tag('p', $deployfeedback, array('class' => 'overallresult pass'));
}
$deployfeedbackerr = optional_param('deployfeedbackerr', null, PARAM_TEXT);
if (!is_null($deployfeedbackerr)) {
echo html_writer::tag('p', $deployfeedbackerr, array('class' => 'overallresult fail'));
}
// Display the list of deployed variants, with UI to edit the list. // Display the list of deployed variants, with UI to edit the list.
echo $OUTPUT->heading(get_string('deployedvariants', 'qtype_stack'), 3); echo $OUTPUT->heading(get_string('deployedvariants', 'qtype_stack'), 3);
...@@ -188,6 +197,24 @@ if ($question->has_random_variants()) { ...@@ -188,6 +197,24 @@ if ($question->has_random_variants()) {
echo html_writer::end_tag('p'); echo html_writer::end_tag('p');
echo html_writer::end_tag('form'); echo html_writer::end_tag('form');
// Deploy many variants
if ($canedit) {
echo html_writer::start_tag('form', array('method' => 'get', 'class' => 'deploymany',
'action' => new moodle_url('/question/type/stack/deploy.php', $urlparams)));
echo html_writer::start_tag('p');
echo html_writer::input_hidden_params($PAGE->url, array('seed'));
echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
echo html_writer::tag('label', get_string('deploymany', 'qtype_stack'));
echo ' ' . html_writer::empty_tag('input', array('type' => 'text', 'size' => 4,
'id' => 'deploymanyfield', 'name' => 'deploymany', 'value' => ''));
echo ' ' . html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go')));
echo html_writer::tag('label', ' '.get_string('deploymanynotes', 'qtype_stack'));
echo html_writer::end_tag('p');
echo html_writer::end_tag('form');
}
} }
// Display the question. // Display the question.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment