uninstall package -> programmatically uninstall block(s)

Permalink
I'm trying to auto-uninstall blocks "owned" by packages by the way it should be done (the proper way), but it won't "budge"...

I'm trying to use the uninstall() method to permanently remove block tables. The package controller method does the job for package tables, but somehow the block method uninstall() never receives a "call".

I've tried something like:
$test = BlockType::getByHandle('handle')->uninstall();

and even hacked /concrete/models/package.php
case 'BlockType':
$item->uninstall();
break;

Although the latter seemed wrong while trying...

Suggestions are welcome...

kaspera
 
Job replied on at Permalink Reply
Job
I had thought it would be just:

public function uninstall() {
  parent::uninstall();
}


Assuming you installing the blocks properly:

public function install() {
  $pkg = parent::install();
  // install block
  BlockType::installBlockTypeFromPackage('handle', $pkg);
}
kaspera replied on at Permalink Reply
kaspera
My idea too... but alas!

The block by the way uninstalls properly (it removes itself from the blocktypes table) but the btBlockTables remain untouched.

Again: the blocks' method uninstall never gets called during the uninstall procedure of package.
kaspera replied on at Permalink Reply
kaspera
So I ran into the following unpleasant surprise:

File: "/concrete/libraries/block_controller.php"
Line: 426-434
/**
       * @access private
       * @todo Make block's uninstallable
       */
      public function uninstall() {
         // currently blocks cannot be uninstalled
      }


Currently blocks cannot be uninstalled...
Job replied on at Permalink Reply
Job
As a temporary fixed I'd just put the database calls in your package uninstaller to remove the tables ..

eg ...

public function uninstall() {
  parent::uninstall();
  $db = Loader::db();
  $db->Execute('drop table if exists tablenamehere');
}


Hope this helps... If it does, don't forget to mark it as an answer!
kaspera replied on at Permalink Best Answer Reply
kaspera
I thought about that, but since we're trying to do it the proper way, I came up with a little workaround. In the package controller I just added the following line:

public function uninstall() {
      BlockType::getByHandle('btHandle')->controller->uninstall();
      parent::uninstall();
      // more code
   }


It's still not really the way it should be, but it keeps the blocks' uninstall() method the way it should be.

Don't ask me why, but it is possible to uninstall package-blocks on an individual basis without having to uninstall the whole package. There is however no other way to install them than to uninstall the entire package first and re-installing the whole thing again.

Makes you want to run up-and-down the office shouting: "Ffffffuuuuuuuu..." :P