I think you'll have the same timeout problem I had when I wrote an import script, because the indexing was set to automatic.
I would create a script in your magento root (or in a subfolder) and do the following:
1) make sure you've got all necessary includes ..
// load the mage file
require("../app/Mage.php");
// load magento in admin mode
Mage::app('admin');
Loading in admin mode is necessary to be able to delete.
2) Make sure you disable indexing:
// set the indexing modus in magento
// TRUE or FALSE
function setIndexingManual($value = TRUE) {
// set the magento indexing status to auto
$pCollection = Mage::getSingleton('index/indexer')->getProcessesCollection();
if($value) { // TRUE
$mode = Mage_Index_Model_Process::MODE_REAL_TIME;
} else {
$mode = Mage_Index_Model_Process::MODE_MANUAL;
}
foreach ($pCollection as $process) {
$process->setMode($mode)->save();
}
}
Call it with the following before you do any mass edits / deletes / creates:
// set the magento indexing status to manual
setIndexingManual(FALSE);
Now do your stuff by first getting all disabled products ..
$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => 2)) //only disabled
->load();
now ..loop through the collection and delete each product
// loop through each product
foreach($collection as $product){
try {
// delete the product
$product_load = Mage::getSingleton('catalog/product')->load($product->getId());
Mage::dispatchEvent('catalog_controller_product_delete', array('product' => $product_load));
$product_load->delete();
} catch(Exception $e) { // end try
// error log
Mage::log($e->getMessage());
$error = $e->getMessage();
echo "-> <b>deletion of " . $product->getName() . "(" . $product->getId() . ") failed!</b> <br />$error<br /><br />";
}
}
Now you can enable indexing again ..
// set the magento indexing status to auto
setIndexingManual();