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:
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?
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?
Will this work:
public function upgrade() { parent::upgrade(); BlockType::getByHandle('btFitTextBeta')->controller->uninstall(); $db = Loader::db(); $db->Execute('DROP TABLE IF EXISTS btFitTextBeta'); }
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.
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.
I suspect that if you look inside 'uninstall' there will be code that removes a block type in a more sympathetic way.