0

For example, I got in config,

<crontab>
    <jobs>
        <test>
            <schedule>
                <cron_expr>*/15 * * * *</cron_expr>
            </schedule>
            <run>
                <model>test/observer::saveAction</model>
            </run>  
        </test>
    </jobs>
</crontab>

And at: */15 * * * *, can I call a specific time from my db? I want to let the user choose the time interval for the update function. But I am not sure if I can call something from db using php in config.xml, is there a way to put the interval for a cron job in a php file?

1

You can create a system configuration text field via system.xml and use it as your cron schedule:

<crontab>
    <jobs>
        <test>
            <schedule>
                <config_path>path/to/system_config</config_path>
            </schedule>
            <run>
                <model>test/observer::saveAction</model>
            </run>  
        </test>
    </jobs>
</crontab>

Don't forget to add a default value to this field or it won't work if your customer don't change it:

<default>
    <path>
        <to>
            <system_config>*/15 * * * *</system_config>
        </to>
    </path>
</default>
  • Yes, but when the customer chose an interval, I will first save that interval to my db, and after that call the db value with the interval time and replace it in the cron schedule, but I will still not be able to call a value in the system.xml, right? – DanteZ Sep 16 '16 at 13:55
  • @DanteZ well system.xml fields are stored in the database right ? In core_config_data – Raphael at Digital Pianism Sep 16 '16 at 13:57

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.