Skip to content

Migrate Configurable Reports blocks to SQL report list blocks - #8

Merged
matthewhilton merged 5 commits into
MOODLE_405_STABLEfrom
bcr-to-bsqlr
Dec 3, 2026
Merged

matthewhilton merged 5 commits into
MOODLE_405_STABLEfrom
bcr-to-bsqlr

Conversation

@keevan

@keevan keevan commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #9

Moves the Configurable Reports (BCR) block migration out of report_sql (catalyst/moodle-report_sql#53) into this plugin, as suggested in review there.

What it does

Replaces every block_configurable_reports block with a block_sqlreports block in "List of reports" mode, from database rows only (no BCR code required).

Carried over as-is:

  • placement: context, "show in subcontexts", page type and sub-page patterns, default region and weight;
  • per-page hidden/shown state (block_positions) and per-user collapsed/docked state;
  • the moodle/block:view and moodle/block:edit permission overrides;
  • the title (BCR's default title is dropped) and the global/course switches, as "Show site reports" and "Show course reports".

Each block is migrated in its own transaction. A failure leaves that block unchanged and the rest go ahead. Re-running is safe.

How to use

  • Admin page: Site administration > Plugins > Blocks > SQL report, then the migration link (/blocks/sqlreports/migrate_bcr.php). It previews the blocks, then migrates on confirm.
  • CLI: php blocks/sqlreports/cli/migrate_bcr.php --dry-run, then without --dry-run.

Suggested order: import the reports with report_sql, publish them and set audiences, run this migration, then remove BCR. Publishing and report import stay in report_sql.

Changes

  • classes/local/bcr_migrate.php, bcr_migration_item.php: migration logic and result object
  • migrate_bcr.php, cli/migrate_bcr.php: admin page and CLI
  • settings.php, block_sqlreports::has_config(): settings page linking to the migration
  • language strings, README section, version bump
  • tests/local/bcr_migrate_test.php

Testing

  • PHPUnit: placement, positions, user prefs, permission overrides, config mapping, dry run, idempotency.
  • Manual (Playwright): preview, confirm, sesskey check, re-run, anonymous access, and a 56-block production-shaped data set.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Overlapping CLI/admin migrations can create a duplicate replacement block from a stale legacy row, leaving the duplicate without its copied visibility restrictions. Separately, in the cited Moodle default-branch implementation, deleting the old block context removes block-local role assignments, potentially causing affected users to lose edit access or bypass a view prohibition.

2 open issues
What changed in this PR

Moves Configurable Reports block migration into block_sqlreports, keeping report importing and publishing in report_sql.

Changes:

  • Adds database-driven conversion to report-list blocks with per-block transactions.
  • Provides an admin preview/confirmation page and CLI dry-run support.
  • Adds migration tests, documentation, language strings, and a version bump.
File Description
version.php Bumps the plugin version and release.
tests/​local/​bcr_migrate_test.php Tests migration, configuration mapping, and reruns.
settings.php Links plugin settings to the migration page.
README.md Documents migration steps and scope.
migrate_bcr.php Adds admin preview, confirmation, and results.
lang/​en/​block_sqlreports.php Adds migration interface strings.
cli/​migrate_bcr.php Adds CLI migration and dry-run options.
classes/​local/​bcr_migration_item.php Represents per-block migration results.
classes/​local/​bcr_migrate.php Implements block replacement and state transfer.
block_sqlreports.php Enables the plugin settings page.

Review effort: Balanced

Comment thread classes/local/bcr_migrate.php Resolved
Comment thread classes/local/bcr_migrate.php Resolved
Add dry run functionality and locking mechanism for migration.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread classes/local/bcr_migrate.php Resolved
Comment thread classes/local/bcr_migration_item.php Resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@matthewhilton
matthewhilton merged commit f01d69b into MOODLE_405_STABLE Dec 3, 2026
55 checks passed
@matthewhilton
matthewhilton deleted the bcr-to-bsqlr branch December 3, 2026 00:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate Configurable Reports blocks to SQL report list blocks

4 participants