Repository navigation
Don't increment id's when editing reports #41 - #44
Open
brendanheywood wants to merge 1 commit into
Open
brendanheywood wants to merge 1 commit into
brendanheywood wants to merge 1 commit into
Conversation
brendanheywood
force-pushed
the
renames
branch
2 times, most recently
from
November 17, 2026 06:10
7588dd3 to
ffbf3b3
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
SQL edits can bypass approval, remove row-level restrictions, and leave report audiences or rollback state inconsistent, creating critical data-exposure risks.
6 open issues
Require approval before ordinary saves republish live SQL · New Preserve and validate row scoping when republishing · New Restore the full prior query state after a failed rebuild · New Drop the rejected view before restoring the original on PostgreSQL · New Reapply visibility to every preserved report binding · New Purge hidden per-user columns and their saved references · New
What changed in this PR
This PR changes published SQL-query editing to preserve existing Moodle Report Builder report IDs, keeping report links and embeds stable.
Changes:
- Rebuilds the query view while retaining bound reports and removing references to deleted columns.
- Adds recovery logic and tests for successful edits and invalid SQL.
- Increments the plugin release and version.
| File | Description |
|---|---|
version.php |
Bumps release and version to 2026091013. |
tests/query_test.php |
Tests report preservation, column cleanup and invalid-SQL recovery. |
classes/local/query.php |
Adds automatic republishing and recovery while preserving report IDs. |
Review effort: Balanced
| // SQL change while published: rebuild the view in place and keep the report (and its id, audiences, | ||
| // filters and blocks) so that existing links and embeds keep working. Columns that no longer exist | ||
| // are removed from the report by republish(). | ||
| if ($existing->status === self::STATUS_PUBLISHED && $existing->querysql !== $sql) { |
Comment on lines
+686
to
+687
| try { | ||
| self::get((int) $record->id)->republish(); |
| self::get((int) $record->id)->republish(); | ||
| } catch (\Throwable $e) { | ||
| // The new SQL can't be compiled, so restore the old SQL and view. | ||
| $DB->update_record(self::TABLE, (object) [ |
| 'pagecoursecolumn' => $existing->pagecoursecolumn, | ||
| ]); | ||
| try { | ||
| view::create_or_replace((int) $existing->id, $existing->querysql, (int) $existing->courseid); |
|
|
||
| // PostgreSQL can't rename or remove columns of an existing view with CREATE OR REPLACE. | ||
| view::drop($this->id()); | ||
| $this->publish(); |
Comment on lines
+898
to
+899
| $newcolumns = array_keys($this->columns_meta()); | ||
| foreach (array_diff($oldcolumns, $newcolumns) as $removed) { |
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.


No description provided.