Moodle

Quiz entering question IDs into backup_ids table before the backup has been executed

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.9
  • Fix Version/s: 1.9.5
  • Component/s: Backup, Quiz
  • Labels:
    None
  • Database:
    Any
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

I discovered this issue when using the backup_course_silently() function from /backup/lib.php.

The standard function quiz_check_backup_mods() from /mod/quiz/backuplib.php is actually storing question and question category IDs into the 'backup_ids' table before the backup has been executed.

The MODNAME_check_backup_mods() functions are never called during the backup_generate_preferences_artificially() function used when silently creating a backup as those standard functions seem to only be used when displaying a list of modules for inclusion / exclusion before beginning the standard backup process.

The quiz module is actually performing actions which, if not done, means that no questions or question categories are stored in the backup and if that backup is used to restore the course, any quizzes in that course will have no questions in them and none available to add to quizzes.

It seems to me like this is a bug but I haven't dug around enough into the quiz and question backup code to determine if this is something that could be considered a "necessary hack". An obvious solution is to update the backup_preferences_artificially() function but it seems to me like the quiz code is just performing backup actions in a function only meant to gather data for display in a form.

Activity

Hide
Piers Harding added a comment -

Hi -

This sounds very much in the same area that I've been looking at. If you compare backup_generate_preferences_artificially() (backup/lib.php), with the equivalent routines in the cron backup schedule_backup_course_configure() (backup/schedule_backup.php), then there is a call missing to <mod name>_check_backup_mods. This call inserts the entries in backp_ids, which primes everything up for the quiz question backup.
I'll attach a patch to demonstrate.

Cheers.

Show
Piers Harding added a comment - Hi - This sounds very much in the same area that I've been looking at. If you compare backup_generate_preferences_artificially() (backup/lib.php), with the equivalent routines in the cron backup schedule_backup_course_configure() (backup/schedule_backup.php), then there is a call missing to <mod name>_check_backup_mods. This call inserts the entries in backp_ids, which primes everything up for the quiz question backup. I'll attach a patch to demonstrate. Cheers.
Hide
Piers Harding added a comment -

Attaching a patch that demonstrates the missing call to _check_backup_mods - stable-19.

Show
Piers Harding added a comment - Attaching a patch that demonstrates the missing call to _check_backup_mods - stable-19.
Hide
Piers Harding added a comment -

Hi Eloy - I've added you as a watcher to this, as I'm not sure who would be best placed to look at backup issues - sorry if I've got that wrong.

Cheers,
Piers Harding.

Show
Piers Harding added a comment - Hi Eloy - I've added you as a watcher to this, as I'm not sure who would be best placed to look at backup issues - sorry if I've got that wrong. Cheers, Piers Harding.
Hide
Eloy Lafuente (stronk7) added a comment -

Thanks Piers, looking this right now!

Really sad (perhaps the cause is that silent backups (export) are intended to be used only by imports? I don't think so but is so strange we haven't detected this before...

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Thanks Piers, looking this right now! Really sad (perhaps the cause is that silent backups (export) are intended to be used only by imports? I don't think so but is so strange we haven't detected this before... Ciao
Hide
Eloy Lafuente (stronk7) added a comment -

Grrr!

I always get confused with those functions:

  • backup_course_silently()
  • import_backup_file_silently()

They are the ones introduced by Penny (and never used by core) long time ago and not really maintained (as export/import work using core backup itself, instead of those functions).

I guess they'll have more "peculiarities" that current bug, anyway, I'll test the fix suggested... and apply it. I hope 2.0 will have better isolated functions to be able to keep only one codebase to perform backup/restore from anywhere (scheduled, normal, import/export, silent...). Right now (1.9) it's a nightmare!

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Grrr! I always get confused with those functions:
  • backup_course_silently()
  • import_backup_file_silently()
They are the ones introduced by Penny (and never used by core) long time ago and not really maintained (as export/import work using core backup itself, instead of those functions). I guess they'll have more "peculiarities" that current bug, anyway, I'll test the fix suggested... and apply it. I hope 2.0 will have better isolated functions to be able to keep only one codebase to perform backup/restore from anywhere (scheduled, normal, import/export, silent...). Right now (1.9) it's a nightmare! Ciao
Hide
Eloy Lafuente (stronk7) added a comment -

Wow, it's missing not only module related data.... but users/roles... a lot of things... trying to add the missing bits.

Show
Eloy Lafuente (stronk7) added a comment - Wow, it's missing not only module related data.... but users/roles... a lot of things... trying to add the missing bits.
Hide
Eloy Lafuente (stronk7) added a comment -

Resolving as fixed (19_STABLE and HEAD). I've added missing pre-checks for:

  • modules, as suggested by Piers, thanks!
  • users
  • files (user/course/site)
  • role assignments

all them were missing causing backups performed by backup_course_silently() to be incomplete. I've tested one normal backup with one backup generated with the function and they are 100% equivalent. B-)

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Resolving as fixed (19_STABLE and HEAD). I've added missing pre-checks for:
  • modules, as suggested by Piers, thanks!
  • users
  • files (user/course/site)
  • role assignments
all them were missing causing backups performed by backup_course_silently() to be incomplete. I've tested one normal backup with one backup generated with the function and they are 100% equivalent. B-) Ciao
Hide
Piers Harding added a comment -

Hey thanks Eloy - that was incredibly quick! I've tested against my backup script, and it works perfectly too.
Cheers,
Piers Harding.

Show
Piers Harding added a comment - Hey thanks Eloy - that was incredibly quick! I've tested against my backup script, and it works perfectly too. Cheers, Piers Harding.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: