delete method in controller not working.

Permalink
I have this delete method in a blocks controller.php:

public function delete() {
      $db = Loader::db();
      $q = 'DELETE FROM btMyBlock WHERE bID=?';
      $v = array($this->bID);
      $db->Execute($q,$v);
      parent::delete();
}


Doesn't seem to be working. Can anybody see any problems with it?

 
andrew replied on at Permalink Reply
andrew
1. You won't need to write the method as is – that's almost exactly what the stock BlockController::delete() (it deletes the corresponding row from the $btTable.

2. Blocks in concrete5 only get deleted when they aren't used anywhere – including in any old versions of the page. That's likely why you're not seeing this method run – the block is still active in an old version of the page. Try deleting all versions or deleting the page and see if it runs.
frankdesign replied on at Permalink Reply
I'll have a look but I'm pretty sure that the AddEvent / Event List blocks from SimpleEvents will not work then. As the Event List block getCurrentEvents method it its library calls:

$db = Loader::db();
if ($ctID == 'All Categories'){
  $r = $db->Query("SELECT * FROM btAddEvent WHERE sdt>=CURDATE() ORDER BY sdt $ordering,st_a $ordering,st_h +0 $ordering, st_m $ordering");
}else{
  $r = $db->Query("SELECT * FROM btAddEvent WHERE sdt>=CURDATE() AND ctID = '$ctID' ORDER BY sdt $ordering,st_a $ordering,st_h +0 $ordering, st_m $ordering");
}


So if I delete an event, it would still show in list. I'm probably wrong but I'll look.
andrew replied on at Permalink Reply
andrew
Hmm – yeah someone might want to double-check that. Unless they've got that block set up to ignore versioning by including $btIncludeAll in the block controller, it will cause problems. We've gotten around this by joining SQL calls like this to CollectionVersions.cvIsApproved = 1 (which only includes blocks on approved pages.)
frankdesign replied on at Permalink Reply
Well, it's a job for monday for me now. I'm OUTA HERE! Thanks for the help.