Remove duplicate blocks from several courses in bulk

Remove duplicate blocks from several courses in bulk

by Eric Phetteplace -
Number of replies: 1

Is there any tool or API that might help me remove a bunch of duplicate blocks from a large number of courses?

We used templates to generate courses recently but, for reasons we haven't yet figured out, a number of the courses have two copies of blocks like "Upcoming events" and "Recent activity" while it only makes sense for them to have one. I am wondering if there is a tool that can help me weed these out programmatically. I've looked at moosh and while it can add blocks, it cannot remove them. I'd be interested if there is a PHP API for removing blocks or a good way to do it via database queries (currently my best guess).

We are on Moodle 3.8.2

Average of ratings: -
In reply to Eric Phetteplace

Re: Remove duplicate blocks from several courses in bulk

by Eric Phetteplace -
So I figured out why the duplicate blocks appeared—we are using local_course_template but I did not set $CFG->defaultblocks_override = ''; in our config.php.

I ended up bulk deleting blocks using database queries after a convoluting process to identify which blocks needed to be deleted. I wrote up the whole procedure here: https://gist.github.com/phette23/4afdf2aee4011b39aa7aec31f3d23606