Removing a Block Upon Package Upgrade

Permalink
One of my theme packages will have a new version that will require getting rid of a block from a previous version.

Below is the code that I have in my package controller for the upgrade:

public function upgrade() {
   parent::upgrade();
   $db = Loader::db();
   $db->Execute('DROP TABLE IF EXISTS btFitTextBeta');
}


The name of the block I'm removing in the new version is "Fit Text Beta".

Is the above code correct, or is there anything else I need to add?

PineCreativeLabs
 
JohntheFish replied on at Permalink Reply
JohntheFish
That will kill the blocks data, but would it leave any already installed blocks hanging and ready to crash?

I suspect that if you look inside 'uninstall' there will be code that removes a block type in a more sympathetic way.
PineCreativeLabs replied on at Permalink Reply
PineCreativeLabs
Will this work:

public function upgrade() {
    parent::upgrade();
    BlockType::getByHandle('btFitTextBeta')->controller->uninstall();
    $db = Loader::db();
    $db->Execute('DROP TABLE IF EXISTS btFitTextBeta');
}
JohntheFish replied on at Permalink Reply
JohntheFish
Looks plausible enough to be worth testing and developing from. If it works, It would cleanly remove all instances of the block.

If you are replacing a block with a redevelopment, it would be a friendlier upgrade to migrate instances of the old block into the new block so content doesn't get lost in the process.