1

in my Magento Store I need to set some Cron to: - Run maintenance.php - Apply Catalog Rule and after that Refresh Cache - Refresh Sitemaps

My hosting create a curl to cron.php but I don't know how to modify my cron.php to run this operations. Can someone help me? This is my cron.php

require 'app/Mage.php';

if (!Mage::isInstalled()) { echo "Application is not installed yet, please complete install wizard first."; exit; }

// Only for urls // Don't remove this $_SERVER['SCRIPT_NAME'] = str_replace(basename(FILE), 'index.php', $_SERVER['SCRIPT_NAME']); $_SERVER['SCRIPT_FILENAME'] = str_replace(basename(FILE), 'index.php', $_SERVER['SCRIPT_FILENAME']);

Mage::app('admin')->setUseSessionInUrl(false);

umask(0);

try { Mage::getConfig()->init()->loadEventObservers('crontab'); Mage::app()->addEventArea('crontab'); Mage::dispatchEvent('default'); } catch (Exception $e) { Mage::printException($e); }

How should I modify it? Thanks to everyone

2

It looks like your hosting provider has enabled the default Magento cron. This is good news as now Magento will have the cron running on an interval. In order to add a process that you want to the cron you need to create a new module. Within your config.xml add the following:

<config>
...
<crontab>
    <jobs>
        <namespace_module>
            <schedule>
                <cron_expr>0,15,30,45 * * * *</cron_expr>
            </schedule>
            <run>
                <model>module/cron::doSomeAction</model>
            </run>
        </namespace_module>
    </jobs>
</crontab>
...
</config>

If you then create a new file with model/cron.php with the following contents:

<?php
class MyVendor_Module_Model_Cron
{
   public function doSomeAction()
   {
       // Do your logic here
   }
}

Magento will then pick this up when cron runs based on the cron schedule and process the action we created.

Alternatively you could create a new shell command and add this to your linux cron tab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.