Magento 1.x: How do I run the catalog price rules + the indexers in 1 php script?

Magento 1.x: How do I run the catalog price rules + the indexers in 1 php script?

I want to apply the Catalog Price Rules

And run related indexers

In 1 go through a script, how do I do this?

This does not seem to be working.

Help appreciated

require_once $ mageFilename;

Mage :: app (& # 39; admin & # 39 ;, & # 39; store & # 39;);

$ connection = Mage :: getSingleton (& # 39; core / resource & # 39;) -> getConnection (& # 39; core_write & # 39;);

Mage :: app () -> removeCache (& # 39; catalog_rules_dirty & # 39;);

$ catalogPriceRule = Mage :: getModel (& # 39; catalogrule / rule & # 39;);
$ catalogPriceRule-> applyAll ();

$ indexProcess = Mage :: getSingleton (& # 39; index / indexer & # 39;) -> getProcessByCode (& # 39; catalog_product_price & # 39;);
$ indexProcess-> reindexAll ();