Last active
August 29, 2015 14:22
-
-
Save natrod/e00691bc30f4d7c55b4b to your computer and use it in GitHub Desktop.
Catalog Rule script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'app/Mage.php'; | |
ini_set('display_errors', 1); | |
ini_set("memory_limit","11364M"); | |
Mage::setIsDeveloperMode(true); | |
$time_start = microtime(true); | |
$premem=memory_get_usage(true); | |
Mage::app(); | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
try { | |
Mage::getModel('catalogrule/rule')->applyAll(); | |
Mage::app()->removeCache('catalog_rules_dirty'); | |
$Report="Catalog Rules have been applied via cron job at ".date("d-m-y, H:i:s")."<br />".PHP_EOL; | |
} catch (Exception $e) { | |
$Report="Catalog Rules failure when applied via cron job at ".date("d-m-y, H:i:s")."<br />".PHP_EOL;; | |
$date=date("Y-m-d-H-i-s"); | |
$logname="catalog-rule-cron".$date.".log"; | |
Mage::log(print_r($e->getMessage(),true),null,$logname); | |
} | |
$postmem=memory_get_usage(true); | |
$time_end = microtime(true); | |
$tt=$time_end-$time_start; | |
$tmem=echo_readable_memory_usage($postmem-$premem); | |
$Report.="TOTAL EXECUTION TIME ".$tt."<br />".PHP_EOL; | |
$Report.= "PRE MEM ".$premem."<br />".PHP_EOL; | |
$Report.= "POST MEM ".$postmem."<br />".PHP_EOL; | |
$Report.= "Total MEM Consumption ".$tmem."<br />".PHP_EOL; | |
echo $Report; | |
$reciever="[email protected]"; | |
$cc=array('[email protected]'); | |
$mail = new Zend_Mail(); | |
$mail->setFrom("[email protected]","Catalog Rules Cron" ); | |
$mail->addTo($reciever); | |
foreach($cc as $c ) | |
{ | |
$mail->addCc($c); | |
} | |
$mail->setSubject("Catalog Rule Cron Status".date("d-m-y")); | |
$mail->setBodyHtml($Report); | |
$mail->send(); | |
function echo_readable_memory_usage($mem_usage) { | |
if ($mem_usage < 1024) | |
return $mem_usage." bytes"; | |
elseif ($mem_usage < 1048576) | |
return round($mem_usage/1024,2)." KB"; | |
else | |
return round($mem_usage/1048576,2)."MB"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment