fix(set_ode): make online SCORM package replacement idempotent#57
fix(set_ode): make online SCORM package replacement idempotent#57eXeLearningProject merged 2 commits intomainfrom
Conversation
set_ode.php now performs a targeted delete of the existing package at itemid 0 before storing the new file (instead of wiping the whole filearea), records timemodified together with the new reference, and relies on exescorm_parse() to refresh content/version. This mirrors the embedded editor save flow and prevents stale package files from being left behind when an online save replaces an existing package. Adds an integration test exercising the package replacement to guard against regressions of the symptom described in #55.
ignaciogros
left a comment
There was a problem hiding this comment.
The issue might be in eXeLearning:
- Open eXeLearning online and add an image
x.png. - Export as SCORM: the image is placed in
content/resources/x.pngand is correctly referenced in the HTML. Example:<img src="content/resources/x.png">.
But if instead of downloading you click on "Finish" to publish to Moodle, and download the generated content (the SCORM .zip file), you'll see that the content/resources folder does not exist, and the image is not correctly referenced in the HTML. Example: <img src="content/resources/f4c4e81d-c0a6-be4a-c26e-4082c34b08aa.png"> (instead of x.png).
|
Follow-up: the actual root cause (broken images served by Moodle when content comes from the Finish to Moodle path) lives on the eXeLearning side and is fixed in:
The client now flushes pending assets to the server before triggering This Moodle-side PR (#57) keeps the package replacement idempotent during online saves, complementing that fix. |
Summary
Complements exelearning/exelearning#1740 (which fixes the visible 404 on
content/resources/<uuid>.<ext>by generating the SCORM package in the browser). This PR fixes a separate Moodle-side robustness bug surfaced while investigating mod_exescorm#55: replacing a SCORM package viaset_ode.phpwas not idempotent and could leave the activity broken if the operation failed mid-way.Root cause
set_ode.phppreviously wiped the entire package filearea before writing the new file (delete_area_files(...'package')) and never updatedtimemodified. While that worked for the happy path, it left the activity in a half-broken state if anything between the deletion andexescorm_parse()failed: no package on disk, but the DB row still pointed at the (now missing) reference.In addition, the lack of a
timemodifiedupdate meant downstream code couldn't tell when the package was last refreshed via online save.Changes
set_ode.phpdelete_area_files()with a targeted delete of the files atitemid 0so we only drop the entry that the new file would collide with, keeping the operation reversible if it bails out below.$exescorm->timemodified = time()together with the new reference so the activity advances in lockstep with the file replacement.itemid 0and thatexescorm_parse()reads from the package filearea using$exescorm->reference.tests/online_save_test.php(new)referencecolumn matches it.Relationship to mod_exescorm#55
The 404 on
content/resources/<uuid>.<ext>reported in #55 is fixed on the eXeLearning side by exelearning/exelearning#1740 — the SCORM package is now generated in the browser (where the live Y.Doc and IndexedDB asset blobs are), andBaseExporter.addAssetsToZipWithResourcePathalso writes each asset under its<assetId><ext>literal path so any stale URL still resolves.This PR does not make that symptom go away on its own. It addresses a separate Moodle-side robustness issue: making the package-replacement step idempotent so a partial failure no longer leaves the activity pointing at a missing file, and so the package filearea always ends with exactly one entry matching the activity's
reference.Refs: mod_exescorm#55, exelearning/exelearning#1740
Test plan
composer test/ docker test target).Moodle Playground Preview
The changes in this pull request can be previewed and tested using a Moodle Playground instance.