/** * Removes the block type. Also removes instances of content. */ public function delete() { $db = Loader::db(); $r = $db->Execute('select cID, cvID, b.bID, arHandle from CollectionVersionBlocks cvb inner join Blocks b on b.bID = cvb.bID where btID = ? union select cID, cvID, cvb.bID, arHandle from CollectionVersionBlocks cvb inner join btCoreScrapbookDisplay btCSD on cvb.bID = btCSD.bID inner join Blocks b on b.bID = btCSD.bOriginalID where btID = ?', array($this->getBlockTypeID(), $this->getBlockTypeID())); while ($row = $r->FetchRow()) { $nc = Page::getByID($row['cID'], $row['cvID']); if (!is_object($nc) || $nc->isError()) { continue; } $b = Block::getByID($row['bID'], $nc, $row['arHandle']); if (is_object($b)) { $b->deleteBlock(); } } $em = $db->getEntityManager(); $em->remove($this); $em->flush(); //Remove gaps in display order numbering (to avoid future sorting errors) BlockTypeList::resetBlockTypeDisplayOrder('btDisplayOrder'); }