Each month my module needs to reset some values in a database table. I need to reset saldo's in a table I created. I know how to write a function in drupal that does the work but how do I trigger this function each first day of the month at midnight? Do I have to make a cron script? And how does that call my drupal funtion?

Comments

kevinwal’s picture

If you've already created your own module, you can do that in hook_cron: http://api.drupal.org/api/drupal/modules!system!system.api.php/function/...

Does that help? Then you could check if it's the second day of the month and run your script if it's after midnight.

sebto’s picture

(Assume you are D7 developer)
Drupal itself has a cron functionality in core. You should implement hook_cron in your module to execute your code in every cron run time. Set cron execution time to "every day" or less; then check if the current time is greater than 1 month.


function your_module_name_cron() {
  $last_cron_time = variable_get('your_module_name_last_cron_time',NULL);
  if( /* check if $last_cron_time is greater than 1 month */) {
    /* your code to reset db variables */
   variable_set('your_module_name_last_cron_time',time());
  }
}

alb’s picture

Set cron execution time to "every day"

fordrupal 6 how can have this?

but for execute a function every day is necessary run cron?
with rules is possible and how?
rules performs the function without using cron?