Delete method of Block Controller not firing on delete

Permalink
The delete method of the block controller apparently only fires if you enter edit mode first, then delete. If you just delete the block on a page it does not fire. In a previous post over a year ago, this was identified as the proper functioning of the block controller.

In the documentation on blocks, it says:

"delete()

This method is responsible for clearing out all information about a block when it's deleted.
"

and is identified as the method to use if your block needs to do additional processing on delete from a page. Unfortunately, if the method only gets called sometimes, then you can't really add additional processing for the block delete that is reliable. The question, then, is how to reliably perform additional processing when a block is deleted without requiring the user to edit the block first?

Assistance with this would be greatly appreciated.

Thank you

dbeer
 
dbeer replied on at Permalink Reply
dbeer
I'm beginning to think this is a bug. While investigating further to find a solution, I noticed that when I add any of the core blocks, such as the guest book, and then later delete it without first editing the block, it's entry is removed from the blocks table, as it should be. All of the custom blocks which were deleted without first opening them for edit have been removed from the page as expected, but they all still have an entry in the blocks table and the IsActive flag is set to 1, indicating they are still in use. This means that I have the same block shown as existing on the same page multiple times, when currently there are no instances of the block installed.

There is some issue with the delete block process, just not sure exactly what yet.
daenu replied on at Permalink Reply
daenu
It's a time ago since this thread has been opened, but does anybody have a solution for this?
----- PROBLEM -----
Removing a custom block from the page:
- If in Edit Mode, the concerning row is deleted from it's table.
- If in View Mode, the row isn't deleted from it's table.
C5 Version 5.6.3.1
thx 2 all

----- SOLUTION-----
See below:
http://www.concrete5.org/community/forums/customizing_c5/delete-met...
JohntheFish replied on at Permalink Reply
JohntheFish
Are you deleting through some aspect of the c5 user interface, or deleting by calling the api from code?
daenu replied on at Permalink Reply
daenu
When deleting from the front end, like a user does.

When deleting the block while in Edit Mode (without publishing), it works, but once it's published & deleted the corresponding row isn't deleted in the blocks db-table.

After googling around, I wrote my own delete method, but it's only a turnaround... which does'nt work. Pls help:
public function delete() {
        $db = Loader::db();
        $db->Execute('DELETE FROM ' . $this->btTable . ' WHERE bID = ' . $this->bID);
        parent::delete();
    }


***************
UPDATE
***************
From Andrew Ambler:
"Not a bug. Blocks still store their data so that they can be reinstated in case a previous version of a page gets approved and rolled back to. Block's will only call BlockController::delete() when they no longer need to keep their data around."

See also stackoverflow question & answer:http://stackoverflow.com/questions/22928895/concrete5-block-not-del...