From f1a45863eda25593e32616e8804487051d9836f6 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Mon, 11 Dec 2023 10:39:01 -0600 Subject: [PATCH] Make the PG problem editor always regenerate dynamic images. Currently if a problem that uses dynamically generated images is edited and the code for generated an image changes the image is not regenerated unless you force it by adding `$refreshCachedImages = 1` to the problem itself. This is problematic as an author may forget to remove that later which can cause unneeded image regeneration in production use. The problem editor now forces image generation by setting `refreshCachedImages` in the PG environment. For this to work a minor change is needed to PG. --- htdocs/js/PGProblemEditor/pgproblemeditor.js | 3 +++ lib/WeBWorK/Utils/Rendering.pm | 17 +++++++++-------- lib/WebworkWebservice/RenderProblem.pm | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/htdocs/js/PGProblemEditor/pgproblemeditor.js b/htdocs/js/PGProblemEditor/pgproblemeditor.js index 144d149e59..03e60ad537 100644 --- a/htdocs/js/PGProblemEditor/pgproblemeditor.js +++ b/htdocs/js/PGProblemEditor/pgproblemeditor.js @@ -278,6 +278,7 @@ requestData.set('send_pg_flags', 1); requestData.set(button.name, button.value); requestData.set('set_id', document.getElementsByName('hidden_set_id')[0]?.value ?? 'Unknown Set'); + requestData.set('refreshCachedImages', 1); renderProblem(requestData); @@ -357,6 +358,7 @@ showFooter: 0, displayMode: document.getElementById('action_view_displayMode_id')?.value ?? 'MathJax', language: document.querySelector('input[name="hidden_language"]')?.value ?? 'en', + refreshCachedImages: 1, send_pg_flags: 1, view_problem_debugging_info: 1 })).then(() => resolve()); @@ -444,6 +446,7 @@ noprepostambles: 1, processAnswers: 1, displayMode: 'tex', + refreshCachedImages: 1, view_problem_debugging_info: 1 }) }); diff --git a/lib/WeBWorK/Utils/Rendering.pm b/lib/WeBWorK/Utils/Rendering.pm index 60df75e5b0..c1ed0b8cab 100644 --- a/lib/WeBWorK/Utils/Rendering.pm +++ b/lib/WeBWorK/Utils/Rendering.pm @@ -57,14 +57,15 @@ sub constructPGOptions ($ce, $user, $set, $problem, $psvn, $formFields, $transla $options{problemSeed} = $problem->problem_seed; # Display information - $options{displayMode} = $translationOptions->{displayMode}; - $options{showHints} = $translationOptions->{showHints}; - $options{showSolutions} = $translationOptions->{showSolutions}; - $options{forceScaffoldsOpen} = $translationOptions->{forceScaffoldsOpen}; - $options{setOpen} = time > $set->open_date; - $options{pastDue} = time > $set->due_date; - $options{answersAvailable} = time > $set->answer_date; - $options{refreshMath2img} = $translationOptions->{refreshMath2img}; + $options{displayMode} = $translationOptions->{displayMode}; + $options{showHints} = $translationOptions->{showHints}; + $options{showSolutions} = $translationOptions->{showSolutions}; + $options{forceScaffoldsOpen} = $translationOptions->{forceScaffoldsOpen}; + $options{setOpen} = time > $set->open_date; + $options{pastDue} = time > $set->due_date; + $options{answersAvailable} = time > $set->answer_date; + $options{refreshMath2img} = $translationOptions->{refreshMath2img}; + $options{refreshCachedImages} = $translationOptions->{refreshCachedImages}; # Default values for evaluating answers $options{ansEvalDefaults} = $ce->{pg}{ansEvalDefaults}; diff --git a/lib/WebworkWebservice/RenderProblem.pm b/lib/WebworkWebservice/RenderProblem.pm index f039322613..cf09aa725c 100644 --- a/lib/WebworkWebservice/RenderProblem.pm +++ b/lib/WebworkWebservice/RenderProblem.pm @@ -217,7 +217,8 @@ async sub renderProblem { showHints => $rh->{showHints}, showSolutions => $rh->{showSolutions}, refreshMath2img => $rh->{showHints} || $rh->{showSolutions}, - processAnswers => $rh->{processAnswers} // 1, + refreshCachedImages => $rh->{refreshCachedImages} // 0, + processAnswers => $rh->{processAnswers} // 1, catchWarnings => 1, r_source => $r_problem_source, problemUUID => $rh->{problemUUID} // 0,