Drupal upgrade tip: Converting from Event module to CCK Date

Comments

Gerard writes:

Interesting post. I've been an event module user in the past, and based on your post, I'm wondering if it's perhaps best to migrate away from Event.module now?

It sounds like a much more flexible method of doing things - so thanks, as always for sharing!

venkat-rk writes:

Although I haven't tried it, this tutorial sounds very useful. Thank you for taking the time to write this.

Mark writes:

Thanks for the tips! It just so happened that I needed to do exactly this, except using event data from version 4.7. I adapted the script slightly:

<?php
while ($row = mysql_fetch_assoc($r)){

  // Transform the date information
  // CCK date format: 2008-12-10T00:00:00
  // event date format: 2006-11-13 15:00:00
  // $startdate = preg_replace ("/ /", 'T', $row['event_start']);

  $startdate = date('Y-m-d\TH:i:s', $row['event_start']);
 
$enddate = date('Y-m-d\TH:i:s', $row['event_end']);
 
$nid = $vid = $row['nid'];

  $q2 = 'INSERT INTO content_type_event (vid, nid, field_event_start_value, field_event_end_value) ' .
   
"VALUES ($nid, $vid, \"$startdate\", \"$enddate\")";

  // Populate the new field for eventstart
 
if (!$r2 = mysql_query($q2)){
    print (
$q2 ." failed!\n");
    exit;
  }

}
?>

Notably, after creating the CCK start and end date fields, there's no data in them - so I don't quite understand how your script populates the table using UPDATE sql statements? I use INSERT statements.

Also, the old event table didn't store revision info, but luckily revisions are disabled for my event nodes, so I could happily use the nid for both nid and vid fields.

The old event data was also stored as Unix timestamps, so I had to convert those. Seemed to work nicely!

Cheers
Mark

Dylan Tack writes:

On my site, the event module data was stored in the local timezone, while date uses UTC. As a result it was necessary to use the Date API to convert to the UTC timezone. I was also running this inside a hook_update_N(), so I used update_sql to perform the queries.

<?php
  $events
= db_query('select * from {event}');
  while(
$event = db_fetch_array($events)) {
 
   
$startdate = date_make_date($event['event_start'], "America/Los Angeles", DATE_ISO);
   
$enddate = date_make_date($event['event_end'], "America/Los Angeles", DATE_ISO);
   
   
date_timezone_set($startdate, timezone_open('UTC'));
   
date_timezone_set($enddate, timezone_open('UTC'));
 
   
$startdate = date_format($startdate, 'Y-m-d\TH:i');
   
$enddate = date_format($enddate, 'Y-m-d\TH:i');
   
   
$results[] = update_sql("update {content_type_trainings} set field_event_date_value = '" . $startdate . "', field_event_date_value2 = '" . $enddate . "' where nid = '" . $event['nid'] . "'");
  }
?>

Post new comment

The content of this field is kept private and will not be shown publicly.