You are here

function datereminder_update_6200 in Date Reminder 6.2

Same name and namespace in other branches
  1. 7 datereminder.install \datereminder_update_6200()

Convert `next` from datestamp to Unix timestamp.

File

./datereminder.install, line 160
Stuff Druapl needs to install this module.

Code

function datereminder_update_6200() {
  $ret = array();

  // First, add field to hold converted values.
  $fd = array(
    'description' => 'Time for reminder as Unix epoch',
    'type' => 'int',
    'size' => 'normal',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_add_field($ret, 'datereminder', 'next_due', $fd);

  // The following forces Drupal to start using the new schema. That's
  // necessary for drupal_write_record() to write out the new field.
  drupal_get_schema('datereminder', TRUE);

  // Now, read all records and generate new value.
  $utc = new DateTimeZone('UTC');
  $q = db_query('SELECT * from {datereminder}');
  while ($r = db_fetch_object($q)) {
    $next_due = DateTime::createFromFormat('Y-m-d H:i:s', $r->next, $utc);
    $r->next_due = intval($next_due
      ->format('U'));
    drupal_write_record('datereminder', $r, 'rid');
  }

  // Get rid of old 'next' field. Henceforth, we'll use only next_due.
  db_drop_field($ret, 'datereminder', 'next');
  return $ret;
}