ngandrass / moodle-quiz_archiver

Archives quiz attempts as PDF and HTML files for long-term storage independent of Moodle
GNU General Public License v3.0
5 stars 3 forks source link

There are no images in the final PDF of the student's attempt. #11

Closed bbdev2 closed 7 months ago

bbdev2 commented 8 months ago

There are no images in the final PDF of the student's attempt. I see only blank areas in that places where the images should be. I think it happens, because the rendering html contains the links to moodle's pluginfile.php which protects attempt resources.

ngandrass commented 8 months ago

Thanks for your report. Maybe this is related to your runtime environment. Let's wait for #10 :)

bbdev2 commented 8 months ago

it so happened that I created a similar private project earlier for the university, but I used only php-way without external instruments. So, this proplem isn't new for me. By this reason I wrote here about it. I solved this problem by filtering the html and replacing the links to another web-service. I think this project is more correct than mine, since it uses chromium as rendering method.

ngandrass commented 8 months ago

This plugin tries to address this issue by inlining all images encoded with base64, see: https://github.com/ngandrass/moodle-quiz_archiver/blob/a2657d161350efabb359dada12a2c9e189af9365/classes/Report.php#L654

So it seems that within your test setup some of this "inline magic" fails. Can you provide the HTML that is generated by the plugin for debugging purposes? To do so, set "Keep HTML source files" while creating an archive job. The HTML files can then be found alongside the report PDFs within the generated quiz archive.

Location of the "Keep HTML source files" setting: image

Thanks :+1:

ngandrass commented 8 months ago

See #10

500gLychee commented 7 months ago

I would like to reopen this issue. We have the same problem on Moodle Version 4.2.6 (Build: 20240212). With quiz_archiver 1.2.3 and quiz_archive_worker 1.3.2.

Here is the archive attached (containing the .html) 07_Test-Test 01-18346_2024-02-14-13-17-49.tar.gz

There should be a picture in question 4 submitted by the student and a picture in question 5´s description, indicated by the small icons.

If i print the attempt from moodle to pdf i get this: Test 01 Überprüfung des Testversuchs jku.pdf

ngandrass commented 7 months ago

Thanks for your files! :+1:

I performed a quick check of the HTML files you provided. It seems that the requests that inline images within Moodle itself fail, prior to passing the result to the quiz archive worker. https://github.com/ngandrass/moodle-quiz_archiver/blob/cf8352bcc70c119c81b1a319bdd40cb65ad893b2/classes/Report.php#L654

It produces the following error messaged (stripped down to relevant part):

      <main>
        <div>
          <h1>Error page</h1>
<p>You may be seeing this page because you used the Back button while browsing a secure web site or application. Alternatively, you may have mistakenly bookmarked the web login form instead of the actual web site you wanted to bookmark or used a link created by somebody else who made the same mistake.</p> <br/> <p>Left unchecked, this can cause errors on some browsers or result in you returning to the web site you tried to leave, so this page is presented instead.</p>          </div>
      </main>

So there seems to be some sort of problem with the access restrictions to the resource files. Tomorrow, I should find some time to look into this a little closer.

Do you have any specific access restrictions in place with your Moodle? Can you provide a Moodle backup (.mbz) of the affected quiz so that I can take a closer look? Thanks!

500gLychee commented 7 months ago

As always, thanks for the fast reply.

Attached I have the quiz.mbz. There should be a picture in question 5´s description.

test_moe1-Test 01-19213_2024-02-15-06-12-05.tar.gz

I have forwarded the question regarding restrictions on our Moodle, but I am not aware that there should be anything like that.

500gLychee commented 7 months ago

Regarding restriction what I can say already: we use only Shibboleth for the login and our Moodle is not allowed to communicate with the outside world regarding API access and such.

500gLychee commented 7 months ago

The webserver should have all rights to the moodledata files though.

ngandrass commented 7 months ago

Attached I have the quiz.mbz. There should be a picture in question 5´s description.

This seems to be the wrong file. I need either a Moodle backup (.mbz) of either the quiz or the course that contains the quiz. You uploaded a quiz archive (created by this plugin).

500gLychee commented 7 months ago

You are right, my bad, here should be the correct file.

sicherung-moodle2-activity-8837164-quiz8837164-20240215-1129.zip

ngandrass commented 7 months ago

