What the script does:

It checks the artefactid within the block_instance configdata to make
sure the artefactid relates to an artefact that is allowed in this
type of block. If the artefactid is not allowed in this type of block
then it outputs some useful information about what is going on.

To use this script:

1) Go to the admin/cli/ directory of your Mahara and copy the
'check_for_mismatched_block_artefacts.php' file into it.

2) Run the script by going: php check_for_mismatched_block_artefacts.php
Note: you may need to do these other steps as well depending on your
setup

A) If you get the html code of the login screen returned you will need
to adjust your Mahara's init.php file (then adjust it back when you
are finished).

Find the code similar to:

// The installer does its own auth_setup checking, because some upgrades may
// break logging in and so need to allow no logins.
if (!defined('INSTALLER')) {
    auth_setup();
}

And change to:

// The installer does its own auth_setup checking, because some upgrades may
// break logging in and so need to allow no logins.
if (!defined('INSTALLER') && !defined('CLI')) {
    auth_setup();
}

B) If you get an error like 'Your defined data root directory ... is not
writable' this means you probably need to run the script as sudo:
sudo php check_for_mismatched_block_artefacts.php

The expected output should look something like this:

 get the installed artefact types
 get all the blocks that have an artefactid set
 400 block(s) have an artefactid set
 Block instance: 22 is a(n) internalmedia block but has an artefactid: 7 that is type blogpost and therefore not allowed here
 1 block / artefact clashes
 
Or this if things are fine:

 get the installed artefact types
 get all the blocks that have an artefactid set
 400 block(s) have an artefactid set
 All ok