Magento snippets

# clear cache
foreach ( Mage::helper( 'core' )->getCacheTypes() as $type => $label ) {
echo $label . "\n";
}
http://www.magentocommerce.com/boards/viewthread/43238/#t156277

----------------------------------------------------

require_once 'app/Mage.php';
umask(0);

Mage::app()->cleanCache();
flush();

$collection = Mage::getSingleton('index/indexer')->getProcessesCollection();

foreach ($collection as $process) {
if ($process->isLocked()) {
$process->unlock();
}
$process->reindexEverything();
}

# create category with static cms page
https://magento.stackexchange.com/questions/84830/how-to-create-category-programatically
<?php
require '/var/www/html/app/Mage.php';
Mage::app("admin");
$bar=$_SERVER['argv'][1];
try{
$category = Mage::getModel('catalog/category');
$category->setName("Foo $bar");
$category->setUrlKey("foo-$bar");
$category->setIsActive(1);
$category->setDisplayMode(Mage_Catalog_Model_Category::DM_PAGE);
$category->setIsAnchor(1);
# $category->setStoreId(Mage::app()->getStore()->getId());
$category->setStoreId(0);
$category->setLandingPage(46);
$parentCategory = Mage::getModel('catalog/category')->load(2230);
$category->setPath($parentCategory->getPath());
$category->save();
} catch(Exception $e) {
var_dump($e);
}
?>

# delete url_rewrite
https://magento.stackexchange.com/questions/100523/delete-url-rewrite-programmatically
<?php
require '/var/www/html/app/Mage.php';
Mage::app("admin");
$path="%foo/bar-123%";
try{
$coll = Mage::getModel('core/url_rewrite')->getCollection();
$coll->addFieldToFilter('request_path', array('like' => $path));
foreach ($coll->getItems() as $rewrite){
echo var_dump($rewrite);
$rewrite->delete();
}
} catch(Exception $e) {
var_dump($e);
}
?>