I am using the following code to delete a category from my Magento installation programmatically:
$hostId = $model->getId()->getHost();
$category = \Mage::getModel('catalog/category')
->loadByAttribute('jtl_erp_id', $hostId);
if ($category) {
\Mage::register('isSecureArea', true);
$category->delete();
\Mage::unregister('isSecureArea');
}
This works fine unless the flat category index is enabled. If this is the case, the following exception is being thrown:
Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Category_Flat::isForbiddenToDelete() in /path/to/magento/app/code/core/Mage/Catalog/Model/Category.php on line 755
Any ideas? I am using Magento 1.9.0.1