function simplenews_scheduler_update_6007 in Simplenews Scheduler 6.2
Implementation of hook_update_N().
Add the next_run field to the scheduler table and populate it.
Equivalent to simplenews_scheduler_update_7001().
File
- ./
simplenews_scheduler.install, line 227 - Install and uninstall functions for the Simplenews Scheduler module.
Code
function simplenews_scheduler_update_6007() {
$ret = array();
// Add the field.
$field = array(
'description' => 'The future timestamp the next scheduled newsletter is due to be sent.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'initial' => 0,
);
db_add_field($ret, 'simplenews_scheduler', 'next_run', $field);
// Populate the new field with each schedule's next run time.
// Retrieve all records into an associative array keyed by nid.
$result = db_query("SELECT * FROM {simplenews_scheduler}");
while ($schedule = db_fetch_object($result)) {
// Clear last_run to force the next_run calculation to work from the
// start_date. This ensures that any error in previous edition dates due to
// bugs with month length is ignored.
// @see http://drupal.org/node/1364784
$schedule->last_run = 0;
// Get the next run time relative to the request time.
$next_run = simplenews_scheduler_calculate_next_run_time($schedule, REQUEST_TIME);
// Don't use drupal_write_record() in a hook_update_N().
db_query("UPDATE {simplenews_scheduler} SET next_run = %d WHERE nid = %d", $next_run, $schedule->nid);
}
return $ret;
}