Thanks for the file. After installing qbehaviour_deferredallnothing I was able to restore the course. Let's see what I can do :)

500gLychee commented 7 months ago

Thank you and sorry to have made it unnecessarily complicated.

ngandrass commented 7 months ago

Hmm, sadly I was not able to reproduce the error. A just now created export looks fine on my vanilla test instance...

image


I went a little deeper and tried to find the source of the error message from some posts ago. It is not part of the Moodle core. To me it looks like it is coming from your SSO/IDP, most likely being Shibboleth.

However, this is not particularly an issue on your side but a failure of the function that tries to inline all images: https://github.com/ngandrass/moodle-quiz_archiver/blob/cf8352bcc70c119c81b1a319bdd40cb65ad893b2/classes/Report.php#L654

The problem is most likely related to the way in which Moodle builds its "pluginfile URLs". The function in this plugin currently is very strict with that it tries to load from the local Moodle storage to prevent exploitation. I'll try to debug this a little further and make the image handling routine a little more resilient.

This, however, could take some time. I'd reach back to you here once I got a test version ready. Would you be willing to install a development version to validate if changes fixes your problems?

Thanks in advance! :)

500gLychee commented 7 months ago

Thank you. You mean a dev version of the quiz_archiver? Yes we can do that.

ngandrass commented 7 months ago

Thank you. You mean a dev version of the quiz_archiver? Yes we can do that.

Exactly, yes. I'd create a development release which can be fully upgraded to the following stable release once everything works :)

ngandrass commented 7 months ago

@500gLychee I still was not able to reproduce the problem. Therefore, I now published a development release that includes additional debug information from the image inlining process into the generated HTML files. It also includes a small fix for local Moodle files that, however, is unlikely to solve your problem straight away.

At this point I need your help. Please:

  1. Upgrade your quiz_archiver Moodle plugin to version 1.2.3-dev+2024021500 (2024021500)
  2. Create a new quiz archive, including HTML files
  3. Upload the generated quiz archive .tar.gz file here

Thank you! :)

500gLychee commented 7 months ago

Thanks, we will update and I will come back tomorrow with how it worked.

500gLychee commented 7 months ago

That actually already did it. We testet on a different Moodle, but it should have the same settings. Testing later again on the same Moodle as yesterday.

Here is the full quiz_archive (.mbz should be inside this time). I made a new attempt with 2 pictures, both are included in the pdf file.
Test Martin-Test 01-12_2024-02-16-10-20-56.tar.gz

Thanks so much! 💯

500gLychee commented 7 months ago

On the same Moodle as yesterday it is not working. Here the quiz_archive and the Moodle backup: sicherung-moodle2-activity-8837164-quiz8837164-20240216-0906.zip 07_Test-Test 01-18346_2024-02-16-10-11-29.tar.gz

ngandrass commented 7 months ago

Thanks for testing. I think I got something. Is the following correct?

  1. The Moodle, on which the archiving works, is located directly under: https://yourdomain.example/
  2. The Moodle, on which the archiving does not work, is located in a separate folder/path: https://yourdomain.example/mymoodle/

I think the regular expression that detects the resource types, based on the given URLs, fails for the latter case.

500gLychee commented 7 months ago

I think you are right on the money.

The moodle wich works is like

The not working one is like

ngandrass commented 7 months ago

Yeah, perfect. I should be able to create a fix candidate around next Monday (currently busy with other stuff), so that you can test if that solves the problem on your "nested" Moodle.

500gLychee commented 7 months ago

That would be awesome, many thanks. :)

ngandrass commented 7 months ago

And here comes the promised test version that hopefully fixes your problem :)

Please:

  1. Upgrade your quiz_archiver Moodle plugin to version 1.2.3-dev+2024021900 (2024021900)
  2. Create a new quiz archive, including HTML files
  3. Upload the generated quiz archive .tar.gz file here

Thank you!

If everything works I'll create an official release (v1.2.4) :tada:

LisaE14 commented 7 months ago

Many thanks for the quick fix. It works now. 07_Test-Test 01-18346_2024-02-19-14-22-57.tar.gz

ngandrass commented 7 months ago

Perfect. I'm glad to hear that your issue is fixed. I'll close this for now, but feel free to re-open it if you encounter further problems :+1:

I'll also release a new version of the plugin today. You can just upgrade your dev version once the v1.2.4 release is out :)