Skip to main content

Rules cron based condition code for allowing execution only once

Submitted by amitsedai on
<?php /* * Part of Rules condition code that returns true if the current time during cron is between 6 am and 7 am */ $ji_daily_status = variable_get("ji_daily_report","1"); //Check if the variable is set, if not set it to 1 [First Time] /* * This fragment checks if the time is between 6 and 7, if so enables the flag * If any other time, sets the ji_daily_report so that next time it executes when cron runs between 6 and 7 */ $time = date('H'); // Get the current time /* Any arbitrary time - Checks if the time is not between 6 am and 7 am */ if($time < 6 || $time > 7){ if('1' != $ji_daily_status){ //Avoid DB operation if already 1 is set variable_set("ji_daily_report","1"); //Sets to 1 so that it works next time } return false; } if($ji_daily_status =='1'){ /* Once executed, set it to 0 so that it does not get executed more than once between 6 and 7 */ variable_set("ji_daily_report","0"); return true; } return false; ?>

Technologies