ewallah / moodle-availability_relativedate

Relative dates in Moodle
https://moodle.org/plugins/availability_relativedate
GNU General Public License v3.0
8 stars 7 forks source link

Fixed error where course module would not be set and would try to get id #20

Closed AraPraxis closed 1 year ago

AraPraxis commented 1 year ago

Hello @ewallah

I found a bug, as you've seen too, that when updating the modules $this->cmid would be set instead of $this->relativecoursemodule - The main problem there was that if it was possible for an activity to rely on a non-existing activity, it would throw an error, cause it could not find the course module. But that is now fixed with your latest update.

How to replicate current error I'm still experiencing;

  1. Create a courses (C1)
  2. Create 2 activities in C1 (A1 & A2) 2.1. Give A2 a restrict access on A1 using "After completion of activity"
  3. Backup course C1 only with the activity A2
  4. Restore course as a new course

This should throw an error, since the course module should have a valid id. This PR should fix that problem, and instead of an error just shows the activity as missing.

I've hereto updated tests to test on all the 7 different cases that can happen, hereto for their debug string. Also updated a test, that had no assertions.

Thank you for looking at this!

Kind regards, Anders Rasmussen

ewallah commented 1 year ago

THX for the report and the proposed changes.

I detected a related error when testing using php8.2 and fixed this by changing the cmid into relativecoursemodule.

Give me some time to detect if your solution does the job.

ewallah commented 1 year ago

Merged into main. THX for your contribution!