Update catalogue price rules in Magento programmatically

If you’ve a long or complicated catalogue, then on occasion when you try to update and reapply all your price rules via the admin panel you may find that things time-out. Whilst the updating should continue to run past this point, it may not.

Below is a quick a dirty script – upload it to the web root of your site, and then access through the Terminal over SSH (where you don’t get any of those pesky timeout issues), and it’ll reapply all your price rules in one go.

require 'app/Mage.php';
Mage::app('admin', 'store');
  $catalogPriceRule = Mage::getModel('catalogrule/rule');
} catch (Exception $e) {