backdrop-contrib / examples

Examples for Developers
GNU General Public License v2.0
7 stars 9 forks source link

Do not use a configuration value when a state value should be used #43

Closed avpaderno closed 1 year ago

avpaderno commented 1 year ago

cron_example_cron() uses the following code.

// We usually don't want to act every time cron runs (which could be every
// minute) so keep a time for the next run in a variable.
if (time() >= config_get('cron_example.settings', 'cron_example_next_execution')) {
  // This is a silly example of a cron job.
  // It just makes it obvious that the job has run without
  // making any changes to your database.
  watchdog('cron_example', 'cron_example ran');
  if (!empty($GLOBALS['cron_example_show_status_message'])) {
    backdrop_set_message(t('cron_example executed at %time', array('%time' => cron_example_date_iso8601(time(0)))));
  }
  config_set('cron_example.settings', 'cron_example_next_execution', time() + $interval);
}

The next time a cron hook should be executed is not a value to put in a configuration file, for the same reason the time backdrop_cron_run() has been called is set with state_set('cron_last', REQUEST_TIME).

avpaderno commented 1 year ago

The module does not use a configuration file; the only changes are in the code that reads or writes that configuration value.