Fix: accept both 'course' and 'cm' keys in __construct() - for backwards compatibility#51
Open
michael-milette wants to merge 1 commit intoModernLMS:masterfrom
Open
Fix: accept both 'course' and 'cm' keys in __construct() - for backwards compatibility#51michael-milette wants to merge 1 commit intoModernLMS:masterfrom
michael-milette wants to merge 1 commit intoModernLMS:masterfrom
Conversation
…s compatibility Commit 69e5c26 updated save() to output 'course' but did not update __construct() which still read 'cm', causing a coding_exception on every load after save. The constructor now accepts 'course' (post-69e5c26 DB data) and falls back to 'cm' (pre-69e5c26 DB data). No database migration required — data self-heals on next save. Fixes ModernLMS#38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Commit 69e5c26 (fix #38) for issue #22 (Fixed course condition when duplicating an activity) introduced a save/load key mismatch that silently breaks all conditions saved after that commit.
Root cause
In classes\condition.php,
save()andget_json()were updated to output the JSON key'course', but__construct()was never updated — it still reads$structure->cm:Effect
Any availability condition saved after commit 69e5c26 throws a coding_exception when Moodle reloads it from the database, making the condition permanently unresolvable.
Fix
In __construct(), change the key read from 'cm' to 'course' to match save(). A DB migration is NOT required if __construct() is updated to accept both keys:
Data will now self-heal on the next save.
This also fixes related JavaScript and phpUnit test references, changing 'cm' to 'course'.
Affected versions
All releases from commit 69e5c26 (2024-02-02) onwards.
Let me know if you have any questions or need any changes.
Best regards,
Michael Milette