Welcome to the Geeks & God Static Archive. Read more »

Migrate from Event Module to CCK Date fields

User Rating:
3.57143
Average: 3.6 (7 votes)

I ran across a script/solution for migrating event module date fields over to CCK date fields and I had to share it (and put it where I could reference it again :) You can find the original post over here and it's parent version (which I could NOT get to work) here. You could also use a modified version of Matt's conversion process to do this.

The process goes something like this:

  1. Backup everything!!!! If this breaks your stuff and you don't have a backup, don't blame me.
  2. On your existing event content type, add a new CCK datefield called "eventstart"
  3. Set the defaults on that field so they are similar to your event date fields
  4. Create a file at your server root called eventmigrate.php or whatever you want
  5. Paste in the code below, modify the timezone and save the file
  6. Navigate to this file in your browser to run the script (ie go to mysite.com/eventmigrate.php) (you may have to increase your timeout limit depending on the number of nodes to convert)
  7. Check to make sure your nodes converted
  8. Delete the script file and uninstall event module.
  9. Build your views using calendar module
  10. Dance and rejoice.

The Code

<?php
// You backed up your database, right?
// Bootstrap Drupal
require 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require
'modules/node/node.pages.inc';


// Cycle through all the records in the event table
$q = 'select * from event';
$r = mysql_query($q);
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']);
 
$enddate = preg_replace("/ /", 'T', $row['event_end']);
 
$nid = $row['nid'];
 
$node = node_load($nid);
 
$vid = $node->vid;
 
$count++;

$timezone = 'America/Detroit';

$node->field_eventstart[0]['value'] = $startdate;
$node->field_eventstart[0]['value2'] = $enddate;
$node->field_eventstart[0]['timezone'] = $timezone;
$node->field_eventstart[0]['timezone'] = $timezone;
$node->field_eventstart[0]['timezone_db'] = $timezone;
$node->field_eventstart[0]['date_type'] = 'date';

$node = node_submit($node);
node_save($node);

}
print
"<br>".$count." records converted.";
?>

Exactly what I need - cant get it to work

2

Hi There,

I'm not having any luck with this script. I've followed the steps closely. For some reason, when I run eventmigrate.php from the root directory, I get a completely blank screen -- I never see a 'records converted' message.

I've verified the mysql info and the timezone as well. Are there specific versions of the event module and the date module that need to be used for this to work? My site is running event 6.x 1.0 and date 6.x 2.4

Thanks for any help!
Andrew

Fixed

4

Ok, check out the updated code now. I changed from putting in database details directly to just using the system to bootstrap Drupal. The above now is working for me.

-Rob Feature
Geeks and God Co-Host
www.mustardseedmedia.com