Get ezpublish user real names for drupal profile.module
Last modified: February 19, 2008 - 03:56
[note from ax to cheryl: this code triggers "suspicious input" because it of "data=". had to escape this with "data=". i also wrapped the lines ("my $template=") at 80 chars to make this look better here - hope i didn't introduce any bugs]
#!/usr/bin/perl -w
use strict;
use DBI;
use Carp;
my $server = 'localhost';
my $database = 'drupal';
my $username = 'me';
my $password = 'password';
my $verbose;
my $dbh = DBI->connect("dbi:mysql:$database:$server", $username, $password )
or croak "Can't connect to database";
$dbh->{RaiseError} = 1;
# difference between ezp user id and drupal uid (see @uid in migrate.sql)
my $iddifference = 1;
my $template='a:13:{s:16:"profile_realname";s:%d:"%s";s:15:"profile_address";\
s:0:"";s:12:"profile_city";s:0:"";s:13:"profile_state";s:0:"";s:11:"profile_zip";\
s:0:"";s:15:"profile_country";s:0:"";s:11:"profile_job";s:0:"";s:16:"profile_homepage";\
s:0:"";s:17:"profile_biography";s:0:"";s:11:"weblink_new";s:1:"0";s:5:"pass1";\
s:0:"";s:5:"pass2";s:0:"";s:5:"block";a:0:{}}';
my $select = $dbh->prepare( q/select ID, FirstName, LastName from ezp.eZUser_User/ );
my $update = $dbh->prepare( q/update users set data=? where uid=?/ );
$select->execute;
while ((my $id, my $first, my $last) = $select->fetchrow) {
my $name = ($first || '') . ($first && $last ? ' ' : '') . ($last || '');
my $profile = sprintf( $template, length( $name ), $name );
$update->execute( $profile, $id+$iddifference );
}