4848
4949// Initialise $PAGE.
5050$ nexturl = new moodle_url ('/question/type/stack/questiontestrun.php ' , $ urlparams , 'variants-pane ' );
51+ $ nexturl ->param ('hidetests ' , 1 );
5152$ PAGE ->set_url ($ nexturl ); // Since this script always ends in a redirect.
5253$ PAGE ->set_heading ($ COURSE ->fullname );
5354$ PAGE ->set_pagelayout ('popup ' );
5455
5556require_login ();
57+ // Deploying lots of variants is time consuming, and we need a progress bar in some cases.
58+ $ numforprogressbar = 10 ;
5659
5760/**
5861 * Run tests on a given seed and stop deployment if a test fails.
@@ -200,13 +203,33 @@ function testseed($question, $seed, $context, $nexturl, $numberdeployed) {
200203
201204 // Deploy all new variants.
202205 $ numberdeployed = 0 ;
206+ $ newseeds = array_diff ($ newseeds , $ question ->deployedseeds );
207+ $ deployhalt = optional_param ('deployhalt ' , null , PARAM_TEXT );
208+ $ newcount = count ($ newseeds );
209+
210+ // Output something if we need a progress bar.
211+ // (We have 10+ variants and we are running the tests.)
212+ if ($ newcount >= $ numforprogressbar && isset ($ deployhalt )) {
213+ echo $ OUTPUT ->header ();
214+ flush ();
215+ $ a = ['total ' => $ newcount , 'done ' => 0 ];
216+ $ progressevery = (int ) min (max (1 , $ newcount / 500 ), 100 );
217+ $ pbar = new progress_bar ('deployedprogress ' , 500 , true );
218+ }
219+
203220 foreach ($ newseeds as $ seed ) {
204- if (!in_array ($ seed , $ question ->deployedseeds )) {
205- testseed ($ question , $ seed , $ context , $ nexturl , $ numberdeployed );
206- $ question ->deploy_variant ($ seed );
207- $ numberdeployed ++;
221+ testseed ($ question , $ seed , $ context , $ nexturl , $ numberdeployed );
222+ $ question ->deploy_variant ($ seed );
223+ $ numberdeployed ++;
224+ if ($ newcount >= $ numforprogressbar && isset ($ deployhalt )) {
225+ $ a ['done ' ] += 1 ;
226+ if ($ a ['done ' ] % $ progressevery == 0 || $ a ['done ' ] == $ a ['total ' ]) {
227+ core_php_time_limit::raise (60 );
228+ $ pbar ->update ($ a ['done ' ], $ a ['total ' ], get_string ('deployedprogress ' , 'qtype_stack ' , $ a ));
229+ }
208230 }
209231 }
232+ $ nexturl ->param ('deployfeedback ' , stack_string ('deploymanysuccess ' , ['no ' => $ numberdeployed ]));
210233 redirect ($ nexturl );
211234}
212235
@@ -216,8 +239,7 @@ function testseed($question, $seed, $context, $nexturl, $numberdeployed) {
216239// The number of seconds we devote to deploying before moving on. Prevents system hangging.
217240// Note, in "safe mode" the set time limit function has no effect.
218241$ maxtime = 180 ;
219- // Deploying lots of variants is time consuming, and we need a progress bar in some cases.
220- $ numforprogressbar = 10 ;
242+
221243core_php_time_limit::raise ($ maxtime ); // Prevent PHP timeouts.
222244gc_collect_cycles (); // Because PHP's default memory management is rubbish.
223245
0 commit comments