Brice Stacey home

Converting from Event module to CCK Date

I've been preparing the Healey Library's website to be upgraded to Drupal 6. That includes getting each module up to date, but in some cases it means finding a replacement. The Event module has been one of those modules that came to a screeching halt following the release of Drupal 6. Luckily, Date is far superior and easily fills its place.

I have only created a single Event content type, ironically called event. For this content type, I created a new CCK Date field called eventdate. When configuring this field, I enabled an Optional To Date. Next, I ran a short script that would transfer existing Event Module data into our new field. You should use the Devel Module to execute this PHP. Please note: You will need to change the timezone to reflect your implementation.

// Iterate through each event.
$result = db_query("SELECT * FROM {event}");
while ($event = db_fetch_array($result)){
  // Transform the date information
  // CCK date format: Y-m-d\TH:i:s
  // Event date format: unix timestamp
  $startdate = date('Y-m-d\TH:i:s', $event['event_start']);
  $enddate = date('Y-m-d\TH:i:s', $event['event_end']);
  $nid = $event['nid'];

  // Load the node corresponding to the event
  $node = node_load(array('nid' => $nid));

  $node->field_eventdate[0]['value'] = $startdate;
  $node->field_eventdate[0]['value2'] = $enddate;
  $node->field_eventdate[0]['timezone'] = 'America/New_York';
  $node->field_eventdate[0]['timezone_db'] = 'America/New_York';
  $node->field_eventdate[0]['date_type'] = 'Date';

  // Save the modified node

Now, we can disable and uninstall the Event module. Then, create a new content type with the same original machine readable name as your original event node (in my case, event). Then you're done!

You will undoubtedly need to make changes throughout the rest of your site, particularly modifying any views and themes that used the original event data structures.

For the record, at the time of this writing I was running Event 5.x-1.0 and Date 5.x-2.8.